Blame view

src/idl/dustem_plugin_dl07_isrf_model.pro 5.52 KB
746b3ee2   Jean-Philippe Bernard   fixed for REPLACE...
1
FUNCTION dustem_plugin_dl07_isrf_model, key=key, val=val, scope=scope, paramtag=paramtag, help=help, Umean=Umean,st=st
79bbc7a3   Jean-Philippe Bernard   First commit
2
3
4
5
6
7

;+
; NAME:
;    dustem_plugin_dl07_isrf_model
;
; PURPOSE:
1e69909c   Annie Hughes   remove redundant ...
8
9
10
;    Returns the dust spectrum after heating by a Draine-like ISRF
;            with Umin, Umax, gamma, alpha parameters described by the val keyword
;  
79bbc7a3   Jean-Philippe Bernard   First commit
11
; CATEGORY:
1e69909c   Annie Hughes   remove redundant ...
12
;    DUSTEM Wrapper, Plugin
79bbc7a3   Jean-Philippe Bernard   First commit
13
14
;
; CALLING SEQUENCE:
1e69909c   Annie Hughes   remove redundant ...
15
;    sed=dustem_plugin_dl07_isrf_model(key=,val=,Umean=,/paramtag][,/scope][,/help])
79bbc7a3   Jean-Philippe Bernard   First commit
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
;
; INPUTS:
;    None
;
; OPTIONAL INPUT PARAMETERS:
;    key = input parameter number.
;           1: gamma
;           2: alpha
;           3: Umin
;           4: Umax
;    val = input parameter values for the above.
;
; OUTPUTS:
;    None
;
; OPTIONAL OUTPUT PARAMETERS:
1e69909c   Annie Hughes   remove redundant ...
32
33
;    Umean = the average radiation field
;  
79bbc7a3   Jean-Philippe Bernard   First commit
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
; ACCEPTED KEY-WORDS:
;    help                  = if set, print this help
;
; COMMON BLOCKS:
;    None
;
; SIDE EFFECTS:
;    None
;
; RESTRICTIONS:
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
;    The path of the ISRF must be assigned to one of the DustEMWrap free pointers.
;    The user-defined ISRF needs to be on the same dustem ISRF grid.
;
; PROCEDURE:
;    
; EXAMPLES
;    res=dustem_dl07_isrf_model()
;
; MODIFICATION HISTORY:
;    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_dl07_isrf_model'
  goto,the_end
ENDIF

797bd3a9   Annie Hughes   added all grain t...
64
65
spec=0.

79bbc7a3   Jean-Philippe Bernard   First commit
66
IF keyword_set(scope) THEN BEGIN 
797bd3a9   Annie Hughes   added all grain t...
67
    out=0 & st=0
79bbc7a3   Jean-Philippe Bernard   First commit
68
69
70
71
    goto, the_end
ENDIF 

IF keyword_set(paramtag) THEN BEGIN
797bd3a9   Annie Hughes   added all grain t...
72
    out=0 & st=0
79bbc7a3   Jean-Philippe Bernard   First commit
73
74
75
    goto, the_end 
ENDIF

746b3ee2   Jean-Philippe Bernard   fixed for REPLACE...
76
77
78
;dustem_print_params
;stop

79bbc7a3   Jean-Philippe Bernard   First commit
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
;==== default parameter values
Umin=1.
Umax=1.e6
alpha=2.
gamma=0.     ;default is no contribution from U<>1.
IF keyword_set(key) THEN BEGIN
    ind=where(key EQ 1,count) ;gamma parameter as in DL07
    IF count NE 0 then begin
       gamma=val[ind[0]]
    ENDIF
    ind=where(key EQ 2,count) ;gamma parameter as in DL07
    IF count NE 0 then begin
       alpha=val[ind[0]]
    ENDIF
    ind=where(key EQ 3,count) ;gamma parameter as in DL07
    IF count NE 0 then begin
       Umin=val[ind[0]]
    ENDIF
    ind=where(key EQ 4,count) ;gamma parameter as in DL07
    IF count NE 0 then begin
       Umax=val[ind[0]]
    ENDIF
ENDIF

