Blame view

src/idl/dustem_compute_polsed.pro 6.83 KB
283845da   Ilyes Choubani   Small corrections...
1
FUNCTION dustem_compute_polsed,p_dim,$
474c4b97   Jean-Philippe Bernard   modified to cope ...
2
3
4
5
                               st=st,$
                               P_spec=P_spec,$
                               SP_spec=SP_spec,$
                               dustem_polfrac=dustem_polfrac,$
2926480f   Ilyes Choubani   Modified header c...
6
7
                               dustem_sed=dustem_sed,$
                               help=help
f133c4ae   Jean-Philippe Bernard   improved help a bit
8

427f1205   Jean-Michel Glorian   version 4.2 merged
9
;+
427f1205   Jean-Michel Glorian   version 4.2 merged
10
11
; NAME:
;    dustem_compute_polsed
4c27620f   Annie Hughes   cosmetic hanges t...
12
;
427f1205   Jean-Michel Glorian   version 4.2 merged
13
; PURPOSE:
07a51917   Ilyes Choubani   updating help sec...
14
;    Computes a Polarized SED for a given Dustem spectrum
4c27620f   Annie Hughes   cosmetic hanges t...
15
;
427f1205   Jean-Michel Glorian   version 4.2 merged
16
; CATEGORY:
4c27620f   Annie Hughes   cosmetic hanges t...
17
18
;    DustEMWrap, Mid-Level, Distributed
;
427f1205   Jean-Michel Glorian   version 4.2 merged
19
; CALLING SEQUENCE:
2926480f   Ilyes Choubani   Modified header c...
20
;    sed=dustem_compute_polsed(p_dim[,st=][,P_spec=][,SP_spec=][,dustem_polfrac=][,dustem_sed=][,/help])
4c27620f   Annie Hughes   cosmetic hanges t...
21
;
427f1205   Jean-Michel Glorian   version 4.2 merged
22
23
; INPUTS:
;    p_dim      = parameter values
4c27620f   Annie Hughes   cosmetic hanges t...
24
;
427f1205   Jean-Michel Glorian   version 4.2 merged
25
; OPTIONAL INPUT PARAMETERS:
5f04fa07   Ilyes Choubani   general update
26
;    st        = Dustem structure
07a51917   Ilyes Choubani   updating help sec...
27
;    dustem_sed = Computed emission for spectrum points in !dustem_data
4c27620f   Annie Hughes   cosmetic hanges t...
28
;
427f1205   Jean-Michel Glorian   version 4.2 merged
29
; OUTPUTS:
07a51917   Ilyes Choubani   updating help sec...
30
31
32
33
34
;    sed         = computed SED for filters in !dustem_data
;    dustem_polsed = Computed polarized emission for spectrum points in !dustem_data
;    P_spec        = Dustem polarized emission output 
;    SP_spec       = Dustem polarized emission fraction
;    dustem_polfrac = Computed polarization emission fraction for spectrum points in !dustem_data
4c27620f   Annie Hughes   cosmetic hanges t...
35
;
427f1205   Jean-Michel Glorian   version 4.2 merged
36
; OPTIONAL OUTPUT PARAMETERS:
474c4b97   Jean-Philippe Bernard   modified to cope ...
37
38
;    st        = Dustem structure
;    dustem_sed = Computed emission for spectrum points in !dustem_data
4c27620f   Annie Hughes   cosmetic hanges t...
39
;
427f1205   Jean-Michel Glorian   version 4.2 merged
40
41
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
4c27620f   Annie Hughes   cosmetic hanges t...
42
;
427f1205   Jean-Michel Glorian   version 4.2 merged
43
44
; COMMON BLOCKS:
;    None
4c27620f   Annie Hughes   cosmetic hanges t...
45
;
427f1205   Jean-Michel Glorian   version 4.2 merged
46
47
; SIDE EFFECTS:
;    None
4c27620f   Annie Hughes   cosmetic hanges t...
48
;
427f1205   Jean-Michel Glorian   version 4.2 merged
49
; RESTRICTIONS:
4c27620f   Annie Hughes   cosmetic hanges t...
50
51
52
;    The DustEM fortran code must be installed
;    The DustEMWrap idl code must be installed
;
427f1205   Jean-Michel Glorian   version 4.2 merged
53
54
; PROCEDURE:
;    None
4c27620f   Annie Hughes   cosmetic hanges t...
55
;
427f1205   Jean-Michel Glorian   version 4.2 merged
56
57
58
59
; EXAMPLES
;    
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard
4c27620f   Annie Hughes   cosmetic hanges t...
60
61
62
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-
427f1205   Jean-Michel Glorian   version 4.2 merged
63

