Commit b125205a5b9c28a2f3fa6408ca0d1aa471bcf690

Authored by Annie Hughes
1 parent 553fad92
Exists in master

updated examples to conform with webpages

src/idl/dustem_fit_ext_pol_example.pro
... ... @@ -216,7 +216,7 @@ if not keyword_set(ext_file) then begin
216 216 dustem_set_data, m_fit,m_show,ext,ext
217 217  
218 218 IF keyword_set(wait) THEN BEGIN
219   - message,'Finished generating a synthetic EXT from the model',/info
  219 + message,'Finished generating a synthetic EXT from the model '+use_model,/info
220 220 wait,wait
221 221 ENDIF
222 222  
... ...
src/idl/dustem_fit_intensity_example.pro
... ... @@ -138,10 +138,8 @@ dustem_define_la_common
138 138  
139 139 ;=== AN EXAMPLE FOR DBP90
140 140 ;=== Here we fit the dust abundances of the DBP90 model, the
141   -;=== intensity of the dust-heating radiation field, as well as several plug-ins:
142   -;=== (i) continuum due to a blackbody
143   -;=== (ii) free-free emission
144   -;=== (iii) synchrotron emission
  141 +;=== intensity of the dust-heating radiation field, as well as a plug-in
  142 +;=== for synchrotron emission
