Blame view

src/idl/dustem_mask_data.pro 5.93 KB
11a73ecb   Ilyes Choubani   The filtering/mas...
1
FUNCTION dustem_mask_data,data_struct,omit=omit,data_set=data_set,help=help
11e52e98   Ilyes Choubani   corrected to incl...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
;+
; NAME:
;    dustem_mask_data
; PURPOSE:
;    Removing filters from a data structure.
; CATEGORY:
;    DUSTEM Wrapper
; CALLING SEQUENCE:
;    data_struct=dustem_mask_data(data_struct,omit=,data_set=)
; INPUTS:
;    data_struct=read_xcat(file,/silent). Data structure formatted as outlined in the DustermWrap Users' Guide
;    data_set : Array of character strings containing the different data sets to be filtered.
;    ie: ['SED'],['QSED'],'USED'] or just ['QSED'] for example. The use of ['STOKESI','STOKESQ','STOKESU'] instead is equivalent.
;    omit : Can be an array or list. In both cases it should contain the filter names as character strings. 
;    ie: omit=['SPIRE1','SPIRE2'] for an array or omit=list(['SPIRE2','SPIRE1','PACS2'],['HFI5','HFI4']) for a list.
;    When using a list, its shape (dimension) should be the number of elements of the data_set array.
;    ie: Each dimension is an array of filters to be removed from the corresponding data set in the data_set array.
; OPTIONAL INPUT PARAMETERS:
;    None
; OUTPUTS:
;    data_struct 
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help                  = if set, prints this help
; COMMENTS
;   Both list and array entries for omit and hide keywords are allowed.
; MODIFICATION HISTORY:
;    Written by IC 
;-
11a73ecb   Ilyes Choubani   The filtering/mas...
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_filter_data'
  goto,the_end
ENDIF

IF keyword_set(data_struct) and keyword_set(omit) THEN BEGIN

    ;Array of filters present in dustem
    filters_dustem=[((*!dustem_filters).(0).filter_names)]
    
    for i=1L,n_elements(tag_names(*!dustem_filters))-1 do begin
        filters_dustem=[filters_dustem,((*!dustem_filters).(i).filter_names)] 
    endfor 
    
    ;Array of filters present in data_struct
    filters_data = data_struct.filter
    
    ;Tag names present in data_struct (to be able to test on the different data sets)
    tagnames = tag_names(data_struct)
   
11a73ecb   Ilyes Choubani   The filtering/mas...
54
    
11a73ecb   Ilyes Choubani   The filtering/mas...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    if typename(omit) EQ 'LIST' then ind0 = omit[*] else ind0=intarr(n_elements(omit)) ; this is a better condition because it is also valid for when the user wants to omit 'spectrum' (non-filter) data points.
    ;because types can be float or double but not long. 
    
    for i=0L,n_elements(omit)-1 do begin
        dim_i = n_elements(omit(i)) ;getting the dimension of each element of the list/array
        ind0[i] = intarr(dim_i) + la_undef() ;initializing to la_undef()     
    endfor
    
    ;Gathering the indices of the filters to remove.        
    
    for i=0L,n_elements(omit)-1 do begin
        
        dim_i=n_elements(omit(i)) ;Getting the dimension of each element of the list

        arr_i=intarr(dim_i) + la_undef() ;initializing to la_undef()
        
        for j=0L,dim_i-1 do begin
            
            ;testing whether the element corresponds to a specific wavelength. 
            ;accepts both numbers/strings
            
            if valid_num((omit[i])[j]) then begin
                
                ind=where(float((omit[i])[j]) EQ data_struct.wave,test0)
                if test0 ne 0 then arr_i[j] = ind else message, 'WAVELENGTH '+strtrim((omit[i])[j],2)+' does not correspond to any spectrum point in the supplied data strucure.'
            endif else begin
                
                ind = where((omit[i])[j] EQ filters_dustem,test1) ;Test if the filter is in the wrapper's database
                if test1 eq 0 then message, 'Filter '+strtrim((omit[i])[j],2)+' cannot be found in the DustemWrap database.'
                
                ind = where((omit[i])[j] EQ filters_data,test2) ;Test if the filter in in the data itself
                if test2 ne 0 then arr_i[j] = ind else message, 'Filter '+strtrim((omit[i])[j],2)+' cannot be found in the data supplied.'  
            
            endelse
               
        endfor
        ind0[i] = arr_i ;Indices of the filters to be removed in the data structure
    endfor
18e4331f   Ilyes Choubani   general update (f...
93
94
95
96
        ;PSI is present two times and you have to fix this.
        eq_tags = ['STOKESI','EXT_I','EXT_P','LARGEP','SMALLP','PSI','PSI','STOKESQ','STOKESU','EXT_Q','EXT_U']
        errvec = ['SIGMAII','SIGEXTI','SIGEXTP','SIGMA_LARGEP','SIGMA_SMALLP','SIGMA_PSI','SIGMA_PSI','SIGMAQQ','SIGMAUU','SIGEXTQ','SIGEXTU']
        
11a73ecb   Ilyes Choubani   The filtering/mas...
97
98
99
100
101
102
103
104
    IF keyword_set(data_set) then begin
        for i=0L,n_elements(data_set)-1 do begin 
            ind_set = where(tagnames EQ data_set(i),ctset)
            ;here using eq_tags and errvec for another purpose
            ;because I need to locate the associated errors
            if ctset ne 0 then begin
                inderr = where(eq_tags EQ data_set(i)) ;no need for counters this is supposedly true at all times plus the error message is below in the next test
                ind_errset = where(tagnames EQ errvec[inderr[0]])
18e4331f   Ilyes Choubani   general update (f...
105
                ;stop
11a73ecb   Ilyes Choubani   The filtering/mas...
106
107
108
109
110
            endif else begin
               ind_set1 = where(tag_names(!dustem_data) EQ data_set(i),ctset)
               if ctset eq 0 then message, 'Aborting. The supplied data set is not found in the DustemWrap database.'
               ind_set = where(tagnames EQ eq_tags(ind_set1[0]))
               ind_errset = where(tagnames EQ errvec(ind_set1[0]))
18e4331f   Ilyes Choubani   general update (f...
111
            ;stop
11a73ecb   Ilyes Choubani   The filtering/mas...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
            endelse
            
            if typename(ind0) EQ 'LIST' then begin 
                data_struct(ind0[i]).(ind_set) = la_undef()
                data_struct(ind0[i]).(ind_errset) = la_undef() 
            endif else begin
                data_struct(ind0).(ind_set) = la_undef()
                data_struct(ind0).(ind_errset) = la_undef()  
            endelse
             
        endfor
    endif else begin
        ind_tags = where(tagnames ne 'INSTRU' and tagnames ne 'FILTER' and tagnames ne 'WAVE')
        for j=0L,n_elements(ind_tags)-1 do begin
            data_struct(ind0).(ind_tags(j)) = la_undef()               
        endfor 
    endelse

    
ENDIF ELSE message, 'Cannot proceed. Keyword(s) missing. Refer to help for keyword options.'

return, data_struct

the_end:


END