dustem_set_data.pro
10.8 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
107
108
109
110
111
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
FUNCTION dustem_set_data,help=help,sed=sed,ext=ext,polfrac=polfrac,rchi2_weight=rchi2_weight,f_HI=f_HI
;+
; NAME:
; dustem_set_data
; PURPOSE:
; Initializes the dustem data structure (!dustem_data)
; CATEGORY:
; Dustem
; CALLING SEQUENCE:
; dustem_set_data,spec[,help=]
; INPUTS:
; spec: array of structures containing a SED
; OPTIONAL INPUT PARAMETERS:
; None
; OUTPUTS:
; None
; OPTIONAL OUTPUT PARAMETERS:
; None
; ACCEPTED KEY-WORDS:
; help = If set print this help
; COMMON BLOCKS:
; None
; SIDE EFFECTS:
; initializes !dustem_data
; wavelengths are forced to be the central filter wavelength for
; photometric data
; RESTRICTIONS:
; The dustem idl wrapper must be installed
; PROCEDURE:
; None
; EXAMPLES
; dustem_init
; dir=getenv('DUSTEM_SOFT_DIR')+'/src/dustem3.8_web/SEDs/'
; file=dir+'Gal_composite_spectrum.xcat'
; spec=read_xcat(file,/silent)
; dustem_set_data,spec
; MODIFICATION HISTORY:
; Written by J.-Ph. Bernard
; see evolution details on the dustem cvs maintained at CESR
; Contact J.-Ph. Bernard (Jean-Philippe.Bernard@cesr.fr) in case of problems.
;
; V. Guillet (2012) : dustem_set_data is turned into a function which can be used
; indifferently for sed, ext, polext
;-
;fully deprecate the use of polfrac?
IF keyword_set(help) THEN BEGIN
doc_library,'dustem_set_data'
goto,the_end
ENDIF
;=== clean the data structure
;This step detects polarization without the polarization keyword of dustem_init
!dustem_data.sed = ptr_new()
!dustem_data.ext = ptr_new()
NP=0
NQ=0
NU=0
IF !run_pol THEN BEGIN
ind=where(sed.largeP NE la_undef(),NP)
if NP NE 0 then !dustem_data.polsed = ptr_new()
ind=where(sed.StokesQ NE la_undef(),NQ)
if NQ NE 0 then !dustem_data.qsed = ptr_new()
ind=where(sed.StokesU NE la_undef(),NU)
if NU NE 0 then !dustem_data.used = ptr_new()
ENDIF
;NOTA BENE: if we want to make a similar change to the ext structure we have to find a name
;that suits polext and the cos and sin components
; ind=where(ext.largeP NE la_undef(),NPext)
; if NPext NE 0 then !dustem_data.polext = ptr_new()
; ind=where(sed.StokesQext NE la_undef(),NQext)
; if NQext NE 0 then !dustem_data.qext = ptr_new()
; ind=where(sed.StokesUext NE la_undef(),NUext)
; if NUext NE 0 then !dustem_data.uext = ptr_new()
;=============
IF keyword_set(sed) THEN BEGIN
wavs=sed.wave
;=== Impose central wavelengths for photometric channels
ind=where(sed.filter NE 'SPECTRUM',count)
IF count NE 0 THEN BEGIN
wavs(ind)=dustem_filter2wav(sed(ind).filter)
ENDIF
;=== define observations structure
obs_st={instru_names:sed.instru,filt_names:sed.filter,wav:wavs, values:sed.StokesI,sigma:sqrt(sed.sigmaII)}
;=== fill !dustem_data
!dustem_data.sed = ptr_new(obs_st)
;VGb
; If f_HI is specified, multiply the data by f_HI
if keyword_set(f_HI) then begin
if f_HI gt 0 then (*!dustem_data.sed).values *= f_HI else f_HI = 1.
endif else f_HI = 1.
defsysv,'!dustem_f_HI',f_HI
;VGe
if NP NE 0 then BEGIN
;=== define observations structure
obs_st.values=sed.largeP
obs_st.sigma=sqrt(sed.sigma_largeP)
;=== fill !dustem_data
!dustem_data.polsed = ptr_new(obs_st)
;VGe
; If f_HI is specified, multiply the data by f_HI
if keyword_set(f_HI) then if f_HI gt 0 then $
(*!dustem_data.polsed).values *= f_HI
;VGe
ENDIF
if NQ NE 0 then BEGIN
;=== define observations structure
;obs_st={instru_names:polsed.instru,filt_names:polsed.filter,wav:wavs, values:polsed.spec,sigma:polsed.error}
obs_st.values=sed.StokesQ
obs_st.sigma=sqrt(sed.sigmaQQ)
;=== fill !dustem_data
!dustem_data.qsed = ptr_new(obs_st)
;VGe
; If f_HI is specified, multiply the data by f_HI
if keyword_set(f_HI) then if f_HI gt 0 then $
(*!dustem_data.qsed).values *= f_HI
;VGe
ENDIF
if NU NE 0 then BEGIN
;=== define observations structure
;obs_st={instru_names:polsed.instru,filt_names:polsed.filter,wav:wavs, values:polsed.spec,sigma:polsed.error}
obs_st.values=sed.StokesU
obs_st.sigma=sqrt(sed.sigmaUU)
;=== fill !dustem_data
!dustem_data.used = ptr_new(obs_st)
;VGe
; If f_HI is specified, multiply the data by f_HI
if keyword_set(f_HI) then if f_HI gt 0 then $
(*!dustem_data.used).values *= f_HI
;VGe
ENDIF
ENDIF
; ;===== not sure if this below is vere happening anymore
; IF keyword_set(polsed) THEN BEGIN
; wavs=polsed.wave
; ;=== Impose central wavelengths for photometric channels
; ind=where(polsed.filter NE 'SPECTRUM',count)
; IF count NE 0 THEN BEGIN
; wavs(ind)=dustem_filter2wav(polsed(ind).filter)
; ENDIF
; ;=== define observations structure
; ;obs_st={instru_names:polsed.instru,filt_names:polsed.filter,wav:wavs, values:polsed.spec,sigma:polsed.error}
; obs_st={instru_names:polsed.instru,filt_names:polsed.filter,wav:wavs, values:polsed.largeP,sigma:sqrt(sed.sigma_largeP)}
; ;=== fill !dustem_data
; !dustem_data.polsed = ptr_new(obs_st)
; ;VGe
; ; If f_HI is specified, multiply the data by f_HI
; if keyword_set(f_HI) then if f_HI gt 0 then $
; (*!dustem_data.polsed).values *= f_HI
; ;VGe
; ENDIF
;
;
; ;IF keyword_set(qsed) THEN BEGIN
; IF NQ NE 0 THEN BEGIN
; qsed=sed[indQ]
; wavs=qsed.wave
; ;=== Impose central wavelengths for photometric channels
; ind=where(qsed.filter NE 'SPECTRUM',count)
; IF count NE 0 THEN BEGIN
; wavs[ind]=dustem_filter2wav(qsed[ind].filter)
; ENDIF
; ;=== define observations structure
; obs_st={instru_names:qsed.instru,filt_names:qsed.filter,wav:wavs, values:qsed.StokesQ,sigma:sqrt(qsed.SIGMAQQ)}
; ;=== fill !dustem_data
; !dustem_data.qsed = ptr_new(obs_st)
; ;VGe
; ; If f_HI is specified, multiply the data by f_HI
; if keyword_set(f_HI) then if f_HI gt 0 then $
; (*!dustem_data.qsed).values *= f_HI
; ;VGe
; ENDIF
;
; IF NU NE 0 THEN BEGIN
; ;IF keyword_set(used) THEN BEGIN
; used=sed[indU]
; wavs=used.wave
; ;=== Impose central wavelengths for photometric channels
; ind=where(used.filter NE 'SPECTRUM',count)
; IF count NE 0 THEN BEGIN
; wavs(ind)=dustem_filter2wav(used(ind).filter)
; ENDIF
; ;=== define observations structure
; obs_st={instru_names:used.instru,filt_names:used.filter,wav:wavs, values:used.StokesU,sigma:sqrt(qsed.SIGMAUU)}
; ;=== fill !dustem_data
; !dustem_data.used = ptr_new(obs_st)
; ;VGe
; ; If f_HI is specified, multiply the data by f_HI
; if keyword_set(f_HI) then if f_HI gt 0 then $
; (*!dustem_data.used).values *= f_HI
; ;VGe
; ENDIF
;I'm not so sure about the extinction
IF keyword_set(qext) THEN BEGIN
wavs=qext.wave
;=== Impose central wavelengths for photometric channels
ind=where(qext.filter NE 'SPECTRUM',count)
IF count NE 0 THEN BEGIN
wavs(ind)=dustem_filter2wav(qext(ind).filter)
ENDIF
;=== define observations structure
obs_st={instru_names:qext.instru,filt_names:qext.filter,wav:wavs, values:qext.spec,sigma:qext.error}
;=== fill !dustem_data
!dustem_data.qext = ptr_new(obs_st)
;VGe
; If f_HI is specified, multiply the data by f_HI
if keyword_set(f_HI) then if f_HI gt 0 then $
(*!dustem_data.qext).values *= f_HI
;VGe
ENDIF
IF keyword_set(uext) THEN BEGIN
wavs=uext.wave
;=== Impose central wavelengths for photometric channels
ind=where(uext.filter NE 'SPECTRUM',count)
IF count NE 0 THEN BEGIN
wavs(ind)=dustem_filter2wav(uext(ind).filter)
ENDIF
;=== define observations structure
obs_st={instru_names:uext.instru,filt_names:uext.filter,wav:wavs, values:uext.spec,sigma:uext.error}
;=== fill !dustem_data
!dustem_data.uext = ptr_new(obs_st)
;VGe
; If f_HI is specified, multiply the data by f_HI
if keyword_set(f_HI) then if f_HI gt 0 then $
(*!dustem_data.uext).values *= f_HI
;VGe
ENDIF
;===== not sure if this below is vere happening anymore
IF keyword_set(polfrac) THEN BEGIN
wavs=polfrac.wave
;=== Impose central wavelengths for photometric channels
ind=where(polfrac.filter NE 'SPECTRUM',count)
IF count NE 0 THEN BEGIN
wavs(ind)=dustem_filter2wav(polfrac(ind).filter)
ENDIF
;=== define observations structure
obs_st={instru_names:polfrac.instru,filt_names:polfrac.filter,wav:wavs, values:polfrac.spec,sigma:polfrac.error}
;=== fill !dustem_data
!dustem_data.polfrac = ptr_new(obs_st)
ENDIF
IF keyword_set(polext) THEN BEGIN
wavs=polext.wave
;=== Impose central wavelengths for photometric channels
ind=where(polext.filter NE 'SPECTRUM',count)
IF count NE 0 THEN BEGIN
wavs(ind)=dustem_filter2wav(polext(ind).filter)
ENDIF
;=== define observations structure
obs_st={instru_names:polext.instru,filt_names:polext.filter,wav:wavs, values:polext.spec,sigma:polext.error}
;=== fill !dustem_data
!dustem_data.polext = ptr_new(obs_st)
ENDIF
IF keyword_set(ext) THEN BEGIN
wavs=ext.wave
;=== Impose central wavelengths for photometric channels
ind=where(ext.filter NE 'SPECTRUM',count)
IF count NE 0 THEN BEGIN
wavs(ind)=dustem_filter2wav(ext(ind).filter)
ENDIF
;=== define observations structure
obs_st={instru_names:ext.instru,filt_names:ext.filter,wav:wavs, values:ext.spec,sigma:ext.error}
;=== fill !dustem_data
!dustem_data.ext = ptr_new(obs_st)
ENDIF
!fit_rchi2_weight.sed=1.
!fit_rchi2_weight.ext=1.
IF NP NE 0 THEN !fit_rchi2_weight.polsed=1.
IF NQ NE 0 THEN !fit_rchi2_weight.qsed=1.
IF NU NE 0 THEN !fit_rchi2_weight.used=1.
;needs the rest
; if keyword_set(polext) then !fit_rchi2_weight.polext=1.
; if keyword_set(polsed) then !fit_rchi2_weight.polsed=1.
; if keyword_set(polfrac) then !fit_rchi2_weight.polfrac=1.
; if keyword_set(qsed) then !fit_rchi2_weight.qsed=1.
; if keyword_set(used) then !fit_rchi2_weight.used=1.
; if keyword_set(qext) then !fit_rchi2_weight.qext=1.
; if keyword_set(uext) then !fit_rchi2_weight.uext=1.
IF keyword_set(rchi2_weight) THEN begin
!fit_rchi2_weight.sed = rchi2_weight.sed
!fit_rchi2_weight.ext = rchi2_weight.ext
IF NP NE 0 THEN !fit_rchi2_weight.polsed = rchi2_weight.polsed
IF NQ NE 0 THEN !fit_rchi2_weight.qsed = rchi2_weight.qsed
IF NU NE 0 THEN !fit_rchi2_weight.used = rchi2_weight.used
;you need to add the rest too
; if keyword_set(polext) then !fit_rchi2_weight.polext = rchi2_weight.polext
; if keyword_set(polsed) then !fit_rchi2_weight.polsed = rchi2_weight.polsed
; if keyword_set(polfrac) then !fit_rchi2_weight.polfrac = rchi2_weight.polfrac
; if keyword_set(qsed) then !fit_rchi2_weight.qsed = rchi2_weight.qsed
; if keyword_set(used) then !fit_rchi2_weight.used = rchi2_weight.used
; if keyword_set(qext) then !fit_rchi2_weight.qext = rchi2_weight.qext
; if keyword_set(uext) then !fit_rchi2_weight.uext = rchi2_weight.uext
endif
return,ptr_new(obs_st)
the_end:
END