5f04fa07   Ilyes Choubani   general update
64

427f1205   Jean-Michel Glorian   version 4.2 merged
65
66
67
68
69
70
IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_compute_polsed'
  dustem_polsed=0.
  goto,the_end
ENDIF

5f04fa07   Ilyes Choubani   general update
71
IF not keyword_set(st) THEN BEGIN
ae2e6114   Ilyes Choubani   small corrections...
72
  dustem_activate_plugins,p_dim/(*(*!dustem_fit).param_init_values),st=st
07372e26   Ilyes Choubani   Corrected huge pl...
73
  ;st=dustem_run(p_dim)
427f1205   Jean-Michel Glorian   version 4.2 merged
74
ENDIF
452c334e   Ilyes Choubani   Implementation Of...
75

2a8e29d5   Ilyes Choubani   small corrections...
76
If keyword_set(result) THEN result=sti
5f04fa07   Ilyes Choubani   general update
77
fact = 1.e4*(*!dustem_HCD)/(4.*!pi)/(3.e8/1.e-6/(st.polsed).wav)*1.e20/1.e7
759a527d   Ilyes Choubani   general update
78

3c479f24   Ilyes Choubani   Allowing to fix p...
79
80
P_spec = st.polsed.em_tot*fact ;This is Polarized intensity P
stI = st.sed.em_tot*fact    ;This is Total intensity I
ba82c5cf   Ilyes Choubani   improved with mod...
81
out=0.
5f04fa07   Ilyes Choubani   general update
82
Nwaves=(size(P_spec))[1]
83b3ddee   Jean-Philippe Bernard   modified with Ily...
83

5f04fa07   Ilyes Choubani   general update
84
frac=P_spec/stI
ba82c5cf   Ilyes Choubani   improved with mod...
85
86
87
tes=where(finite(frac) eq 0)
frac(tes)=0.

afde94a3   Ilyes Choubani   general update
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
;This block was added to generate the polarization fraction spectrum with the plugins contributions. 
;smallp (polfrac) is naturally not an additive quantity.



;NB: if plugins that replace the total emission given by the fortran executable exist, 
;the need to add a block with a 'REPLPACE_SED' scope as for the 'REPLACE_POLSED' below, may arise.

scopes=tag_names((*!dustem_plugin)) 
IF scopes[0] NE 'NONE' THEN BEGIN
;IF ptr_valid(!dustem_plugin) THEN BEGIN
  for i=0L,n_tags(*!dustem_plugin)-1 do begin
    if total(strsplit((*(*!dustem_plugin).(i).scope),'+',/extract) eq 'ADD_SED') then stI+=(*(*!dustem_plugin).(i).spec)[*,0]
  endfor
ENDIF

3ff9cac3   Ilyes Choubani   general update
104

759a527d   Ilyes Choubani   general update
105
IF scopes[0] NE 'NONE' THEN BEGIN
ba82c5cf   Ilyes Choubani   improved with mod...
106

3c479f24   Ilyes Choubani   Allowing to fix p...
107
    FOR i=0L,n_tags(*!dustem_plugin)-1 DO BEGIN   
ba82c5cf   Ilyes Choubani   improved with mod...
108
        
3c479f24   Ilyes Choubani   Allowing to fix p...
109
        IF total(strsplit((*(*!dustem_plugin).(i).scope),'+',/extract) EQ 'REPLACE_POLSED') THEN BEGIN
5f04fa07   Ilyes Choubani   general update
110
            
3c479f24   Ilyes Choubani   Allowing to fix p...
111
112
            Q_spec=(*(*!dustem_plugin).(i).spec)[*,1]
            U_spec=(*(*!dustem_plugin).(i).spec)[*,2]
