Blame view

src/idl/dustem_make_polarization_ext_example.pro 6.02 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


;+
; NAME:
;    dustem_make_polarization_ext_example
;
; PURPOSE:
e431104b   Annie Hughes   general updates f...
14
15
;    This is an example of how to generate an extinction curve (Stokes
;    IQU) using one of the physical dust models in DustEMWrap.
9c053027   Annie Hughes   first commit
16
17
18
19
20
21
22
23
24
25
;    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...
26
27
28
29
30
31
;    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
32
33
34
35
36
37
38
39
40
41
42
;
; OPTIONAL INPUT PARAMETERS:
;    None
;
; OUTPUTS:
;    None
;
; OPTIONAL OUTPUT PARAMETERS:
;    outfile = path+filename for .xcat output of the EXT
;
; ACCEPTED KEY-WORDS:
6735604d   Annie Hughes   making FITS read ...
43
44
45
;    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.
9c053027   Annie Hughes   first commit
46
;    help      = If set print this help
2d758fdd   Annie Hughes   improved commenti...
47
;    verbose      = If set, subroutines will be more chatty
9c053027   Annie Hughes   first commit
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;
; 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...
67
;    Written by AH Nov-2022
9c053027   Annie Hughes   first commit
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;    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

6735604d   Annie Hughes   making FITS read ...
91
92
93
94
exists=dustem_test_model_exists(use_model,/pol)
if exists ne 1 then $
   message,'Unknown/unpolarised dust model: '+use_model

9c053027   Annie Hughes   first commit
95
96

use_verbose=0
2d758fdd   Annie Hughes   improved commenti...
97
98
99
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
100
if keyword_set(verbose) then use_verbose=1
2d758fdd   Annie Hughes   improved commenti...
101
102
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
103

2d758fdd   Annie Hughes   improved commenti...
104
105
   
dustem_init,mode=use_model,polarization=use_polarization
9c053027   Annie Hughes   first commit
106
107
108
109
110
111
112
113
114
115
116
117
118
!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...
119
120
121
122
123
124
125
126
127
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
e431104b   Annie Hughes   general updates f...
128
;=== here, the default DustEM fortran values will be used
9c053027   Annie Hughes   first commit
129
pd = [ $
2d758fdd   Annie Hughes   improved commenti...
130
131
     '(*!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
132
     '(*!dustem_params).grains(2).mdust_o_mh', $         ;aSil2001BE6pctG_0.4x mass fraction
2d758fdd   Annie Hughes   improved commenti...
133
134
135
     '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
136

9c053027   Annie Hughes   first commit
137

9c053027   Annie Hughes   first commit
138
139
140
;== 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
97d6b02a   Annie Hughes   changed llims to ...
141
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
142
143
144
145
146


;=== 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
6735604d   Annie Hughes   making FITS read ...
147
dustem_set_data,m_fit=m_fit,m_show=m_show,x_fit=ext,x_show=ext
9c053027   Annie Hughes   first commit
148

2d758fdd   Annie Hughes   improved commenti...
149
150
;=== compute the extinction curve (I then QU) using the model and specified
;=== true_vals of parameters
9c053027   Annie Hughes   first commit
151
152
153
154
155
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
156
157
158
159
160
161
162
163
164
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...
165
;=== set covariances to 0.
9c053027   Annie Hughes   first commit
166
167
168
169
170
171
172
173
174
175
176
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

e431104b   Annie Hughes   general updates f...
177
178
;======== example of how to move the file to the Data/EXAMPLE_OBSDATA/ subdirectory 
;filename_final=!dustem_wrap_soft_dir+'/Data/EXAMPLE_OBSDATA/my_example_EXT_G17MDL_D.xcat'
9c053027   Annie Hughes   first commit
179
180
181
182
;str='cp '+use_outfile+' '+filename_final
;message,'Do '+str+' to make change permanent',/continue

the_end:
e431104b   Annie Hughes   general updates f...
183
message,'Finished dustem_make_polarization_ext_example',/info
9c053027   Annie Hughes   first commit
184
185

END