Commit d0f68bb612d90086541e4e4b3b56d3632a8b9016

Authored by Jean-Philippe Bernard
1 parent 7fb01a01
Exists in master

replaced system variable fit_rchi2_weight by a pointer

src/idl/dustem_fit.pro
... ... @@ -71,17 +71,19 @@ defsysv, '!dustem_data', { $ ;Data to fit
71 71  
72 72 ; Define global !fit_rchi2_weight with the same structure and field order like !dustem_data
73 73 tagnames = tag_names(!dustem_data)
74   -instr="defsysv, '!fit_rchi2_weight', {"
  74 +;instr="defsysv, '!fit_rchi2_weight', {"
  75 +instr="fit_rchi2_weight_string={"
75 76 for i = 0, n_elements(tagnames)-1 do instr+=tagnames(i)+': rchi2_weight.'+tagnames(i)+', '
76   -instr+='empty: 0. }
  77 +instr+='empty: 0. }'
77 78 toto=execute(instr)
  79 +defsysv, '!fit_rchi2_weight',ptr_new(fit_rchi2_weight_string)
78 80  
79 81 ;=== Set weight for reduced chi2 ponderation between emission, extinction, polarized extinction and emission ===
80 82 ; Calculate total according to fileds in !dustem_data structure
81 83 total = 0
82   -for i = 0, n_tags(!dustem_data)-1 do total = total + !fit_rchi2_weight.(i)
  84 +for i = 0, n_tags(!dustem_data)-1 do total = total + (*!fit_rchi2_weight).(i)
83 85 ; values are relative to total
84   -for i = 0, n_tags(!dustem_data)-1 do !fit_rchi2_weight.(i) /= total
  86 +for i = 0, n_tags(!dustem_data)-1 do (*!fit_rchi2_weight).(i) /= total
85 87  
86 88 dustem_init,mode=use_mode
87 89  
... ...
src/idl/dustem_init.pro
... ... @@ -211,13 +211,15 @@ if !run_pol then begin
211 211  
212 212 endif else tagnames=tag_names(*!dustem_data)
213 213  
214   -instr="defsysv, '!fit_rchi2_weight', {"
  214 +;instr="defsysv, '!fit_rchi2_weight', {"
  215 +instr="fit_rchi2_weight_str={"
215 216 FOR i = 0, n_elements(tagnames)-1 DO BEGIN
216 217 instr+=tagnames(i)+': rchi2_weight.'+tagnames(i)
217 218 IF i NE n_elements(tagnames)-1 THEN instr+=','
218 219 ENDFOR
219 220 instr+='}'
220 221 toto=execute(instr)
  222 +defsysv, '!fit_rchi2_weight',ptr_new(fit_rchi2_weight_str)
221 223  
222 224 ;#########system variables necessary for cgwindow plotting##########
223 225 defsysv, '!dustemcgwin_id', { $ ;IDs of windows to plot
... ...
src/idl/dustem_mpfit_data.pro
... ... @@ -103,8 +103,8 @@ FOR j=0,n_elements(fields)-1 DO BEGIN
103 103 ; sigma_ext *= sqrt(52./366./0.2) = 0.84
104 104 ; By increasing sigma by a factor w, we diminish the weight of the corresponding point by a factor w^2
105 105 if count_data_tag gt 1 and j eq 2 then begin ; sigma ponderation = sqrt(ni/wi)
106   - if !fit_rchi2_weight.(i) gt 0 then begin
107   - weight = sqrt(1./!fit_rchi2_weight.(i) )
  106 + if (*!fit_rchi2_weight).(i) gt 0 then begin
  107 + weight = sqrt(1./(*!fit_rchi2_weight).(i) )
108 108 endif else begin
109 109 weight = 1.d99
110 110 endelse
... ...
src/idl/dustem_mpfit_run.pro
... ... @@ -102,7 +102,7 @@ FOR i_tag=0,count_data_tag-1 DO BEGIN
102 102 chi2_sed = total(((*(*!dustem_data).sed).values-dustem_sed)^2/(*(*!dustem_data).sed).sigma^2)
103 103 n_sed = n_elements((*(*!dustem_data).sed).values)
104 104 rchi2_sed = chi2_sed / n_sed
105   - wrchi2_sed = rchi2_sed * !fit_rchi2_weight.sed
  105 + wrchi2_sed = rchi2_sed * (*!fit_rchi2_weight).sed
106 106 message,"chi2 SED = "+strtrim(chi2_sed,2)+" rchi2 SED = "+strtrim(rchi2_sed,2),/continue;," weighted rchi2 SED=",wrchi2_sed
107 107 ;print,'wl ',(*(*!dustem_data).sed).wav
108 108 ;print,"Delta SED per wl: ",(*(*!dustem_data).sed).values-dustem_sed
... ... @@ -129,7 +129,7 @@ FOR i_tag=0,count_data_tag-1 DO BEGIN
129 129 chi2_ext = total(((*(*!dustem_data).ext).values-dustem_ext)^2/(*(*!dustem_data).ext).sigma^2)
130 130 n_ext = n_elements((*(*!dustem_data).ext).values)
131 131 rchi2_ext = chi2_ext / n_ext
132   - wrchi2_ext = rchi2_ext * !fit_rchi2_weight.ext
  132 + wrchi2_ext = rchi2_ext * (*!fit_rchi2_weight).ext
133 133 print,"chi2 EXT = ",chi2_ext," rchi2 EXT = ",rchi2_ext;," weighted rchi2 EXT=",wrchi2_ext
134 134 ;print,"chi2 per wl: ",((*(*!dustem_data).ext).values-dustem_ext)^2/(*(*!dustem_data).ext).sigma^2
135 135  
... ... @@ -169,7 +169,7 @@ FOR i_tag=0,count_data_tag-1 DO BEGIN
169 169 chi2_qsed = total(((*(*!dustem_data).qsed).values-dustem_qsed)^2/(*(*!dustem_data).qsed).sigma^2)
170 170 n_qsed = n_elements((*(*!dustem_data).qsed).values)
171 171 rchi2_qsed = chi2_qsed / n_qsed
172   - wrchi2_qsed = rchi2_qsed * !fit_rchi2_weight.qsed
  172 + wrchi2_qsed = rchi2_qsed * (*!fit_rchi2_weight).qsed
173 173 dustem_out = [ dustem_out, dustem_qsed ] ; classic command
174 174 message,"chi2 QSED = "+strtrim(chi2_qsed,2)+" rchi2 QSED = "+strtrim(rchi2_qsed,2),/continue;," weighted rchi2 POLSED=",wrchi2_polsed
175 175 print,"chi2 per wl: ",((*(*!dustem_data).qsed).values-dustem_qsed)^2/(*(*!dustem_data).qsed).sigma^2
... ... @@ -181,7 +181,7 @@ FOR i_tag=0,count_data_tag-1 DO BEGIN
181 181 chi2_used = total(((*(*!dustem_data).used).values-dustem_used)^2/(*(*!dustem_data).used).sigma^2)
182 182 n_used = n_elements((*(*!dustem_data).used).values)
183 183 rchi2_used = chi2_used / n_used
184   - wrchi2_used = rchi2_used * !fit_rchi2_weight.used
  184 + wrchi2_used = rchi2_used * (*!fit_rchi2_weight).used
185 185 dustem_out = [ dustem_out, dustem_used] ; classic command
186 186 message,"chi2 USED = "+strtrim(chi2_used,2)+" rchi2 USED = "+strtrim(rchi2_used,2),/continue;," weighted rchi2 POLSED=",wrchi2_polsed
187 187 print,"chi2 per wl: ",((*(*!dustem_data).used).values-dustem_used)^2/(*(*!dustem_data).used).sigma^2
... ... @@ -206,7 +206,7 @@ FOR i_tag=0,count_data_tag-1 DO BEGIN
206 206 chi2_qext =total(((*(*!dustem_data).qext).values-dustem_qext)^2/(*(*!dustem_data).qext).sigma^2)
207 207 n_qext = n_elements((*(*!dustem_data).qext).values)
208 208 rchi2_qext = chi2_qext / n_qext
209   - wrchi2_qext = rchi2_qext * !fit_rchi2_weight.qext
  209 + wrchi2_qext = rchi2_qext * (*!fit_rchi2_weight).qext
210 210 dustem_out = [ dustem_out, dustem_qext] ; classic command
211 211 message,"chi2 QEXT = "+strtrim(chi2_qext,2)+" rchi2 QEXT = "+strtrim(rchi2_qext,2),/continue;," weighted rchi2 POLSED=",wrchi2_polsed
212 212 print,"chi2 per wl: ",((*(*!dustem_data).qext).values-dustem_qext)^2/(*(*!dustem_data).qext).sigma^2
... ... @@ -218,7 +218,7 @@ FOR i_tag=0,count_data_tag-1 DO BEGIN
218 218 chi2_uext =total(((*(*!dustem_data).uext).values-dustem_uext)^2/(*(*!dustem_data).uext).sigma^2)
219 219 n_uext = n_elements((*(*!dustem_data).uext).values)
220 220 rchi2_uext = chi2_uext / n_uext
221   - wrchi2_uext = rchi2_uext * !fit_rchi2_weight.uext
  221 + wrchi2_uext = rchi2_uext * (*!fit_rchi2_weight).uext
222 222 dustem_out = [ dustem_out, dustem_uext] ; classic command
223 223 message,"chi2 UEXT = "+strtrim(chi2_uext,2)+" rchi2 UEXT = "+strtrim(rchi2_uext,2),/continue;," weighted rchi2 POLSED=",wrchi2_polsed
224 224 print,"chi2 per wl: ",((*(*!dustem_data).uext).values-dustem_uext)^2/(*(*!dustem_data).uext).sigma^2
... ... @@ -237,34 +237,34 @@ DOF = n_elements(p_min)
237 237 total_chi2 = 0
238 238 total_rchi2 = 0
239 239 total_n = 0
240   -if !fit_rchi2_weight.ext ne 0 then begin
  240 +if (*!fit_rchi2_weight).ext ne 0 then begin
241 241 total_n += n_ext
242 242 total_chi2 += chi2_ext
243 243 total_rchi2 += rchi2_ext
244 244 endif
245   -if !fit_rchi2_weight.sed ne 0 then begin
  245 +if (*!fit_rchi2_weight).sed ne 0 then begin
246 246 total_n += n_sed
247 247 total_chi2 += chi2_sed
248 248 total_rchi2 += rchi2_sed
249 249 endif
250 250 if !run_pol then begin
251 251  
252   - if !fit_rchi2_weight.qsed ne 0 then begin
  252 + if (*!fit_rchi2_weight).qsed ne 0 then begin
253 253 total_n += n_qsed
254 254 total_chi2 += chi2_qsed
255 255 total_rchi2 += rchi2_qsed
256 256 endif
257   - if !fit_rchi2_weight.used ne 0 then begin
  257 + if (*!fit_rchi2_weight).used ne 0 then begin
258 258 total_n += n_used
259 259 total_chi2 += chi2_used
260 260 total_rchi2 += rchi2_used
261 261 endif
262   - if !fit_rchi2_weight.qext ne 0 then begin
  262 + if (*!fit_rchi2_weight).qext ne 0 then begin
263 263 total_n += n_qext
264 264 total_chi2 += chi2_qext
265 265 total_rchi2 += rchi2_qext
266 266 endif
267   - if !fit_rchi2_weight.uext ne 0 then begin
  267 + if (*!fit_rchi2_weight).uext ne 0 then begin
268 268 total_n += n_uext
269 269 total_chi2 += chi2_uext
270 270 total_rchi2 += rchi2_uext
... ... @@ -273,16 +273,16 @@ if !run_pol then begin
273 273 endif
274 274  
275 275  
276   -total_wchi2 = chi2_ext * !fit_rchi2_weight.ext $
277   - + chi2_sed * !fit_rchi2_weight.sed
  276 +total_wchi2 = chi2_ext * (*!fit_rchi2_weight).ext $
  277 + + chi2_sed * (*!fit_rchi2_weight).sed
278 278 if !run_pol then begin
279 279 total_wchi2 += $;chi2_polext * !fit_rchi2_weight.polext $
280 280 ; + chi2_polsed * !fit_rchi2_weight.polsed $
281 281 ; + chi2_polfrac * !fit_rchi2_weight.polfrac $
282   - + chi2_qsed * !fit_rchi2_weight.qsed $
283   - + chi2_used * !fit_rchi2_weight.used $
284   - + chi2_qext * !fit_rchi2_weight.qext $
285   - + chi2_uext * !fit_rchi2_weight.uext
  282 + + chi2_qsed * (*!fit_rchi2_weight).qsed $
  283 + + chi2_used * (*!fit_rchi2_weight).used $
  284 + + chi2_qext * (*!fit_rchi2_weight).qext $
  285 + + chi2_uext * (*!fit_rchi2_weight).uext
286 286 endif
287 287  
288 288 ;Using this expression for now for the weighting.
... ... @@ -296,8 +296,8 @@ print,"Nb of data points = ", total_n
296 296 print,"DOF = ", DOF
297 297 print,"Reduced chi2 EXT/SED/POLEXT/POLSED/POLFRAC",rchi2_ext,rchi2_sed;,rchi2_polext;,rchi2_polsed,rchi2_polfrac
298 298 print,"Weighted reduced chi2 EXT/SED/POLEXT/POLSED/POLFRAC",wrchi2_ext,wrchi2_sed;,wrchi2_polext;,wrchi2_polsed,wrchi2_polfrac
299   -if !run_pol then print,"Weights",!fit_rchi2_weight.ext,!fit_rchi2_weight.sed $;,!fit_rchi2_weight.polext $;,!fit_rchi2_weight.polsed,!fit_rchi2_weight.polfrac $
300   -else print,"Weights",!fit_rchi2_weight.ext,!fit_rchi2_weight.sed
  299 +if !run_pol then print,"Weights",(*!fit_rchi2_weight).ext,(*!fit_rchi2_weight).sed $;,!fit_rchi2_weight.polext $;,!fit_rchi2_weight.polsed,!fit_rchi2_weight.polfrac $
  300 +else print,"Weights",(*!fit_rchi2_weight).ext,(*!fit_rchi2_weight).sed
301 301 print,"Mean weighted reduced chi2 = ", total_wchi2/(total_n-DOF)
302 302 print,"Unweighted reduced Total chi2 = ", total_chi2/(total_n-DOF)
303 303 print,"Unweighted mean reduced chi2 = ", total_rchi2/4*total_n/(total_n-DOF);total_rchi2/4*total_n/(total_n-DOF) original ; I do not understand this line. Maybe redo some computation.
... ...
src/idl/dustem_plot_fit_extsed.pro
... ... @@ -128,7 +128,7 @@ dustem_ext = interpol(st.ext.ext_tot,st.ext.wav,(*!dustem_data.ext).wav)
128 128 chi2_ext = total(((*!dustem_data.ext).values-dustem_ext)^2/(*!dustem_data.ext).sigma^2)
129 129 n_ext = n_elements((*!dustem_data.ext).values)
130 130 rchi2_ext = chi2_ext / n_ext
131   -wrchi2_ext = rchi2_ext * !fit_rchi2_weight.ext
  131 +wrchi2_ext = rchi2_ext * (*!fit_rchi2_weight).ext
132 132 print,"chi2 EXT = ",chi2_ext," rchi2 EXT = ",rchi2_ext;," weighted rchi2 EXT=",wrchi2_ext
133 133 ;xr=[0.3,40]
134 134 ;yr=[1.e-26,1.e-21]
... ...
src/idl/dustem_set_data.pro
... ... @@ -313,30 +313,30 @@ if !run_pol then begin
313 313 endif
314 314  
315 315 IF keyword_set(rchi2_weight) THEN BEGIN
316   - !fit_rchi2_weight.sed = rchi2_weight.sed
317   - !fit_rchi2_weight.ext = rchi2_weight.ext
  316 + (*!fit_rchi2_weight).sed = rchi2_weight.sed
  317 + (*!fit_rchi2_weight).ext = rchi2_weight.ext
318 318  
319 319 IF !run_pol THEN BEGIN
320 320  
321   - IF isa(qsed) THEN !fit_rchi2_weight.qsed = rchi2_weight.qsed
322   - IF isa(used) THEN !fit_rchi2_weight.used = rchi2_weight.used
  321 + IF isa(qsed) THEN (*!fit_rchi2_weight).qsed = rchi2_weight.qsed
  322 + IF isa(used) THEN (*!fit_rchi2_weight).used = rchi2_weight.used
323 323  
324   - IF isa(qext) THEN !fit_rchi2_weight.qext = rchi2_weight.qext
325   - IF isa(uext) THEN !fit_rchi2_weight.uext = rchi2_weight.uext
  324 + IF isa(qext) THEN (*!fit_rchi2_weight).qext = rchi2_weight.qext
  325 + IF isa(uext) THEN (*!fit_rchi2_weight).uext = rchi2_weight.uext
326 326 ENDIF
327 327  
328 328 ENDIF ELSE BEGIN
329 329  
330   - !fit_rchi2_weight.sed=1.
331   - !fit_rchi2_weight.ext=1.
  330 + (*!fit_rchi2_weight).sed=1.
  331 + (*!fit_rchi2_weight).ext=1.
332 332  
333 333 If !run_pol THEN BEGIN
334 334  
335   - IF isa(qsed) THEN !fit_rchi2_weight.qsed=1.
336   - IF isa(used) THEN !fit_rchi2_weight.used=1.
  335 + IF isa(qsed) THEN (*!fit_rchi2_weight).qsed=1.
  336 + IF isa(used) THEN (*!fit_rchi2_weight).used=1.
337 337  
338   - IF isa(qext) THEN !fit_rchi2_weight.qext=1.
339   - IF isa(uext) THEN !fit_rchi2_weight.uext=1.
  338 + IF isa(qext) THEN (*!fit_rchi2_weight).qext=1.
  339 + IF isa(uext) THEN (*!fit_rchi2_weight).uext=1.
340 340  
341 341 ENDIF
342 342  
... ...
src/idl/dustem_show_file_dependencies.pro
... ... @@ -52,14 +52,11 @@ dustem_run_example,'MC10'
52 52 dustem_make_polarization_sed_example,model='G17_MODELA'
53 53 dustem_fit_intensity_example,Nitermax=1,fits_save_and_restore='/tmp/mysavefile1.fits'
54 54 dustem_fit_polarization_example,Nitermax=1,fits_save_and_restore='/tmp/mysavefile2.fits'
55   -
56   -dustem_fit_sed_ext_pol_example,Nitermax=1,fits_save_and_restore='/tmp/mysavefile2.fits'
57   -
58   -dustem_fit_ext_pol_example,Nitermax=1,fits_save_and_restore='/tmp/mysavefile2.fits'
59   -dustem_fit_intensity_mbb_example,Nitermax=1
60   -dustem_fit_modified_bb_example,Nitermax=1
61   -
62   -;dustem_fit_intensity_example
  55 +dustem_fit_ext_pol_example,Nitermax=1,fits_save_and_restore='/tmp/mysavefile3.fits'
  56 +dustem_fit_sed_ext_pol_example,Nitermax=1,fits_save_and_restore='/tmp/mysavefile4.fits'
  57 +dustem_fit_intensity_mbb_example,Nitermax=1,postscript='/tmp/dustemwrap_postcript_example.ps'
  58 +;The following is obsolete. No need to be there.
  59 +;dustem_fit_modified_bb_example,Nitermax=1
63 60 ; END LIST OF TOP-LEVEL ROUTINES
64 61  
65 62 help,/function,output=ff
... ...