afde94a3   Ilyes Choubani   general update
113
            ;make sure sti hasn't been replaced. But this is not happening in the near future
5f04fa07   Ilyes Choubani   general update
114
115
            
        ENDIF 
68598bce   Ilyes Choubani   reducing number o...
116
        
5f04fa07   Ilyes Choubani   general update
117
    ENDFOR    
ba82c5cf   Ilyes Choubani   improved with mod...
118
    
887b421b   Ilyes Choubani   correcting some c...
119
120
ENDIF
    
5f04fa07   Ilyes Choubani   general update
121
    IF ~isa(Q_spec) && ~isa(U_spec) THEN BEGIN
07372e26   Ilyes Choubani   Corrected huge pl...
122
        polar_ippsi2iqu,stI,Q_spec,U_spec,frac,replicate(!dustem_psi,Nwaves) ;the user needs to set this pointer somewhere
5f04fa07   Ilyes Choubani   general update
123
124
        SP_spec = frac 
    ENDIF
887b421b   Ilyes Choubani   correcting some c...
125
126
127

IF scopes[0] NE 'NONE' THEN BEGIN    
       
3c479f24   Ilyes Choubani   Allowing to fix p...
128
    FOR i=0L,n_tags(*!dustem_plugin)-1 DO BEGIN
ba82c5cf   Ilyes Choubani   improved with mod...
129
        
3c479f24   Ilyes Choubani   Allowing to fix p...
130
        IF total(strsplit((*(*!dustem_plugin).(i).scope),'+',/extract) EQ 'ADD_POLSED') THEN BEGIN
5f04fa07   Ilyes Choubani   general update
131
        
3c479f24   Ilyes Choubani   Allowing to fix p...
132
133
            Q_spec+=(*(*!dustem_plugin).(i).spec)[*,1]
            U_spec+=(*(*!dustem_plugin).(i).spec)[*,2]
5f04fa07   Ilyes Choubani   general update
134
135
136
137
            
        ENDIF
      
    ENDFOR
ba82c5cf   Ilyes Choubani   improved with mod...
138
    
759a527d   Ilyes Choubani   general update
139
ENDIF
452c334e   Ilyes Choubani   Implementation Of...
140

887b421b   Ilyes Choubani   correcting some c...
141
P_spec=sqrt(Q_spec^2+U_spec^2)
afde94a3   Ilyes Choubani   general update
142
143
SP_spec=P_spec/Sti

887b421b   Ilyes Choubani   correcting some c...
144

0068116a   Ilyes Choubani   General update + ...
145
dustem_polsed = (*(*!dustem_data).qsed).values * 0.
86e5c5c1   Ilyes Choubani   General update + ...
146

5f04fa07   Ilyes Choubani   general update
147
148
    
if not isarray(P_spec) THEN stop ;I don't understand this test. The only thing it can indicate is a problem with the dust parameters or the fortran executable. But in my opinion these tests would be  
452c334e   Ilyes Choubani   Implementation Of...
149

83b3ddee   Jean-Philippe Bernard   modified with Ily...
150

427f1205   Jean-Michel Glorian   version 4.2 merged
151
152
153
154
155
156
IF !dustem_do_cc NE 0 AND !dustem_never_do_cc EQ 0 THEN BEGIN
  message,'DOING color correction calculations',/info
ENDIF ELSE BEGIN
  message,'SKIPPING color correction calculations',/info
ENDELSE

0068116a   Ilyes Choubani   General update + ...
157
ind_polsed=where((*(*!dustem_data).qsed).filt_names NE 'SPECTRUM',count_polsed)  
452c334e   Ilyes Choubani   Implementation Of...
158
  
266ae799   Ilyes Choubani   General update
159
IF count_polsed NE 0 THEN BEGIN
0068116a   Ilyes Choubani   General update + ...
160
  filter_names=((*(*!dustem_data).qsed).filt_names)(ind_polsed)
5f04fa07   Ilyes Choubani   general update
161
  spolsed=dustem_cc(st.polsed.wav,P_spec,filter_names,cc=cc)
