Commit 8dd965711fa44fc397e5bf1d7761a11513fdb885
1 parent
666cba76
Exists in
master
First commit
Showing
2 changed files
with
373 additions
and
0 deletions
Show diff stats
src/idl/dustem_define_isrf_stellar_modifyer_variable.pro
0 → 100644
... | ... | @@ -0,0 +1,28 @@ |
1 | +FUNCTION dustem_define_isrf_stellar_modifyer_variable,stellar_values=stellar_values | |
2 | + | |
3 | +one_st={radius:0.,temperature:0.,distance:0.,amplitude:0.} | |
4 | + | |
5 | +IF not keyword_set(stellar_values) THEN BEGIN | |
6 | + ;The defaults is one sun at 1au, but with zero amplitude | |
7 | + Nstar=1 | |
8 | + st=replicate(one_st,Nstar) | |
9 | + one_pc=3.08e16 | |
10 | + one_au=1.49e11 | |
11 | + st[0].radius=1. ;Rsun | |
12 | + st[0].temperature=5770. ;K | |
13 | + st[0].distance=one_au/one_pc ;pc | |
14 | + st[0].amplitude=0. ;-- | |
15 | + status=1 | |
16 | +ENDIF ELSE BEGIN | |
17 | + Nstars=n_elements(stellar_values) | |
18 | + ;st=replicate(one_st,Nstar) | |
19 | + st=stellar_values | |
20 | + status=2 | |
21 | +ENDELSE | |
22 | + | |
23 | +defsysv,'!dustem_isrf_star_add',st | |
24 | +message,'defined !dustem_isrf_star_add',/continue | |
25 | + | |
26 | +RETURN,status | |
27 | + | |
28 | +END | |
0 | 29 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,345 @@ |
1 | +PRO dustem_fit_sed_n26_twice,mode=mode,help=help,png=png,postscript=postscript,nitermax=nitermax | |
2 | + | |
3 | +;This Readme describes how to fit SEDs with dustem | |
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_n26 | |
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_n26,postscript=postscript,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 | +; postscript = 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_n26,mode='COMPIEGNE_ETAL2010',nitermax=10 | |
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_n26_twice' | |
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 | +IF keyword_set(png) THEN BEGIN | |
74 | + dir_png='/tmp/Dustem/Figures/' | |
75 | + force_mkdir,dir_png | |
76 | +ENDIF | |
77 | +IF keyword_set(postscript) THEN BEGIN | |
78 | + dir_ps='/tmp/Dustem/Figures/' | |
79 | + force_mkdir,dir_ps | |
80 | +ENDIF | |
81 | + | |
82 | +;dbp=1 | |
83 | +;=== initialise dustem | |
84 | +;dustem_init,/wrap | |
85 | +;dustem_init | |
86 | +dustem_init,mode=use_mode | |
87 | +!dustem_verbose=1 | |
88 | +!dustem_show_plot=1 | |
89 | + | |
90 | +;=== Read sample SED | |
91 | +;=== N26 SED from Longji | |
92 | +dir=!dustem_wrap_soft_dir+'/Data/SEDs/workshop/' | |
93 | +file=dir+'GN26_SED.xcat' | |
94 | +!dustem_redshift=1.22 | |
95 | + | |
96 | +spec=read_xcat(file,/silent) | |
97 | +;stop | |
98 | + | |
99 | +ind=where(spec.error EQ 0.,count) | |
100 | +IF count NE 0 THEN spec(ind).error=0.2*spec(ind).spec | |
101 | +;=== Draine Model SED for U=1. by C. Bot | |
102 | +;;dir=getenv('DUSTEM_SOFT_DIR')+'/src/dustem3.8_web/SEDs/' | |
103 | +;dir=!dustem_wrap_soft_dir+'/Data/SEDs/' | |
104 | +;file=dir+'SED_DraineModel_U1.0.xcat' | |
105 | +;spec=read_xcat(file,/silent) | |
106 | +;=== Fake SED made from Dustem outputs | |
107 | +;spec=dustem_compute_sed(p_dim,st=st,cont=cont,_extra=extra) | |
108 | + | |
109 | +;=== Set which parameters you want to fit | |
110 | +;CASE getenv('DUSTEM_WHICH') OF | |
111 | +CASE !dustem_which OF | |
112 | + 'WEB3p8':BEGIN | |
113 | +;=== This is to use Desert model | |
114 | +;=== must have done dustem_init,/DBP90 | |
115 | + CASE use_mode OF | |
116 | + 'DBP90':BEGIN | |
117 | + pd = [ $ | |
118 | + '(*!dustem_params).G0', $ ;G0 | |
119 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction | |
120 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction | |
121 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;amCBEx | |
122 | + 'dustem_create_continuum_2'] ;Intensity of NIR continuum | |
123 | + iv = [1.0, 4.3e-4, 4.7e-4,6.4e-3,0.001] | |
124 | +; iv = [4.3e-4, 4.7e-4,6.4e-3,0.001] | |
125 | + Npar=n_elements(pd) | |
126 | + ulimed=replicate(0,Npar) | |
127 | + llimed=replicate(1,Npar) | |
128 | + llims=replicate(0.,Npar) | |
129 | + ;=== Fixed parameters | |
130 | +; fpd=['(*!dustem_params).G0'] ;Fixed parameter description | |
131 | +; fiv=[1.5] | |
132 | +; dustem_init_fixed_params,fpd,fiv | |
133 | + END | |
134 | + 'DL01':BEGIN | |
135 | + pd = [ $ | |
136 | + '(*!dustem_params).G0', $ ;G0 | |
137 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction | |
138 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction | |
139 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra | |
140 | + '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra | |
141 | + '(*!dustem_params).grains(4).mdust_o_mh', $ ;aSil | |
142 | + 'dustem_create_continuum_2'] ;Intensity of NIR continuum | |
143 | + iv = [1.0,5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001] | |
144 | +; iv = [5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001] | |
145 | + Npar=n_elements(pd) | |
146 | + ulimed=replicate(0,Npar) | |
147 | + llimed=replicate(1,Npar) | |
148 | + llims=replicate(0.,Npar) | |
149 | + ;=== Fixed parameters | |
150 | +; fpd=['(*!dustem_params).G0'] ;Fixed parameter description | |
151 | +; fiv=[1.0] | |
152 | +; dustem_init_fixed_params,fpd,fiv | |
153 | + END | |
154 | + 'DL07':BEGIN | |
155 | + pd = [ $ | |
156 | + '(*!dustem_params).G0', $ ;G0 | |
157 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction | |
158 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction | |
159 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra | |
160 | + '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra | |
161 | + '(*!dustem_params).grains(4).mdust_o_mh', $ ;aSil | |
162 | + 'dustem_create_continuum_2'] ;Intensity of NIR continuum | |
163 | + iv = [1.0,5.4e-3, 5.4e-3,1.8e-4,2.33e-3,8.27e-3,0.001] | |
164 | +; iv = [5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,0.001] | |
165 | + Npar=n_elements(pd) | |
166 | + ulimed=replicate(0,Npar) | |
167 | + llimed=replicate(1,Npar) | |
168 | + llims=replicate(0.,Npar) | |
169 | + ;=== Fixed parameters | |
170 | +; fpd=['(*!dustem_params).G0'] ;Fixed parameter description | |
171 | +; fiv=[1.0] | |
172 | +; dustem_init_fixed_params,fpd,fiv | |
173 | + END | |
174 | + 'COMPIEGNE_ETAL2010':BEGIN | |
175 | + ; pd = [ $ | |
176 | + ; '(*!dustem_params).gas.G0', $ ;G0 | |
177 | + ; '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH1 mass fraction | |
178 | + ; '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH0 mass fraction | |
179 | + ; '(*!dustem_params).grains(2).mdust_o_mh', $ ;amCBEx | |
180 | + ; '(*!dustem_params).grains(2).alpha_o_a0',$ ;amCBEx slope of size distribution (logn) | |
181 | + ; '(*!dustem_params).grains(3).mdust_o_mh', $ ;amCBEx | |
182 | + ; '(*!dustem_params).grains(4).mdust_o_mh'] ;aSil | |
183 | + ; iv = [45., 7.8e-5, 7.8e-5,1.65e-4,2.e-7,1.45e-3,7.8e-3] | |
184 | + ; Npar=n_elements(pd) | |
185 | + ; ulimed=replicate(0,Npar) | |
186 | + ; llimed=replicate(1,Npar) | |
187 | + ; llims=[0.,0.,0.,0.,0.,0.,0.] | |
188 | + | |
189 | + pd = [ $ | |
190 | + '(*!dustem_params).gas.G0', $ ;G0 | |
191 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH1 mass fraction | |
192 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH0 mass fraction | |
193 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;amCBEx | |
194 | + '(*!dustem_params).grains(3).mdust_o_mh', $ ;amCBEx | |
195 | + '(*!dustem_params).grains(3).alpha_o_a0',$ ;amCBEx slope of size distribution (logn) | |
196 | + '(*!dustem_params).grains(4).mdust_o_mh'] ;aSil | |
197 | + iv = [45., 7.8e-5, 7.8e-5,1.65e-4,1.45e-3,-2.,7.8e-3] | |
198 | + Npar=n_elements(pd) | |
199 | + ulimed=replicate(0,Npar) | |
200 | + llimed=replicate(0,Npar) | |
201 | + llims=[0.,0.,0.,0.,0.,0.,0.] | |
202 | + | |
203 | + ;=== Fixed parameters | |
204 | +; fpd=['(*!dustem_params).G0'] ;Fixed parameter description | |
205 | +; fiv=[1.0] | |
206 | +; dustem_init_fixed_params,fpd,fiv | |
207 | + END | |
208 | + ENDCASE | |
209 | + END | |
210 | + ELSE: BEGIN | |
211 | + pd = ['(*!dustem_params).grains(0).propmass',$ ;PAH mass fraction | |
212 | + '(*!dustem_params).grains(1).propmass',$ ;VSG mass fraction | |
213 | + '(*!dustem_params).grains(2).propmass',$ ;BG mass fraction | |
214 | + 'dustem_create_continuum_2', $ ;Intensity of NIR continuum | |
215 | + 'dustem_create_isrf_1'] ;ISRF scaling factor | |
216 | + ;=== set initial value of parameters you want to fit | |
217 | + iv = [7e-5, 8e-4,6.6e-3,0.001,4.] | |
218 | + ;in this example, we enforce parameters to be >0 and Xisrf >3 | |
219 | + ;Caution, initial values must be within limits ... | |
220 | + Npar=n_elements(pd) | |
221 | + ulimed=replicate(0,Npar) | |
222 | + llimed=replicate(1,Npar) | |
223 | + llims=replicate(0.,Npar) | |
224 | + END | |
225 | +ENDCASE | |
226 | + | |
227 | + | |
228 | +;=== SET THE OBSERVATION STRUCTURE | |
229 | +st=dustem_set_data(sed=spec) | |
230 | + | |
231 | +;== SET THE FITTED PARAMETERS | |
232 | +dustem_init_parinfo,pd,iv,up_limited=ulimed,lo_limited=llimed,up_limits=ulims,lo_limits=llims | |
233 | +;=== RUN fit | |
234 | +tol=1.e-14 | |
235 | +use_Nitermax=2 ;maximum number of iteration. This is the criterium which will stop the fit procedure | |
236 | +IF keyword_set(Nitermax) THEN use_Nitermax=Nitermax | |
237 | + | |
238 | +loadct,13 | |
239 | +;!y.range=[1e-4,10] ;This is to ajust plot range from outside the routine | |
240 | +t1=systime(0,/sec) | |
241 | +yr=[1e-1,1.e3] | |
242 | +xr=[10,10000] | |
243 | +legend_xpos=0.6 | |
244 | +legend_ypos=0.8 | |
245 | +tit='DUSTEMWrap Intensity SED GN26 (Running)' | |
246 | +ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2') | |
247 | +xtit=textoidl('\lambda (\mum)') | |
248 | +res=dustem_mpfit_data(tol=tol,Nitermax=use_Nitermax,gtol=gtol,/xlog,/ylog,xr=xr,yr=yr,xtit=xtit,ytit=ytit,title=tit,legend_xpos=legend_xpos,legend_ypos=legend_ypos,errors=errors,chi2=chi2,rchi2=rchi2) | |
249 | +t2=systime(0,/sec) | |
250 | + | |
251 | +;=== SAVE FIT RESULTS | |
252 | +;file_out=getenv('DUSTEM_RES')+'DUSTEM_fit_example.sav' | |
253 | +file_out='/tmp/DUSTEM_fit_example1.sav' | |
254 | +;dustem_save_sed_fit,file_out | |
255 | +dustem_save_system_variables,file_out | |
256 | +message,'Saved '+file_out,/continue | |
257 | + | |
258 | +;stop | |
259 | + | |
260 | +;==== Doing a second fit | |
261 | +dir=!dustem_wrap_soft_dir+'/Data/SEDs/workshop/' | |
262 | +file=dir+'GN26_SPEC.xcat' | |
263 | + | |
264 | + pd = [ $ | |
265 | + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH1 mass fraction | |
266 | + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH0 mass fraction | |
267 | + '(*!dustem_params).grains(2).mdust_o_mh', $ ;amCBEx | |
268 | + '(*!dustem_params).grains(3).mdust_o_mh', $ ;amCBEx | |
269 | + '(*!dustem_params).grains(3).alpha_o_a0',$ ;amCBEx slope of size distribution (logn) | |
270 | + '(*!dustem_params).grains(4).mdust_o_mh'] ;aSil | |
271 | + iv = [7.8e-5, 7.8e-5,1.65e-4,1.45e-3,-2.,7.8e-3] | |
272 | + Npar=n_elements(pd) | |
273 | + ulimed=replicate(0,Npar) | |
274 | + llimed=replicate(0,Npar) | |
275 | + llims=[0.,0.,0.,0.,0.,0.,0.] | |
276 | + fpd=['(*!dustem_params).gas.G0'] ;Fixed parameter description | |
277 | + fiv=[30.] | |
278 | + dustem_init_fixed_params,fpd,fiv | |
279 | + | |
280 | +dustem_init_parinfo,pd,iv,up_limited=ulimed,lo_limited=llimed,up_limits=ulims,lo_limits=llims | |
281 | + | |
282 | +spec=read_xcat(file,/silent) | |
283 | + | |
284 | +ind=where(spec.error EQ 0.,count) | |
285 | +IF count NE 0 THEN spec(ind).error=0.2*spec(ind).spec | |
286 | + | |
287 | +st=dustem_set_data(sed=spec) | |
288 | + | |
289 | + | |
290 | +;== SET THE FITTED PARAMETERS | |
291 | +dustem_init_parinfo,pd,iv,up_limited=ulimed,lo_limited=llimed,up_limits=ulims,lo_limits=llims | |
292 | +;=== RUN fit | |
293 | +tol=1.e-14 | |
294 | +use_Nitermax=2 ;maximum number of iteration. This is the criterium which will stop the fit procedure | |
295 | +IF keyword_set(Nitermax) THEN use_Nitermax=Nitermax | |
296 | + | |
297 | +res=dustem_mpfit_data(tol=tol,Nitermax=use_Nitermax,gtol=gtol,/xlog,/ylog,xr=xr,yr=yr,xtit=xtit,ytit=ytit,title=tit,legend_xpos=legend_xpos,legend_ypos=legend_ypos,errors=errors,chi2=chi2,rchi2=rchi2) | |
298 | + | |
299 | +file_out='/tmp/DUSTEM_fit_example2.sav' | |
300 | +;dustem_save_sed_fit,file_out | |
301 | +dustem_save_system_variables,file_out | |
302 | +message,'Saved '+file_out,/continue | |
303 | + | |
304 | +;====================================== | |
305 | +;====You can exit IDL here and re-enter | |
306 | +;====================================== | |
307 | + | |
308 | +file='/tmp/DUSTEM_fit_example1.sav' | |
309 | +dustem_restore_system_variables,file | |
310 | + | |
311 | +p_min1=*(*!dustem_fit).current_param_values | |
312 | +dustem_sed1=dustem_compute_sed(p_min1,st=st,cont=cont,freefree=freefree,synchrotron=synchrotron,out_st=out_st1) | |
313 | +st1=out_st1 | |
314 | +z1=!dustem_redshift | |
315 | +help,st1.sed,/str | |
316 | + | |
317 | +file='/tmp/DUSTEM_fit_example2.sav' | |
318 | +dustem_restore_system_variables,file | |
319 | + | |
320 | +p_min2=*(*!dustem_fit).current_param_values | |
321 | +dustem_sed2=dustem_compute_sed(p_min2,st=st,cont=cont,freefree=freefree,synchrotron=synchrotron,out_st=out_st2) | |
322 | +st2=out_st2 | |
323 | +z2=!dustem_redshift | |
324 | +help,st2.sed,/str | |
325 | + | |
326 | +;This is a magic factor to bring SED to the right units | |
327 | +fact = 1.e4*1.E20/(4.*!pi)/(3.e8/1.e-6/st1.sed.wav)*1.e20/1.e7 | |
328 | + | |
329 | +yr=[1e-1,1.e3] | |
330 | +xr=[10,10000] | |
331 | +tit='DUSTEMWrap Intensity SED GN26 (Comparison)' | |
332 | +ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2') | |
333 | +xtit=textoidl('\lambda (\mum)') | |
334 | + | |
335 | +cgplot,st1.sed.wav*(1.+z1),st1.sed.em_tot*fact,/xlog,/ylog,yr=yr,/ysty,xr=xr,/xsty,xtit=xtit,ytit=ytit,tit=tit | |
336 | +cgoplot,st1.sed.wav*(1.+z1),st1.sed.em_grain_4*fact,color='red' | |
337 | + | |
338 | +cgoplot,st2.sed.wav*(1.+z2),st2.sed.em_tot*fact,linestyle=2 | |
339 | +cgoplot,st2.sed.wav*(1.+z2),st2.sed.em_grain_4*fact,color='pink',linestyle=2 | |
340 | + | |
341 | +stop | |
342 | + | |
343 | +the_end: | |
344 | + | |
345 | +END | ... | ... |