Blame view

src/idl/dustem_mask_data.pro 6.48 KB
0068116a   Ilyes Choubani   General update + ...
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
;+
; 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:
7d3f28dc   Jean-Philippe Bernard   not sure what I d...
12
;    data_struct : SED Data structure formatted as outlined in the DustermWrap Users' Guide
11e52e98   Ilyes Choubani   corrected to incl...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
;    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
    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
0068116a   Ilyes Choubani   General update + ...
91
        
11a73ecb   Ilyes Choubani   The filtering/mas...
92
        ind0[i] = arr_i ;Indices of the filters to be removed in the data structure
0068116a   Ilyes Choubani   General update + ...
93
    
11a73ecb   Ilyes Choubani   The filtering/mas...
94
    endfor
0068116a   Ilyes Choubani   General update + ...
95
    
0068116a   Ilyes Choubani   General update + ...
96
97
98
99
        
        eq_tags = ['STOKESI','EXT_I','STOKESQ','STOKESU','LARGEP','SMALLP','PSI','EXT_Q','EXT_U','EXT_P','EXT_smallp','PSI']
            
        errvec = ['SIGMAII','SIGEXTI','SIGMAQQ','SIGMAUU','SIGMA_LARGEP','SIGMA_SMALLP','SIGMA_PSI','SIGEXTQ','SIGEXTU','SIGEXTP','SIGEXTsmallp', 'SIGEXT_PSI']
18e4331f   Ilyes Choubani   general update (f...
100
        
11a73ecb   Ilyes Choubani   The filtering/mas...
101
    IF keyword_set(data_set) then begin
0068116a   Ilyes Choubani   General update + ...
102
        
11a73ecb   Ilyes Choubani   The filtering/mas...
103
104
105
106
        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
0068116a   Ilyes Choubani   General update + ...
107
            
11a73ecb   Ilyes Choubani   The filtering/mas...
108
            if ctset ne 0 then begin
0068116a   Ilyes Choubani   General update + ...
109
                
11a73ecb   Ilyes Choubani   The filtering/mas...
110
111
                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]])
0068116a   Ilyes Choubani   General update + ...
112
113
114
115
116
117
118
119
120
121
122
123
124
                
                ;in the case of PSI for emission and for absorption 
                ;I need to know the different cases: 
                
                ;EMISSION
                
                if data_set(i) EQ 'PSI' and tagnames[3] EQ 'STOKESI' then ind_errset = where(tagnames EQ errvec[6])   
                
                
                ;EXTINCION
                
                if data_set(i) EQ 'PSI' and tagnames[3] EQ 'EXT_I' then ind_errset = where(tagnames EQ errvec[11])
                
18e4331f   Ilyes Choubani   general update (f...
125
                ;stop
11a73ecb   Ilyes Choubani   The filtering/mas...
126
            endif else begin
0068116a   Ilyes Choubani   General update + ...
127
               ind_set1 = where(tag_names(*!dustem_data) EQ data_set(i),ctset)
11a73ecb   Ilyes Choubani   The filtering/mas...
128
129
130
               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...
131
            ;stop
11a73ecb   Ilyes Choubani   The filtering/mas...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
            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