Commit 788b55b9a3b397c9977b006fb72c12a299b60315
1 parent
6c9d0328
Exists in
master
added
Showing
2 changed files
with
373 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,287 @@ |
1 | +PRO dustem_fit_sed_spinning_readme,postcript=postcript,mode=mode,help=help | |
2 | + | |
3 | +;This Readme describes how to fit SEDs with dustem with spinning dust turned on. | |
4 | +;It runs on the SED stored into the file sample_SED.xcat | |
5 | +;in this directory. Remember that the goal here is not necessarily to | |
6 | +;obtain a good fit in the end, but to illustrate the method. | |
7 | +;The provided SED has only photometric data points from SPITZER | |
8 | +;IRAC and MIPS and IRAS. No spectrum data points. | |
9 | +;SPECTRUM data points can be included and the corresponding filter | |
10 | +;filed must read SPECTRUM. Note that its is note necessary | |
11 | +;to use the .xcat file format, and data SED can be provided | |
12 | +;manually, but the observation structure must have the structure shown below. | |
13 | +;Obviously, the dustem package must have been installed succesfully (see | |
14 | +;dustem_cvs_readme.txt for install instructions). | |
15 | + | |
16 | +;+ | |
17 | +; NAME: | |
18 | +; dustem_fit_sed_spinning_readme | |
19 | +; PURPOSE: | |
20 | +; This is an example of how to fit SEDs with the dustem wrapper. | |
21 | +; It is meant to be an example to follow when writing your own | |
22 | +; programs using the dustem IDL wrapper. | |
23 | +; It is not meant to reproduce the result in Compiegne et al 2010 | |
24 | +; The SED used here is in sample_SED.xcat | |
25 | +; CATEGORY: | |
26 | +; Dustem | |
27 | +; CALLING SEQUENCE: | |
28 | +; dustem_fit_sed_spinning_readme,postcript=postcript,mode=mode,help=help | |
29 | +; INPUTS: | |
30 | +; None | |
31 | +; OPTIONAL INPUT PARAMETERS: | |
32 | +; None | |
33 | +; OUTPUTS: | |
34 | +; None | |
35 | +; OPTIONAL OUTPUT PARAMETERS: | |
36 | +; None | |
37 | +; ACCEPTED KEY-WORDS: | |
38 | +; mode = Selects one of the dust mixture used by dustem | |
39 | +; 'COMPIEGNE_ETAL2010' from Compiegne et al 2010 (default) | |
40 | +; 'DBP90' from Desert et al 1990 | |
41 | +; 'DL01' from Draine & Li 2001 | |
42 | +; 'DL07' from Draine & Li 2007 | |
43 | +; postcript = if set plot is done in DUSTEM/Docs/Figures/Last_dustem_fit.ps | |
44 | +; help = If set print this help | |
45 | +; COMMON BLOCKS: | |
46 | +; None | |
47 | +; SIDE EFFECTS: | |
48 | +; None | |
49 | +; RESTRICTIONS: | |
50 | +; The dustem fortran code must be installed | |
51 | +; The dustem idl wrapper must be installed | |
52 | +; PROCEDURE: | |
53 | +; None | |
54 | +; EXAMPLES | |
55 | +; dustem_fit_sed_readme,mode='COMPIEGNE_ETAL2010' | |
56 | +; MODIFICATION HISTORY: | |
57 | +; Written by J.P. Bernard April 1st 2011 | |
58 | +; see evolution details on the dustem cvs maintained at CESR | |
59 | +; Contact J.-Ph. Bernard (Jean-Philippe.Bernard@cesr.fr) in case of problems. | |
60 | +;- | |
61 | + | |
62 | +IF keyword_set(help) THEN BEGIN | |
63 | + doc_library,'dustem_fit_sed_spinning_readme' | |
64 | + goto,the_end | |
65 | +ENDIF | |
66 | + | |
67 | +IF keyword_set(mode) THEN BEGIN | |
68 | + use_mode=strupcase(mode) | |
69 | +ENDIF ELSE BEGIN | |
70 | + use_mode='COMPIEGNE_ETAL2010' ;Default is last dustem model | |
71 | +ENDELSE | |
72 | + | |
73 | +dustem_init,mode=use_mode | |
74 | +!dustem_verbose=1 | |
75 | +!dustem_show_plot=1 | |
76 | + | |
77 | +;===== Read the SED | |
78 | +dir=!dustem_wrap_soft_dir+'/Data/SEDs/' | |
79 | +file=dir+'Gal_composite_spectrum.xcat' | |
80 | +spec=read_xcat(file,/silent) | |
81 | +ind=where(spec.error EQ 0.,count) | |
82 | +IF count NE 0 THEN spec(ind).error=0.2*spec(ind).spec | |
83 | +ind=where(spec.instru EQ 'FIRAS',count) | |
84 | +IF count NE 0 THEN spec(ind).error=0.2*spec(ind).spec | |
85 | + | |
86 | +;=== Set which parameters you want to fit | |
87 | +CASE !dustem_which OF | |
88 | + 'WEB3p8':BEGIN | |
89 | +;=== This is to use Desert model | |
90 | +;=== must have done dustem_init,/DBP90 | |
91 | + CASE use_mode OF | |
92 | + 'DBP90':BEGIN | |
93 | + pd = [ $ | |
94 | + '(*!dustem_params).G0', $ ;G0 | |
95 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction | |
96 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction | |
97 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;amCBEx | |
98 | + 'dustem_create_continuum_2'] ;Intensity of NIR continuum | |
99 | + iv = [1.0, 4.3e-4, 4.7e-4,6.4e-3,0.001] | |
100 | +; iv = [4.3e-4, 4.7e-4,6.4e-3,0.001] | |
101 | + Npar=n_elements(pd) | |
102 | + ulimed=replicate(0,Npar) | |
103 | + llimed=replicate(1,Npar) | |
104 | + llims=replicate(0.,Npar) | |
105 | + ;=== Fixed parameters | |
106 | +; fpd=['(*!dustem_params).G0'] ;Fixed parameter description | |
107 | +; fiv=[1.5] | |
108 | +; dustem_init_fixed_params,fpd,fiv | |
109 | + END | |
110 | + 'DL01':BEGIN | |
111 | + pd = [ $ | |
112 | + '(*!dustem_params).G0', $ ;G0 | |
113 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction | |
114 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction | |
115 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra | |
116 | + '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra | |
117 | + '(*!dustem_params).grains(4).mdust_o_mh', $ ;aSil | |
118 | + 'dustem_create_continuum_2'] ;Intensity of NIR continuum | |
119 | + iv = [1.0,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001] | |
120 | +; iv = [5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001] | |
121 | + Npar=n_elements(pd) | |
122 | + ulimed=replicate(0,Npar) | |
123 | + llimed=replicate(1,Npar) | |
124 | + llims=replicate(0.,Npar) | |
125 | + ;=== Fixed parameters | |
126 | +; fpd=['(*!dustem_params).G0'] ;Fixed parameter description | |
127 | +; fiv=[1.0] | |
128 | +; dustem_init_fixed_params,fpd,fiv | |
129 | + END | |
130 | + 'DL07':BEGIN | |
131 | + pd = [ $ | |
132 | + '(*!dustem_params).G0', $ ;G0 | |
133 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction | |
134 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction | |
135 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra | |
136 | + '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra | |
137 | + '(*!dustem_params).grains(4).mdust_o_mh', $ ;aSil | |
138 | + 'dustem_create_continuum_2'] ;Intensity of NIR continuum | |
139 | + iv = [1.0,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001] | |
140 | +; iv = [5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001] | |
141 | + Npar=n_elements(pd) | |
142 | + ulimed=replicate(0,Npar) | |
143 | + llimed=replicate(1,Npar) | |
144 | + llims=replicate(0.,Npar) | |
145 | + ;=== Fixed parameters | |
146 | +; fpd=['(*!dustem_params).G0'] ;Fixed parameter description | |
147 | +; fiv=[1.0] | |
148 | +; dustem_init_fixed_params,fpd,fiv | |
149 | + END | |
150 | + 'COMPIEGNE_ETAL2010':BEGIN | |
151 | +; PUTTING G0 last DOES NOT WORK BECAUSE OF ORDER ISSUE | |
152 | + pd = [ $ | |
153 | + '(*!dustem_params).G0', $ ;G0 | |
154 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction | |
155 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction | |
156 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;amCBEx | |
157 | + '(*!dustem_params).grains(3).mdust_o_mh', $ ;amCBEx | |
158 | + '(*!dustem_params).grains(4).mdust_o_mh', $ ;aSil | |
159 | + 'dustem_create_continuum_2'] ;Intensity of NIR continuum | |
160 | + iv = [1.0, 7.8e-4, 7.8e-4,1.65e-4,1.45e-3,7.8e-3,0.001] | |
161 | +; iv = [7.8e-4, 7.7e-4,1.65e-4,1.45e-3,7.8e-3,0.001] | |
162 | + Npar=n_elements(pd) | |
163 | + ulimed=replicate(0,Npar) | |
164 | + llimed=replicate(1,Npar) | |
165 | + llims=replicate(0.,Npar) | |
166 | + ;=== Fixed parameters | |
167 | +; fpd=['(*!dustem_params).G0'] ;Fixed parameter description | |
168 | +; fiv=[1.0] | |
169 | +; dustem_init_fixed_params,fpd,fiv | |
170 | + END | |
171 | + ENDCASE | |
172 | + END | |
173 | + ELSE: BEGIN | |
174 | + pd = ['(*!dustem_params).grains(0).propmass',$ ;PAH mass fraction | |
175 | + '(*!dustem_params).grains(1).propmass',$ ;VSG mass fraction | |
176 | + '(*!dustem_params).grains(2).propmass',$ ;BG mass fraction | |
177 | + 'dustem_create_continuum_2', $ ;Intensity of NIR continuum | |
178 | + 'dustem_create_isrf_1'] ;ISRF scaling factor | |
179 | + ;=== set initial value of parameters you want to fit | |
180 | + iv = [7e-5, 8e-4,6.6e-3,0.001,4.] | |
181 | + ;in this example, we enforce parameters to be >0 and Xisrf >3 | |
182 | + ;Caution, initial values must be within limits ... | |
183 | + Npar=n_elements(pd) | |
184 | + ulimed=replicate(0,Npar) | |
185 | + llimed=replicate(1,Npar) | |
186 | + llims=replicate(0.,Npar) | |
187 | + END | |
188 | +ENDCASE | |
189 | + | |
190 | + | |
191 | +;=== SET THE OBSERVATION STRUCTURE | |
192 | +st=dustem_set_data(sed=spec) | |
193 | + | |
194 | +;== SET THE FITTED PARAMETERS | |
195 | +dustem_init_parinfo,pd,iv,up_limited=ulimed,lo_limited=llimed,up_limits=ulims,lo_limits=llims | |
196 | +;stop | |
197 | +;help,(*!dustem_params).grains[0],/str | |
198 | +;(*!dustem_params).grains[0].TYPE_KEYWORDS='mix-logn-spin' | |
199 | + | |
200 | +;dustem_sort_params | |
201 | +;hprint,*(*!dustem_fit).param_descs | |
202 | +;hprint,*(*!dustem_fit).param_init_values | |
203 | +;hprint,*(*!dustem_fit).param_func | |
204 | +;=== RUN fit | |
205 | +tol=1.e-14 | |
206 | +Nitermax=2 ;maximum number of iteration. This is the criterium which will stop the fit procedure | |
207 | + | |
208 | +loadct,13 | |
209 | +!y.range=[1e-4,10] ;This is to ajust plot range from outside the routine | |
210 | +t1=systime(0,/sec) | |
211 | +res=dustem_mpfit_data(tol=tol,Nitermax=Nitermax,gtol=gtol) | |
212 | +t2=systime(0,/sec) | |
213 | + | |
214 | + | |
215 | + | |
216 | + | |
217 | +;=== SAVE FIT RESULTS | |
218 | +;file_out=getenv('DUSTEM_RES')+'DUSTEM_fit_example.sav' | |
219 | +file_out=!dustem_res+'DUSTEM_fit_example.sav' | |
220 | +dustem_save_sed_fit,file_out | |
221 | + | |
222 | +;=== Plot best fit | |
223 | +yr=[1e-4,10] | |
224 | +xr=[1,2000] | |
225 | +tit='DUSTEM Example' | |
226 | +ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2') | |
227 | +xtit=textoidl('\lambda (\mum)') | |
228 | +errors=(*(*!dustem_fit).current_param_errors)*(*(*!dustem_fit).param_init_values) | |
229 | +chi2=(*!dustem_fit).chi2 | |
230 | +rchi2=(*!dustem_fit).rchi2 | |
231 | + | |
232 | +loadct,13 | |
233 | +dustem_sed_plot,(*(*!dustem_fit).current_param_values), $ | |
234 | + ytit=ytit,xtit=xtit,title=tit,yr=yr,xr=xr,/ysty,/xsty, $ | |
235 | + res=res,errors=errors,chi2=chi2,rchi2=rchi2 | |
236 | + | |
237 | +;stop | |
238 | + | |
239 | +;====================================== | |
240 | +;====You can exit IDL here and re-enter | |
241 | +;====================================== | |
242 | +window,1 | |
243 | + | |
244 | +;=== RESTORE FIT RESULTS | |
245 | +;=== initialise dustem | |
246 | +dustem_init,mode=mode | |
247 | +;file=getenv('DUSTEM_RES')+'DUSTEM_fit_example.sav' | |
248 | +file=!dustem_res+'DUSTEM_fit_example.sav' | |
249 | +dustem_restore_sed_fit,file | |
250 | + | |
251 | +;=== recover best fit values | |
252 | +;ind=where(*!dustem_fit_chi2 EQ min(*!dustem_fit_chi2)) | |
253 | +;res=(*!dustem_fit_params); | |
254 | +res=*(*!dustem_fit).current_param_values | |
255 | +chi2=(*!dustem_fit).chi2 | |
256 | +rchi2=(*!dustem_fit).rchi2 | |
257 | +;model_sed=*!dustem_fit_sed | |
258 | +;errors=*!dustem_fit_params_error; | |
259 | +errors=*(*!dustem_fit).current_param_errors | |
260 | + | |
261 | +;=== Plot best fit | |
262 | +yr=[1e-4,10] | |
263 | +xr=[1,2000] | |
264 | +tit='DUSTEM Example (Saved)' | |
265 | +ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2') | |
266 | +xtit=textoidl('\lambda (\mum)') | |
267 | + | |
268 | +loadct,13 | |
269 | +IF keyword_set(postcript) THEN BEGIN | |
270 | + set_plot,'PS' | |
271 | +; ps_file=getenv('DUSTEM_SOFT_DIR')+'/Docs/Figures/'+'Last_dustem_fit.ps' | |
272 | + ps_file=!dustem_wrap_soft_dir+'/Docs/Figures/'+'Last_dustem_fit.ps' | |
273 | + device,filename=ps_file,/color | |
274 | +ENDIF | |
275 | +;dustem_sed_plot,(*!dustem_fit_params),ytit=ytit,xtit=xtit,title=tit,yr=yr,xr=xr,/ysty,/xsty,res=res,errors=errors,chi2=chi2,rchi2=rchi2 | |
276 | +dustem_sed_plot,*(*!dustem_fit).current_param_values,ytit=ytit,xtit=xtit,title=tit,yr=yr,xr=xr,/ysty,/xsty,res=res,errors=errors,chi2=chi2,rchi2=rchi2 | |
277 | +IF keyword_set(postcript) THEN BEGIN | |
278 | + device,/close | |
279 | + set_plot,'X' | |
280 | + message,'wrote '+ps_file,/info | |
281 | +ENDIF | |
282 | + | |
283 | +message,'dustem_mpfit_sed executed in '+strtrim(t2-t1,2)+' sec',/info | |
284 | + | |
285 | +the_end: | |
286 | + | |
287 | +END | ... | ... |
... | ... | @@ -0,0 +1,86 @@ |
1 | +PRO dustem_plot_extinction,st,st_model,_Extra=extra,help=help | |
2 | + | |
3 | +;+ | |
4 | +; NAME: | |
5 | +; dustem_plot_extinction | |
6 | +; PURPOSE: | |
7 | +; Plots a Dustem extinction | |
8 | +; CATEGORY: | |
9 | +; Dustem | |
10 | +; CALLING SEQUENCE: | |
11 | +; dustem_plot_extinction,st,st_model[,/help][,_extra=] | |
12 | +; INPUTS: | |
13 | +; st = Dustem model output structure | |
14 | +; st_model = Dustem model parameters structure | |
15 | +; OPTIONAL INPUT PARAMETERS: | |
16 | +; _extra = extra parameters for the plot routine | |
17 | +; OUTPUTS: | |
18 | +; None | |
19 | +; OPTIONAL OUTPUT PARAMETERS: | |
20 | +; None | |
21 | +; ACCEPTED KEY-WORDS: | |
22 | +; help = If set, print this help | |
23 | +; COMMON BLOCKS: | |
24 | +; None | |
25 | +; SIDE EFFECTS: | |
26 | +; model is plotted | |
27 | +; RESTRICTIONS: | |
28 | +; The dustem idl wrapper must be installed | |
29 | +; PROCEDURE: | |
30 | +; None | |
31 | +; EXAMPLES | |
32 | +; dustem_init,/wrap | |
33 | +; dir_in=getenv('DUSTEM_SOFT_DIR')+'/src/dustem3.8_web/' | |
34 | +; st_model=dustem_read_all(dir_in) | |
35 | +; dir=getenv('DUSTEM_RES') | |
36 | +; st=dustem_read_all_res(dir_in) | |
37 | +; loadct,13 | |
38 | +; dustem_plot_extinction,st,st_model,yr=[1.e-6,1.e0],/ysty,xr=[1.,400],/xsty | |
39 | +; MODIFICATION HISTORY: | |
40 | +; Written by J.-Ph. Bernard | |
41 | +; see evolution details on the dustem cvs maintained at CESR | |
42 | +; Contact J.-Ph. Bernard (Jean-Philippe.Bernard@cesr.fr) in case of problems. | |
43 | +;- | |
44 | + | |
45 | +IF keyword_set(help) THEN BEGIN | |
46 | + doc_library,'dustem_plot_extinction' | |
47 | + goto,the_end | |
48 | +ENDIF | |
49 | + | |
50 | +;stop | |
51 | +;Ngrains=n_tags(st.dustem)-2 | |
52 | +Ngrains=st_model.Ngrains | |
53 | + | |
54 | +colors=dustem_grains_colors(Ngrains) | |
55 | +;colmax=210 & colmin=30 | |
56 | +;colors=findgen(Ngrains)/(1.*Ngrains-1)*(colmax-colmin)+colmin | |
57 | + | |
58 | +xtit=textoidl('\lambda (\mum)') | |
59 | +;ytit=textoidl('extinction (cm^2/g)') & fact=1. | |
60 | +ytit=textoidl('\sigma_{ext} (1e-21 cm^2/H)') & mH=1.66e-24 & fact=mH*1.e21 | |
61 | +tit='Dustem extinction' | |
62 | + | |
63 | +;stop | |
64 | + | |
65 | +i=0L | |
66 | +;plot_oo,st.ext.wav,st.ext.abs_grain(i)*fact,/nodata,_Extra=extra,xtit=xtit,ytit=ytit,tit=tit | |
67 | +ffact=fact*st_model.grains(i).MDUST_O_MH | |
68 | +plot_oo,st.ext.wav,(st.ext.abs_grain(i)+st.ext.sca_grain(i))*ffact,/nodata,_Extra=extra,xtit=xtit,ytit=ytit,tit=tit | |
69 | +abs_tot=st.ext.abs_grain(i)*0. | |
70 | +sca_tot=st.ext.sca_grain(i)*0. | |
71 | +FOR i=0L,Ngrains-1 DO BEGIN | |
72 | + ffact=fact*st_model.grains(i).MDUST_O_MH | |
73 | + oplot,st.ext.wav,(st.ext.abs_grain(i)+st.ext.sca_grain(i))*ffact,color=colors(i),psym=psym | |
74 | +; oplot,st.ext.wav,st.ext.abs_grain(i)*fact,color=colors(i-1),psym=psym | |
75 | +; oplot,st.ext.wav,st.ext.sca_grain(i)*fact,color=colors(i-1),psym=psym,linestyle=2 | |
76 | + abs_tot=abs_tot+st.ext.abs_grain(i)*ffact | |
77 | + sca_tot=sca_tot+st.ext.sca_grain(i)*ffact | |
78 | +ENDFOR | |
79 | +oplot,st.ext.wav,(abs_tot+sca_tot),color=255,psym=psym | |
80 | +;oplot,st.dustem.wav,(abs_tot+sca_tot),color=255,psym=psym | |
81 | +;oplot,st.dustem.wav,abs_tot*fact,color=255,psym=psym | |
82 | +;oplot,st.dustem.wav,sca_tot*fact,color=255,psym=psym,linestyle=2 | |
83 | + | |
84 | +the_end: | |
85 | + | |
86 | +END | ... | ... |