fcbc16e4   Jean-Philippe Bernard   changed to output...
103
;This is the average radiation field in DL07
2f9a477d   Jean-Philippe Bernard   improved and tested
104
105
Umean=(1.-gamma)*Umin+gamma*Umin*alog(Umax/Umin)/(1.-Umin/Umax)

79bbc7a3   Jean-Philippe Bernard   First commit
106
lambir=dustem_get_wavelengths()
1e69909c   Annie Hughes   remove redundant ...
107

79bbc7a3   Jean-Philippe Bernard   First commit
108
Nwavs=n_elements(lambir)
797bd3a9   Annie Hughes   added all grain t...
109
110
111
112
113
114
115
116
117
;spec=fltarr(Nwavs,3) ; if ever one day we enforce IQU outputs
;spec2=fltarr(Nwavs,3)
spec=fltarr(Nwavs) 
spec2=fltarr(Nwavs)

Ngrains=(*!dustem_params).ngrains
spec_grains=fltarr(Nwavs,ngrains) 
spec2_grains=fltarr(Nwavs,ngrains)

797bd3a9   Annie Hughes   added all grain t...
118
;==== save everything to put back later
be96d5ee   Annie Hughes   saved dustem_para...
119
120
121
122
123
saved_params=0 & saved_pd=0 & saved_pinfo=0 & saved_fpd=0
IF ptr_valid(!dustem_params) THEN BEGIN
   dparams=*!dustem_params
   saved_params=1
END
797bd3a9   Annie Hughes   added all grain t...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
IF ptr_valid((*!dustem_fit).param_descs) THEN BEGIN
  pd=*(*!dustem_fit).param_descs
  iv=*(*!dustem_fit).param_init_values
  cv=*(*!dustem_fit).current_param_values
  saved_pd=1
ENDIF
IF ptr_valid(!dustem_parinfo) THEN BEGIN
   parinfo=*(!dustem_parinfo)
  saved_pinfo=1
ENDIF
IF ptr_valid((*!dustem_fit).fixed_param_descs) THEN BEGIN
  fpd=*(*!dustem_fit).fixed_param_descs
  fiv=*(*!dustem_fit).fixed_param_init_values
  saved_fpd=1
ENDIF
79bbc7a3   Jean-Philippe Bernard   First commit
139
140
141

;==== Run dustem with G0(a.k.a. U)=1.
param_desc=['(*!dustem_params).G0']
79bbc7a3   Jean-Philippe Bernard   First commit
142
param_values=[Umin]
fcbc16e4   Jean-Philippe Bernard   changed to output...
143
dustem_init_params,!dustem_model,param_desc,param_values
746b3ee2   Jean-Philippe Bernard   fixed for REPLACE...
144
145

;stop
79bbc7a3   Jean-Philippe Bernard   First commit
146
147
148
st=dustem_run(param_values)
spec1=st.sed.em_tot
spec=(1.-gamma)*spec1
797bd3a9   Annie Hughes   added all grain t...
149
150
151
152
for k=0,ngrains-1 do begin
   this_spec=st.sed.(k+1)    ; position 0 is the wavelengths
   spec_grains[*,k]=(1.-gamma)*this_spec
endfor
79bbc7a3   Jean-Philippe Bernard   First commit
153
154
155

;==== add contribution of dust seeing a power law of U
spec2[*]=0.
2f9a477d   Jean-Philippe Bernard   improved and tested
156
;NUs=3L
fcbc16e4   Jean-Philippe Bernard   changed to output...
157
158
159
NUs=10L   ;This seems sufficient
;NUs=50L
;U values over which integration will be performed
79bbc7a3   Jean-Philippe Bernard   First commit
160
161
Us=range_gen(NUs,[Umin,Umax],/log)
specs=fltarr(NUs,Nwavs)
797bd3a9   Annie Hughes   added all grain t...
162
specs_grains=fltarr(NUs,Nwavs,Ngrains)
79bbc7a3   Jean-Philippe Bernard   First commit
163
;stop
797bd3a9   Annie Hughes   added all grain t...
164

