dustem_run_prediction_example.pro
8.57 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
PRO dustem_run_prediction_example, model $
,filters $
,wave=wave $
,next=next $
,sed_outfile=sed_outfile $
,ext_outfile=ext_outfile $
,polarisation=polarisation $
,show=show $
,fits_save=fits_save $
,noobj=noobj $
,help=help
;+
; NAME:
; dustem_run_prediction_example
;
; PURPOSE:
; This is an example of how to run the DustEM fortran code using
; DustEMWrap and use it to make prediction for fluxes in a set of filters
;
; CATEGORY:
; DustEMWrap, Distributed, High-Level, User Example
;
; CALLING SEQUENCE:
; dustem_run_prediction_example,model,filters,show=show,postscript=postscript,help=help
;
; INPUTS:
; model = specifies the interstellar dust mixture used by
; DustEM. See userguide or dustem_test_model_exists.pro
; for more details about available models in current release.
; filters = specifies the filters for which flux predictions should
; be calculated. The filters will be shown on the plot.
;
; OPTIONAL INPUT PARAMETERS:
; wave = wavelength range specified as [minwave,maxwave] in microns over which
; to construct the extinction curve. The resulting curve
; will be defined on the vector :
; wave_vector=10^(alog10(wave[0])+alog10(wave[1])*findgen(Next)/float(Next))
; default is [0.01,50]
; Next = number of measurements in the extinction curve. Default is 100.
; OUTPUTS:
;
; OPTIONAL OUTPUT PARAMETERS:
; sed_outfile = name of file to write predicted SED (in .xcat
; format). Default is './dustemwrap_predicted_sed.xcat'
; ext_outfile = name of file to write predicted extinction curve (in .xcat
; format). Default is './dustemwrap_predicted_ext.xcat'
;
; ACCEPTED KEY-WORDS:
; help = if set, print this help
; polarisation = if set, run DustemWrap in polarisation mode
; show = if set, show a plot of the predicted SED and the
; model spectra
; fits_save = if set, save the fit results in a binary
; FITS file.
; noobj = if set, runs with no object-oriented graphics
;
; COMMON BLOCKS:
; None
;
; SIDE EFFECTS:
; None
;
; RESTRICTIONS:
; The DustEM fortran code must be installed
; The DustEMWrap IDL code must be installed
;
; PROCEDURE:
; None
;
; EXAMPLES
; dustem_run_prediction_example,'DBP90',['MIRI1','SPIRE3','NIKA21','IRAS1','IRAS2','IRAS3','SPIRE2','SPIRE1','PACS1','WISE3']
;
; MODIFICATION HISTORY:
; Written JPB Apr-2011
; Evolution details on the DustEMWrap gitlab.
; See http://dustemwrap.irap.omp.eu/ for FAQ and help.
;-
IF keyword_set(help) THEN BEGIN
doc_library,'dustem_run_prediction_example'
goto,the_end
ENDIF
exists=dustem_test_model_exists(model)
if exists ne 1 then $
message,'Unknown dust model'
polct=dustem_test_model_exists(model,/pol,/silent)
use_polarisation=0
if keyword_set(polarisation) then use_polarisation=1
;== INITIALISE DUSTEM
dustem_init,model=model,pol=use_polarisation
!dustem_verbose=1
!dustem_show_plot=1
!dustem_which='RELEASE'
dir_in=!dustem_soft_dir
;== READ DEFAULT DUST MODEL VALUES
st_model=dustem_read_all(dir_in)
IF keyword_set(sed_outfile) THEN BEGIN
use_sed_outfile=sed_outfile
ENDIF ELSE BEGIN
use_sed_outfile='./dustmodel_prediction_sed.xcat'
ENDELSE
IF keyword_set(ext_outfile) THEN BEGIN
use_ext_outfile=ext_outfile
ENDIF ELSE BEGIN
use_ext_outfile='./dustmodel_prediction_ext.xcat'
ENDELSE
;=== initialize filters for the SED
Nfilt=n_elements(filters)
sed=dustem_initialize_sed(Nfilt)
sed.filter=filters
sed.wave=dustem_filter2wav(filters)
sed.instru=dustem_filter2instru(filters)
;=== initialize IQU and associated errors to avoid problems when checking SED in dustem_set_data.pro
sed[*].StokesI=1.e-10
sed.StokesQ=sed.StokesI/100.
sed.StokesU=sed.StokesI/100.
sed.SigmaII=sed.StokesI/100.
sed.SigmaQQ=sed.StokesI/100.
sed.SigmaUU=sed.StokesI/100.
sed.SigmaIQ=sed.StokesI/100.
sed.SigmaIU=sed.StokesI/100.
sed.SigmaQU=sed.StokesI/100.
;=== initialize wavelengths for the EXTINCTION
use_next=100 ; number of extinction measurements
use_wave=10^(alog10(0.01)+alog10(50)*findgen(use_next)/float(use_next)) ; wavelengths at which extinction is defined
if keyword_set(next) then use_next=next
if keyword_set(wave) then $
use_wave=range_gen(use_next,[wave[0],wave[1]],/log)
ext=dustem_initialize_ext(use_next)
ext.instru='EXTINCTION'
ext.filter='SPECTRUM'
ext.wave=use_wave
;=== initialize IQU and associated errors to avoid problems when checking EXT in dustem_set_data.pro
ext[*].EXT_I=1.e-10
ext.EXT_Q=ext.EXT_I/100.
ext.EXT_U=ext.EXT_I/100.
ext.SIGEXTII=ext.EXT_I/1000.
ext.SIGEXTQQ=ext.EXT_I/1000.
ext.SIGEXTUU=ext.EXT_I/1000.
ext.SIGEXTIQ=ext.EXT_I/1000.
ext.SIGEXTIU=ext.EXT_I/1000.
ext.SIGEXTQU=ext.EXT_I/1000.
dustem_set_data,m_fit=sed,m_show=sed,x_fit=ext,x_show=ext
;=== initialize at least one parameter as 'free'
;=== this is only to keep dustemwrap happy in its management of variables
;=== no fitting is going to be done
pd = ['(*!dustem_params).gas.G0'] ; G0
pval = [1.]
;=== declare some other parameters as fixed
;=== this shows how to add any non-dust plugins to the observed spectra/SED
;=== for the dust-model parameters, it is not necessary, but allows the
;=== user to (i) change default values and (2) see the adopted values in the graphical output windows
fpd=['(*!dustem_params).G0', $
'(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction
'(*!dustem_params).grains(1).mdust_o_mh',$ ;VSG mass fraction
'(*!dustem_params).grains(2).mdust_o_mh'];,$
; 'dustem_plugin_continuum_1', $ ;
; 'dustem_plugin_continuum_2'] ;
fpval = [1., $
st_model.grains(0).mdust_o_mh,$
st_model.grains(1).mdust_o_mh,$
st_model.grains(2).mdust_o_mh];,$
; 800,$
; 0.05]
;=== initialise all this information into dustemwrap's brain
dustem_init_params,model,pd,pval,fpd=fpd,fiv=fpval,pol=use_polarisation
;=== compute the predicted SED and extinction curve for the dust-model
;=== and any plugins
dustem_Ised=dustem_compute_sed(pval,st=dummy)
dustem_Qsed=dustem_Ised*0.
dustem_Used=dustem_Ised*0.
; uncomment following lines if running a polarisation model and you
;want predictions of QU
;toto=dustem_compute_stokes(pval,st=dummy) ;this procedure also allows for the extraction of the spectra
;dustem_qsed = toto[0]
;dustem_used = toto[1]
dustem_iext=dustem_compute_ext(pval,st=dummy)
dustem_Qext=dustem_Iext*0.
dustem_Uext=dustem_Iext*0.
; uncomment following lines if running a polarisation model and you
;want predictions of QU
;toto=dustem_compute_stokext(pval,st=dummy) ;this procedure also allows for the extraction of the spectra
;dustem_qext = toto[0]
;dustem_uext = toto[1]
;== Now we have a predicted SED (I), we fill up a structure that we
;== will write to the sed_outfile
;== if you
sed.stokesI=dustem_Ised
sed.stokesQ=dustem_Qsed
sed.stokesU=dustem_Used
;=== set uncertainties for I,Q,U to 0.
sed.sigmaII=0.
sed.sigmaQQ=0.
sed.sigmaUU=0.
;=== set covariances to 0.
sed.sigmaIQ=0.
sed.sigmaIU=0.
sed.sigmaQU=0.
;==== fill in dependent columns of the SED.
sed=dustem_fill_sed_dependent_columns(sed)
;======== save the predicted SED to a file
write_xcat,sed,use_sed_outfile
message,'Wrote '+use_sed_outfile,/continue
;== Now we have a predicted extinction (IQU), we fill up a structure that we
;== will write to the ext_outfile
ext.EXT_I=dustem_Iext
ext.EXT_Q=dustem_Qext
ext.EXT_U=dustem_Uext
;=== set uncertainties to 0.
ext.SIGEXTII=abs(ext.EXT_I*0.000001)
ext.SIGEXTQQ=abs(ext.EXT_Q*0.000001)
ext.SIGEXTUU=abs(ext.EXT_U*0.000001)
;=== set covariances to 0.
ext.SIGEXTIQ=0.
ext.SIGEXTIU=0.
ext.SIGEXTQU=0.
;==== fill in dependent columns of the EXT.
ext=dustem_fill_ext_dependent_columns(ext)
;======== save the EXT to a file
write_xcat,ext,use_ext_outfile
message,'Wrote '+use_ext_outfile,/continue
;=== MAKE A PLOT TO VISUALISE THE OUTPUT
IF !dustem_noobj THEN BEGIN
dustemwrap_plot_noobj,*(*!dustem_fit).CURRENT_PARAM_VALUES,st=dummy,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit
ENDIF ELSE BEGIN
dustemwrap_plot,*(*!dustem_fit).CURRENT_PARAM_VALUES,st=dummy,xr=xr,/xstyle,yr=yr,/ysty,/ylog,/xlog,title=tit
ENDELSE
IF keyword_set(fits_save) THEN BEGIN
message,'Writing out results structure: '+fits_save,/info
dustem_write_fits_table,filename=fits_save,help=help
ENDIF
the_end:
message,'Finished dustem_run_prediction_example',/info
stop
END