83b3ddee   Jean-Philippe Bernard   modified with Ily...
162
  dustem_polsed[ind_polsed]=spolsed
427f1205   Jean-Michel Glorian   version 4.2 merged
163
164
ENDIF

266ae799   Ilyes Choubani   General update
165

266ae799   Ilyes Choubani   General update
166
;For spectrum data points, interpolate in log-log.
427f1205   Jean-Michel Glorian   version 4.2 merged
167
168
;Linear interpolation leads to wrong values, in particular where few
;wavelengths points exist in the model (long wavelengths).
3c479f24   Ilyes Choubani   Allowing to fix p...
169
;I believe this to be automatic because the provided dustem spectra are already sampled on a log-log grid.
266ae799   Ilyes Choubani   General update
170

0068116a   Ilyes Choubani   General update + ...
171
172
ind_spec=where((*(*!dustem_data).qsed).filt_names EQ 'SPECTRUM',count_spec) 
IF count_spec NE 0 THEN dustem_polsed(ind_spec)=interpol(P_spec,st.polsed.wav,(((*(*!dustem_data).qsed).wav)(ind_spec)))
86e5c5c1   Ilyes Choubani   General update + ...
173

2926480f   Ilyes Choubani   Modified header c...
174

427f1205   Jean-Michel Glorian   version 4.2 merged
175

fcb6eade   Ilyes Choubani   general update - ...
176
177
;GENERATING THE INTERPOLATES FOR POLFRAC (dustem_polfrac)
if !run_lin then begin
7d3f28dc   Jean-Philippe Bernard   not sure what I d...
178
    ;stop
474c4b97   Jean-Philippe Bernard   modified to cope ...
179
    if not keyword_set(dustem_sed) then dustem_sed = dustem_compute_sed(p_dim,st=st,SED_spec=SED_spec)
67bd858a   Ilyes Choubani   Replication of th...
180
          		
fcb6eade   Ilyes Choubani   general update - ...
181
182
183
184
185
186
187
188
189
190
191
    If n_elements(dustem_sed) ne n_elements(dustem_polsed) then begin                            
        if n_elements(dustem_sed) gt n_elements(dustem_polsed) then begin 
      
            dustem_polsed_x = dustem_polsed
            dustem_sed_x = dustem_polsed ;meaning dustem_sed needs to be modified
      
            nwaves = n_elements(dustem_polsed)
      
      
              for i=0L,nwaves-1 do begin
      
0068116a   Ilyes Choubani   General update + ...
192
                  j=where((*(*!dustem_data).sed).wav EQ (*(*!dustem_data).polfrac).wav(i),testwav)
fcb6eade   Ilyes Choubani   general update - ...
193
194
195
196
197
198
199
200
201
202
203
204
                  if testwav ne 0 then dustem_sed_x(i) = dustem_sed(j(0))                                    
      
              endfor
      
        endif ELSE begin
        
            dustem_polsed_x = dustem_sed
            dustem_sed_x = dustem_sed ;meaning dustem_polsed needs to be modified
        
            nwaves = n_elements(dustem_sed)
        
            for i=0L,nwaves-1 do begin
0068116a   Ilyes Choubani   General update + ...
205
                j=where((*(*!dustem_data).sed).wav EQ (*(*!dustem_data).polfrac).wav(i),testwav)
fcb6eade   Ilyes Choubani   general update - ...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
                if testwav ne 0 then dustem_polsed_x(i) = dustem_polsed(j(0))                                    
            endfor
          
        
        ENDELSE
    
    endif ELSE BEGIN
        
        dustem_polsed_x = dustem_polsed 
        dustem_sed_x = dustem_sed
    
    ENDELSE
    
    dustem_polfrac = dustem_polsed_x/dustem_sed_x 
	       
ENDIF

452c334e   Ilyes Choubani   Implementation Of...
223

427f1205   Jean-Michel Glorian   version 4.2 merged
224
225
226
227
228
229
230
;clean pointers
heap_gc

the_end:

RETURN,dustem_polsed

4c27620f   Annie Hughes   cosmetic hanges t...
231
END