145 143 ;=== The free parameters are all lower-bounded at zero.
146 144 ;=== use_model='DBP90' ; you should specify this above!
147 145 pd = [ $
... ...
src/idl/dustem_myisrf_example.pro 100755 → 100644
1 1 PRO dustem_myisrf_example,model=model $
2 2 ,sed_file=sed_file $
  3 + ,isrf_file=isrf_file $
3 4 ,Nitermax=Nitermax $
4 5 ,postscript=postscript $
5 6 ,fits_save_and_restore=fits_save_and_restore $
... ... @@ -11,11 +12,11 @@ PRO dustem_myisrf_example,model=model $
11 12 ; NAME:
12 13 ; dustem_fit_myisrf_example
13 14 ;
14   -; PURPOSE:
15   -; This routine is an example of how to fit an observational SED
16   -; (StokesI only) with DustEM and DustEMWrap. The objective is to
17   -; illustrate how to use the modify_isrf plugin and not to do science -- the fit
18   -; obtained by running this example is likely to be poor.
  15 +; PURPOSE: This routine is an example of how to fit an observational
  16 +; SED (StokesI only) with DustEM and DustEMWrap. The objective is to
  17 +; illustrate how to use dustem_plugin_modify_isrf and not to do
  18 +; science -- the fit obtained by running this example is likely to be
  19 +; poor.
19 20 ;
20 21 ; For this example, the code uses the SED in the file example_SED_2.xcat,
21 22 ; which is distributed in the Data/EXAMPLE_OBSDATA/ directory
... ... @@ -30,11 +31,12 @@ PRO dustem_myisrf_example,model=model $
30 31 ; DustEMWrap, Distributed, High-Level, User Example
31 32 ;
32 33 ; CALLING SEQUENCE:
33   -; dustem_fit_myisrf_example[,model=][sed_file=][,postscript=][,Nitermax=][,fits_save_and_restore=][,/help,/wait,/verbose]
  34 +; dustem_fit_myisrf_example[,model=][,sed_file=][,isrf_file=][,postscript=][,Nitermax=][,fits_save_and_restore=][,/help,/wait,/verbose]
34 35 ;
35 36 ; INPUTS:
36   -; None
37   -;
  37 +; sed_file = file in .xcat format containing observational SED
  38 +; isrf_file = text file describing ISRF
  39 +;
38 40 ; OPTIONAL INPUT PARAMETERS:
39 41 ; None
40 42 ;
... ... @@ -92,7 +94,7 @@ PRO dustem_myisrf_example,model=model $
92 94  
93 95  
94 96 IF keyword_set(help) THEN BEGIN
95   - doc_library,'dustem_stellarpopisrf_example'
  97 + doc_library,'dustem_myisrf_example'
96 98 goto,the_end
97 99 END
98 100  
... ... @@ -104,6 +106,8 @@ ENDELSE
104 106  
105 107  
106 108 use_verbose=0
  109 +use_polarization=0 ; initialize Dustemwrap in no polarization mode
  110 +use_window=2 ; default graphics window number to use for plotting the results
107 111 if keyword_set(verbose) then use_verbose=1
108 112 use_Nitermax=5 ; maximum number of iterations for the fit
109 113 IF keyword_set(Nitermax) THEN use_Nitermax=Nitermax
... ... @@ -114,155 +118,25 @@ dustem_define_la_common
114 118 ;=== Refer to the DustEM and DustEMWrap userguides for an explanation
115 119 ; of the different grain types
116 120  
117   -CASE use_model OF
118   - 'DBP90':BEGIN
119   - pd = [ $
120   - '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction
121   - '(*!dustem_params).grains(1).mdust_o_mh',$ ;VSG mass fraction
122   - '(*!dustem_params).grains(2).mdust_o_mh', $ ;amCBEx
123   - 'dustem_plugin_modify_isrf_1'] ;amplitude of user-defined ISRF (here G0 because mathis is chosen)
124   - rv = [4.3e-4, 4.7e-4,6.4e-3,100.] ;rv because we're generating fake data and try to retrieve the original values
125   -
126   - iv = rv+[5.00E-4,5.00E-4,5.00E-4,-30] ;###setting the initial parameter vector
127   -
128   - Npar=n_elements(pd)
129   - ulimed=replicate(0,Npar)
130   - llimed=replicate(1,Npar)
131   - llims=replicate(0.,Npar)
132   -
133   -
134   -; fpd=[ $
135   -; 'dustem_plugin_stellar_population_O7V4',$ ;number of stars of stellar population' , $ ;multiplicative factor to total ISRF
136   -; 'dustem_plugin_stellar_population_O5V3'$ ; stellar distance
137   -; ]
138   -; ;initial parameter values for fixed parameters
139   -; fiv=[ $
140   -; 2. , $ ;number of stars of pop O7
141   -; 45$ ;dustance of pop O5
142   -; ]
143   -
144   - END
145   - 'DL01':BEGIN
146   - pd = [ $
147   - '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction
148   - '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction
149   - '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra
150   - '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra
151   - '(*!dustem_params).grains(4).mdust_o_mh', $ ;aSil
152   - 'dustem_plugin_modify_isrf_1'] ;Amplitude of user-defined ISRF
153   -
154   - rv = [5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,50]
155   - iv = rv+[5.e-4, 5.e-4,5.e-5,5.e-3,5.e-3,100]
156   -
157   -; fpd=[ $
158   -; 'dustem_plugin_stellar_population_O5V3'$ ; stellar distance
159   -; ]
160   -; ;initial parameter values for fixed parameters
161   -; fiv=[ $
162   -; 45$ ;fixed stellar distance
163   -; ]
164   -
165   -
166   - Npar=n_elements(pd)
167   - ulimed=replicate(0,Npar)
168   - llimed=replicate(1,Npar)
169   - llims=replicate(0.,Npar)
170   - END
171   - 'WD01_RV5p5B':BEGIN
172   -;; ***COMMENT AH***
173   -;; we need to implement this, or remove
174   - message, 'WD01 model not yet implemented in DustEMWrap',/info
175   -;; ***END COMMENT AH***
176   - END
177   - 'DL07':BEGIN ;takes at least 16 iterations to find minima.
178   - pd = [ $
179   - '(*!dustem_params).grains(0).mdust_o_mh', $ ;PAH0 mass fraction
180   - '(*!dustem_params).grains(1).mdust_o_mh', $ ;PAH1 mass fraction
181   - '(*!dustem_params).grains(2).mdust_o_mh', $ ;Gra
182   - '(*!dustem_params).grains(3).mdust_o_mh', $ ;Gra
183   - '(*!dustem_params).grains(4).mdust_o_mh', $ ;aSil
184   - 'dustem_plugin_modify_isrf_1', $ ;amplitude of user-defined ISRF
185   - 'dustem_plugin_stellar_population_O5V3' $ ;distance to stellar pop O5
186   - ]
187   -
188   - rv = [5.4e-4, 5.4e-4,1.8e-4,2.33e-3,8.27e-3,5.,1.];,10,1.,10.,1.]
189   - iv = rv+ [5.e-4, 5.e-4,5.e-4,5.e-3,5.e-3,5.,2]
190   -
191   - Npar=n_elements(pd)
192   - ulimed=replicate(0,Npar)
193   - llimed=replicate(1,Npar)
194   - llims=replicate(0.,Npar)
195   -
196   - fpd=[ $
197   - 'dustem_plugin_stellar_population_O5V4',$ ; stellar number of pop O5V
198   - '(*!dustem_params).G0' $
199   - ]
200   - ;initial parameter values for fixed parameters
201   - fiv=[ $
202   - 30., $ ;fixed stellar population number
203   - 10. $
204   - ]
205   -
206   - END
207   - 'MC10':BEGIN
208   -
209   - pd = [ $
210   - 'dustem_plugin_modify_isrf_1', $ ;amplitude of user-defined ISRF
211   - '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction
212   - '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction
213   - '(*!dustem_params).grains(2).mdust_o_mh', $ ;amCBEx
214   - '(*!dustem_params).grains(3).mdust_o_mh', $ ;amCBEx
215   - '(*!dustem_params).grains(4).mdust_o_mh' $ ;aSilx
216   - ]
217   - ;initial parameter values for parameters to be fitted
218   - rv = [ $
219   - 50, $
220   - 7.8e-4, $ ;mass fraction of PAH0
221   - 7.8e-4, $ ;mass fraction of PAH1
222   - 1.65e-4, $ ;mass fraction of amCBEx
223   - 1.45e-3, $ ;mass fraction of amCBEx
224   - 7.8e-3 $ ;mass fraction of aSilx
225   - ]
226   -
227   - iv = rv + [-30,5.E-4,5.E-4,5.E-4,5.E-3,5.E-3]
228   -
229   -; fpd = ['dustem_plugin_stellar_population_O5V3'] ;distance to stellar population O5V
230   -; fiv = [25]
231   -
232   -
233   - Npar=n_elements(pd)
234   -
235   - ulimed=replicate(0,Npar)
236   - llimed=replicate(1,Npar)
237   - llims=replicate(0.,Npar)
238   -
239   - END
240   - 'J13':BEGIN
241   - pd = [ $
242   - '(*!dustem_params).grains(1).mdust_o_mh',$ ;CM20 mass fraction
243   - '(*!dustem_params).grains(0).mdust_o_mh',$ ;CM20 mass fraction
244   - '(*!dustem_params).grains(2).mdust_o_mh', $ ;aPyM5
245   - '(*!dustem_params).grains(3).mdust_o_mh', $ ;aPyM5
246   - 'dustem_plugin_modify_isrf_1'] ;amplitude of user-defined ISRF
247   -
248   - rv = [7.8e-4, 7.8e-4,1.65e-4,1.45e-3,35]
249   - iv = rv+ [5.e-4,5.e-4,5.e-4,5.e-3,35]
250   -
251   - Npar=n_elements(pd)
252   - ulimed=replicate(0,Npar)
253   - llimed=replicate(1,Npar)
254   - llims=replicate(0.,Npar)
255   -
256   -; fpd = ['dustem_plugin_stellar_population_O5V3'] ;distance to stellar population O5V
257   -; fiv = [5]
258   -
259   - END
260   - 'ELSE':BEGIN
261   - message,'model '+model+' unknown',/continue
262   - message,'Known models are MC10,DBP90,DL01,DL07,J13,G17_MODELA,G17_MODELB,G17_MODELC,G17_MODELD',/continue
263   - stop
264   - END
265   -ENDCASE
  121 +
  122 +;; ;=== AN EXAMPLE FOR DL07 (or DL01 or WD01_RV5P5B)
  123 +;; ;=== Here we fit the PAH abundances of the model, and the amplitude
  124 +;; ;=== of a user-supplied ISRF.
  125 +;; ;=== The other grain parameters are fixed to their default values.
  126 +;; ;=== The free parameters are all lower-bounded at zero.
  127 +;; use_model='DL07' ; you should specify this above, or in the command line
  128 +pd = [ $
  129 + '(*!dustem_params).grains(0).mdust_o_mh',$ ;PAH0 mass fraction
  130 + '(*!dustem_params).grains(1).mdust_o_mh',$ ;PAH1 mass fraction
  131 + 'dustem_plugin_modify_isrf_1', $ ; Ampitude of user-defined ISRF
  132 + 'dustem_plugin_synchrotron_2'] ;Synchrotron amplitude at 10 mm
  133 + iv = [5.4e-4, 5.4e-4,0.1, 0.01]
  134 + Npar=n_elements(pd)
  135 + ulimed=replicate(0,Npar)
  136 + llimed=replicate(1,Npar)
  137 + llims=replicate(0.,Npar)
  138 +; fpd=['(*!dustem_params).G0']
  139 +; fiv=[1.e-10]
