Blame view

src/idl/dustem_make_polarization_ext_example.pro 6.34 KB
2d758fdd   Annie Hughes   improved commenti...
1
2
3
4
5
6
PRO dustem_make_polarization_ext_example,model=model $
                                         ,wave=wave $
                                         ,next=next $
                                         ,outfile=outfile $
                                         ,help=help $
                                         ,verbose=verbose
9c053027   Annie Hughes   first commit
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


;+
; NAME:
;    dustem_make_polarization_ext_example
;
; PURPOSE:
;    This is an example of how to generate an extinction curve using DustEMWrap.
;    It is meant to be an example to follow when writing your own
;    programs using DustEMWrap
;
; CATEGORY:
;    DustEMWrap, Distributed, High-Level, User Example
;
; CALLING SEQUENCE:
;    dustem_make_polarization_ext_example[,model=][,filters=][,/help]
;
; INPUTS:
2d758fdd   Annie Hughes   improved commenti...
25
26
27
28
29
30
;    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.
9c053027   Annie Hughes   first commit
31
32
33
34
35
36
37
38
39
40
41
42
43
;
; OPTIONAL INPUT PARAMETERS:
;    None
;
; OUTPUTS:
;    None
;
; OPTIONAL OUTPUT PARAMETERS:
;    outfile = path+filename for .xcat output of the EXT
;
; ACCEPTED KEY-WORDS:
;    model     = if set, name of the DustEM dust model to use (default='G17_MODELD')
;    help      = If set print this help
2d758fdd   Annie Hughes   improved commenti...
44
;    verbose      = If set, subroutines will be more chatty
9c053027   Annie Hughes   first commit
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;
; 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_make_polarization_ext_example
;    dustem_make_polarization_ext_example,model='G17_MODELC',outfile='my_polarized_ext.xcat'
;
; MODIFICATION HISTORY:
2d758fdd   Annie Hughes   improved commenti...
64
;    Written by AH Nov-2022
9c053027   Annie Hughes   first commit
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
;    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_make_polarization_ext_example'
  goto,the_end
ENDIF

dustem_define_la_common

IF keyword_set(model) THEN BEGIN
  use_model=strupcase(model)
ENDIF ELSE BEGIN
  use_model='G17_MODELD'    ;Default is one of the Guillet et al (2017) models since they treat dust polarisation properties
ENDELSE

IF keyword_set(outfile) THEN BEGIN
  use_outfile=outfile
ENDIF ELSE BEGIN
  use_outfile='./polarization_ext.xcat'
ENDELSE

known_mdls=['MC10','DBP90','DL01','WD01_RV5P5B','DL07','J13','G17_MODELA','G17_MODELB','G17_MODELC','G17_MODELD'] 
pol_mdls=['G17_MODELA','G17_MODELB','G17_MODELC','G17_MODELD'] 
test_model = where(known_mdls eq use_model,ct)
if ct eq 0 then begin
   message,'ISM dust model '+use_model+' unknown',/continue
   message,'Known models are MC10,DBP90,DL01,WD01_RV5P5B,DL07,J13,G17_MODELA,G17_MODELB,G17_MODELC,G17_MODELD',/continue
   stop
end
test_model = where(pol_mdls eq use_model,ct)
if ct eq 0 then begin
   message,'The only models with polarisation are G17_MODELA,G17_MODELB,G17_MODELC,G17_MODELD',/continue
   stop
end

use_verbose=0
2d758fdd   Annie Hughes   improved commenti...
103
104
105
use_polarization=1
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
9c053027   Annie Hughes   first commit
106
if keyword_set(verbose) then use_verbose=1
2d758fdd   Annie Hughes   improved commenti...
107
108
if keyword_set(next) then use_next=next
if keyword_set(wave) then use_wave=10^(alog10(wave[0])+alog10(wave[1])*findgen(use_next)/float(use_next))
9c053027   Annie Hughes   first commit
109

2d758fdd   Annie Hughes   improved commenti...
110
111
   
