dustem_mask_data.pro
4.47 KB
1
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
FUNCTION dustem_mask_data,data_struct,omit=omit,data_set=data_set,help=help
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)
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
eq_tags = ['STOKESI','EXT_I','EXT_P','STOKESQ','STOKESU','EXT_Q','EXT_U']
errvec = ['SIGMAII','SIGEXTI','SIGEXTP','SIGMAQQ','SIGMAUU','SIGEXTQ','SIGEXTU']
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]])
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]))
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