266 140  
267 141  
268 142 if keyword_set(wait) then begin
... ... @@ -271,26 +145,53 @@ if keyword_set(wait) then begin
271 145 end
272 146  
273 147  
274   -dustem_init,model=use_model
275   -
  148 +dustem_init,model=use_model,polarization=use_polarization
276 149 !dustem_nocatch=1
277   -!dustem_verbose=1
278   -;!dustem_show_plot=1
279   -!EXCEPT=2 ;so I can locate the plotting error...
280   -;!dustem_dim=1 ; this option is to dim the stellar population ISRF with the current Dustem extinction
281   -;We're fitting total optical depths so the dimmed-ISRF scenario is a reasonable assumption.
282   -;Because of this the final parameter values are slightly lower than the initial (real) values.
283   -;But this is because the first run was not extinct with the current dustem extinction
284   -;since it comes prior to the dustem run. Meaning the first ISRF has to be extinct to see if the paramters are retrieved.
285   -
286   -!dustem_isrf_file=ptr_new(!dustem_soft_dir+'data/ISRF_MATHIS.DAT')
287   -
288   -;=== READ EXAMPLE DATA: EXTINCTION
289   -
290   -;NB:HERE WE ARE NOT FITTING THE DATA. WE'RE JUST USING THE EXISTING FILTERS.
291   -
  150 +!dustem_verbose=use_verbose
  151 +
  152 +;== Fill a structure with default inputs to the model. This
  153 +;== includes the default ISRF, which we want here just for plotting a
  154 +;comparison to the ISRF that we construct.
  155 +dir_in=!dustem_soft_dir
  156 +st_model=dustem_read_all(dir_in)
  157 +
  158 +;=== CREATE A DIFFERENT ISRF AND DUMP TO FILE
  159 +if not keyword_set(isrf_file) then begin
  160 + mywaves=[]
  161 + my_isrf_file='./myisrf_3bb_8000K.dat'
  162 + myisrf=dustem_create_rfield([8000,8000,8000],wdil=[1.d-11,1.d-11,1.d-11],isrf=0,fname=my_isrf_file,x=mywaves)
  163 +;myisrf=dustem_create_rfield([3500,4000,5500,6500,8000],wdil=[1.d-13,1.d-13,1.d-13,1.d-13,1.d-13],isrf=1,fname='./myisrf_mathis_5bb.dat',x=mywaves)
  164 +;myisrf=dustem_create_rfield([3500,4000,5500,6500,8000],wdil=[1.d-13,1.d-13,1.d-13,1.d-13,1.d-13],isrf=2,fname='./myisrf_habing_5bb.dat',x=mywaves)
  165 +;myisrf=dustem_create_rfield([3500,4000,5500,6500,8000],wdil=[1.d-13,1.d-13,1.d-13,1.d-13,1.d-13],isrf=0,fname='./myisrf_5bb.dat',x=mywaves)
  166 + isrf_file=my_isrf_file
  167 +endif
  168 +
  169 +
  170 +;=== PLOT AS A SANITY CHECK
  171 +xtit=textoidl('\lambda (\mum)')
  172 +ytit=textoidl('log ISRF [4 \pi I_\nu (erg/cm^2/s/Hz)]')
  173 +tit='DUSTEM MYISRF EXAMPLE'
  174 +yr=[min(st_model.isrf.isrf) < min(myisrf),5.*(max(st_model.isrf.isrf)>max(myisrf))]
  175 +xr=[0.001,1e6]
  176 +window,use_window,xs=600,ys=400,tit=tit & use_window=use_window+2
  177 +cgplot,st_model.isrf.lambisrf,st_model.isrf.isrf $
  178 + ,yr=yr,/ysty,xr=xr,/xsty,/xlog,/ylog $
  179 + ,title=tit,xtit=xtit,ytit=ytit,color=cgcolor('black'),/nodata
  180 +oplot,st_model.isrf.lambisrf,st_model.isrf.isrf,col=cgcolor('black'),thick=2
  181 +oplot,mywaves,myisrf,col=cgcolor('red'),thick=2
  182 +al_legend,/top,/right,clear=0,box=0 $
  183 + ,['default ISRF','my ISRF'] $
  184 + ,linsize=0.5,lines=0 $
  185 + ,color=[cgcolor('black'),cgcolor('red')] $
  186 + ,thick=2,charsize=1.3
  187 +
  188 +;=== READ THE ISRF
  189 +if keyword_set(isrf_file) then !dustem_isrf_file=ptr_new(isrf_file)
  190 +
  191 +
  192 +;=== READ EXAMPLE SED DATA:
292 193 dir=!dustem_wrap_soft_dir+'/Data/EXAMPLE_OBSDATA/'
293   -file=dir+'example_SED_2.xcat'
  194 +file=dir+'example_SED_1.xcat'
294 195 IF keyword_set(sed_file) THEN file=sed_file
295 196 sed=read_xcat(file,/silent)
296 197  
... ... @@ -300,36 +201,15 @@ if keyword_set(wait) then begin
300 201 end
301 202  
302 203  
303   -;=== GENERATE EXAMPLE DATA: EXTINCTION
304   -
305   -;=== initializing IQU and associated errors to avoid problems when checking SED in dustem_set_data.pro
306   -;sed.StokesI=1.
307   -;setting the errors (well equating all the tags to the sigmaii array but this is an initialization)
308   -for i=4l,n_tags(sed)-1 do begin
309   - sed.(i) = sed.sigmaii
310   -endfor
311   -
312   -;###first call to dustem_set_data so that the !dustem_data tags that are used in the 'compute_' procedures are set
313   -
  204 +;== SET THE OBSERVATIONAL STRUCTURE
  205 +;== sed is passed twice -- the first occurrence is the SED that you
  206 +;== wish to fit, the second occurrence is the SED that you wish to visualise.
314 207 dustem_set_data,sed,sed
315 208  
316 209 ; ;== SET INITIAL VALUES AND LIMITS OF THE PARAMETERS THAT WILL BE
317 210 ; ;== ADJUSTED DURING THE FIT
318   -; dustem_init_parinfo,pd,iv,up_limited=ulimed,lo_limited=llimed,up_limits=ulims,lo_limits=llims
319   -;
320   -; ;== INITIALIZE ANY PLUGINS
321   -; dustem_init_plugins, pd,fpd=fpd
322   -;
323   -; dustem_init_fixed_params,fpd,fiv
324   -
325 211 dustem_init_params,use_model,pd,iv,fpd=fpd,fiv=fiv,ulimed=ulimed,llimed=llimed,ulims=ulims,llims=llims
326 212  
327   -;Generating the fake emission data
328   -sed.StokesI = dustem_compute_sed(rv,st=st)
329   -
330   -;== SET THE OBSERVATIONAL STRUCTURE
331   -dustem_set_data, sed,sed
332   -
333 213  
334 214 if keyword_set(wait) then begin
335 215 message,'Finished initializing DustEMWrap, including plugins and fixed parameters',/info
... ... @@ -337,23 +217,19 @@ if keyword_set(wait) then begin
337 217 end
338 218  
339 219 ;== RUN THE FIT
340   -tol=1.e-18
  220 +tol=1.e-16