79bbc7a3   Jean-Philippe Bernard   First commit
165
166
167
168
169
ffacts=fltarr(NUs)
IF gamma NE 0. THEN BEGIN
    fact=gamma*(alpha-1.)/(Umin^(1.-alpha)-Umax^(1.-alpha))
    FOR i=0L,NUs-1 DO BEGIN
        param_values[0]=Us[i];^(-1.*alpha)
746b3ee2   Jean-Philippe Bernard   fixed for REPLACE...
170
        ;stop
79bbc7a3   Jean-Philippe Bernard   First commit
171
172
173
        st=dustem_run(param_values)
        ffacts[i]=Us[i]^(-1.*alpha)*fact
        specs[i,*]=ffacts[i]*st.sed.em_tot
797bd3a9   Annie Hughes   added all grain t...
174
        for k=0,ngrains-1 do specs_grains[i,*,k]=ffacts[i]*st.sed.(k+1)
79bbc7a3   Jean-Philippe Bernard   First commit
175
176
    ENDFOR
    ;integrate over U
746b3ee2   Jean-Philippe Bernard   fixed for REPLACE...
177
    ;stop
79bbc7a3   Jean-Philippe Bernard   First commit
178
    FOR j=0L,Nwavs-1 DO BEGIN
be96d5ee   Annie Hughes   saved dustem_para...
179
        integ=integral(Us,reform(specs[*,j]),Umin,Umax,/no_check)
79bbc7a3   Jean-Philippe Bernard   First commit
180
        spec[j]=spec[j]+integ[0]
797bd3a9   Annie Hughes   added all grain t...
181
        for k=0,ngrains-1 do begin
be96d5ee   Annie Hughes   saved dustem_para...
182
           integ_grains=integral(Us,reform(specs_grains[*,j,k]),Umin,Umax,/no_check)
797bd3a9   Annie Hughes   added all grain t...
183
184
           spec_grains[j,k]=spec_grains[j,k]+integ_grains[0]
        endfor
79bbc7a3   Jean-Philippe Bernard   First commit
185
    ENDFOR
79bbc7a3   Jean-Philippe Bernard   First commit
186
187
ENDIF

797bd3a9   Annie Hughes   added all grain t...
188
;This is to update keyword st with the final spectra. 
746b3ee2   Jean-Philippe Bernard   fixed for REPLACE...
189
190
191
;Not necessary here, but to be used in plugins with scope 'REPLACE_FORTRAN' which actually do not call the Fortran at all.
;Ngrains=3
;st=dustem_make_empty_fortran_st(Ngrains)
79bbc7a3   Jean-Philippe Bernard   First commit
192
st.sed.em_tot=spec
797bd3a9   Annie Hughes   added all grain t...
193
194
195
196
197
198
for k=0,ngrains-1 do st.sed.(k+1)=spec_grains[*,k]

;restore params to their original values
if saved_pd eq 1 then begin
  (*!dustem_fit).param_descs=ptr_new(pd)
  (*!dustem_fit).param_init_values=ptr_new(iv)
be96d5ee   Annie Hughes   saved dustem_para...
199
  (*!dustem_fit).current_param_values=ptr_new(cv)
797bd3a9   Annie Hughes   added all grain t...
200
201
202
203
204
205
206
207
end
if saved_fpd eq 1 then begin
  (*!dustem_fit).fixed_param_descs=ptr_new(fpd)
  (*!dustem_fit).fixed_param_init_values=ptr_new(fiv)
end
if saved_pinfo eq 1 then begin
   !dustem_parinfo=ptr_new(parinfo)
end
be96d5ee   Annie Hughes   saved dustem_para...
208
209
210
if saved_params eq 1 then begin
   !dustem_params=ptr_new(dparams)
end
79bbc7a3   Jean-Philippe Bernard   First commit
211

746b3ee2   Jean-Philippe Bernard   fixed for REPLACE...
212

79bbc7a3   Jean-Philippe Bernard   First commit
213
214
the_end:
scope='REPLACE_FORTRAN'
79bbc7a3   Jean-Philippe Bernard   First commit
215
216
217
;parameter tags. 
paramtag=['gamma','alpha','Umin','Umax']

fcbc16e4   Jean-Philippe Bernard   changed to output...
218
RETURN,spec
79bbc7a3   Jean-Philippe Bernard   First commit
219
END