dustem_init,mode=use_model,polarization=use_polarization
9c053027   Annie Hughes   first commit
112
113
114
115
116
117
118
119
120
121
122
123
124
!dustem_verbose=use_verbose
!dustem_nocatch=1

;=== initialize wavelengths for the EXTINCTION
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.
ext.EXT_Q=ext.EXT_I/100.
ext.EXT_U=ext.EXT_I/100.
2d758fdd   Annie Hughes   improved commenti...
125
126
127
128
129
130
131
132
133
134
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.

;=== Set which model parameters to use for the EXT, this will depend
;=== on the selected dust model. For model parameters not specified
;=== here, the default Dustem fortran values will be used
9c053027   Annie Hughes   first commit
135
pd = [ $
2d758fdd   Annie Hughes   improved commenti...
136
137
     '(*!dustem_params).grains(0).mdust_o_mh', $          ;PAH0_MC10 mass fraction
     '(*!dustem_params).grains(1).mdust_o_mh', $          ;amCBE_0.3333x mass fraction   
9c053027   Annie Hughes   first commit
138
     '(*!dustem_params).grains(2).mdust_o_mh', $         ;aSil2001BE6pctG_0.4x mass fraction
2d758fdd   Annie Hughes   improved commenti...
139
140
141
     'dustem_plugin_modify_dust_polx_2' $                 ;Dust polarization angle in extinction
     ]                   
true_vals=[7.8000E-04,7.8000E-04,7.8000E-04, 52.]
9c053027   Annie Hughes   first commit
142

9c053027   Annie Hughes   first commit
143
144
145
146
147
148
149
150
151

Npar=n_elements(pd)  
ulimed=replicate(0,Npar)
llimed=replicate(1,Npar) & llimed[3]=0
llims=replicate(0,Npar)

;== SET INITIAL VALUES AND LIMITS OF THE PARAMETERS FOR THE FIT 
;== AND ACTIVATE ANY PLUGINS
;== FOR REASONS, WE NEED TO DO THIS DUSTEM_SET_DATA CALL
2d758fdd   Annie Hughes   improved commenti...
152
dustem_init_params,use_model,pd,true_vals,pol=use_polarization,fpd=fpd,fiv=fiv,ulimed=ulimed,llimed=llimed,ulims=ulims,llims=llims
9c053027   Annie Hughes   first commit
153
154
155
156
157
158
159


;=== initialize the !dustem_data structure that will be used internally
;== note that m_fit and m_show do not exist -- this is deliberate
;== since we are not treating emission data
dustem_set_data,m_fit,m_show,ext,ext

2d758fdd   Annie Hughes   improved commenti...
160
161
;=== compute the extinction curve (I then QU) using the model and specified
;=== true_vals of parameters
9c053027   Annie Hughes   first commit
162
163
164
165
166
dustem_iext=dustem_compute_ext(true_vals,st=ssti) ;sst is not set on purpose, for dustem_compute_ext to compute the ext using fortran code
toto=dustem_compute_stokext(true_vals,st=sstqu) ;this procedure also allows for the extraction of the spectra
dustem_qext = toto[0]
dustem_uext = toto[1]

9c053027   Annie Hughes   first commit
167
168
169
170
171
172
173
174
175
ext.EXT_I=dustem_Iext
ext.EXT_Q=dustem_Qext
ext.EXT_U=dustem_Uext

;=== set uncertainties to I,Q,U
ext.SIGEXTII=abs(ext.EXT_I*0.000001)
ext.SIGEXTQQ=abs(ext.EXT_Q*0.000001)
ext.SIGEXTUU=abs(ext.EXT_U*0.000001)

2d758fdd   Annie Hughes   improved commenti...
176
;=== set covariances to 0.
9c053027   Annie Hughes   first commit
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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_outfile
message,'Wrote '+use_outfile,/continue

;======== move the file to the Data/EXAMPLE_OBSDATA/ subdirectory 
;filename_final=!dustem_wrap_soft_dir+'/Data/EXAMPLE_OBSDATA/my_example_EXT_###.xcat'
;str='cp '+use_outfile+' '+filename_final
;message,'Do '+str+' to make change permanent',/continue

the_end:

END