341 221 use_Nitermax=5 ;maximum number of iterations.
342 222 IF keyword_set(Nitermax) THEN use_Nitermax=Nitermax
343 223  
344   -xr_m = [1.,5e5]
345   -yr_m = [5e-8,1.00e6]
346   -
347   -
348   -tit='Spectral Energy Distribution'
  224 +xr = [1.,5e5]
  225 +yr = [5e-8,1.00e6]
  226 +tit='MYISRF EXAMPLE'
349 227 ytit=textoidl('I_\nu (MJy/sr) for N_H=10^{20} H/cm^2')
350 228 xtit=textoidl('\lambda (\mum)')
351   -;Set show_plot to 0 to hide plot
352   -;Commented or set to 1 is the same since !dustem_show_plot (existing sysvar) is initialized to 1 in dustem_init
353   -;show_plot = 0
  229 +
354 230 t1=systime(0,/sec)
355 231 res=dustem_mpfit_data(tol=tol,Nitermax=use_Nitermax,gtol=gtol $
356   - ,/xlog,/ylog,xr_m=xr_m,yr_m=yr_m,xtit=xtit,ytit=ytit,title=tit $
  232 + ,/xlog,/ylog,xr=xr,yr=yr,xtit=xtit,ytit=ytit,title=tit $
357 233 ,legend_xpos=legend_xpos,legend_ypos=legend_ypos $
358 234 ,errors=errors,chi2=chi2,rchi2=rchi2,show_plot=show_plot)
359 235 t2=systime(0,/sec)
... ... @@ -411,7 +287,7 @@ IF keyword_set(fits_save_and_restore) THEN BEGIN
411 287 ENDIF
412 288 ENDIF
413 289  
414   -message,'Finished dustem_fit_intensity_example',/info
  290 +message,'Finished dustem_myisrf_example',/info
415 291  
416 292  
417 293 the_end:
... ...
src/idl/dustem_run_example.pro
... ... @@ -25,6 +25,7 @@ PRO dustem_run_example, model $
25 25 ; polarisation. See Tables 2 and 3 of that paper for details.
26 26 ; 'G17_ModelB' model B from Guillet et al (2018)
27 27 ; 'G17_ModelC' model C from Guillet et al (2018)
  28 +; 'G17_ModelD' model D from Guillet et al (2018)
28 29 ; OPTIONAL INPUT PARAMETERS:
29 30 ; show = vector specifying the type of plot(s) to show. Possible
30 31 ; values (for all dust models) are
... ... @@ -97,6 +98,7 @@ dir_in=!dustem_soft_dir
97 98 ;== Fill the following structure contains with default inputs to the model
98 99 st_model=dustem_read_all(dir_in)
99 100  
  101 +
100 102 ;=== You could modify the model inputs here by directly editing the values in the
101 103 ;=== st_model structure. To inspect contents, type IDL> help,st_model,/str
102 104 ;=== e.g.
... ...