Blame view

src/idl/dustem_plot_fit_sed.pro 7.93 KB
b5ccb706   Jean-Philippe Bernard   improved to fit p...
1
PRO dustem_plot_fit_sed,st,sed,cont,freefree,synchrotron, $
427f1205   Jean-Michel Glorian   version 4.2 merged
2
3
                        res=res,errors=errors,chi2=chi2,rchi2=rchi2, $
                        no_spec_error=no_spec_error, $
e71a7ada   Jean-Philippe Bernard   modified to work ...
4
5
6
                        help=help,win=win,ps=ps, $
                        legend_xpos=legend_xpos,legend_ypos=legend_ypos, $
                        _extra=_extra
427f1205   Jean-Michel Glorian   version 4.2 merged
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

;+
; NAME:
;    dustem_plot_fit_sed
; PURPOSE:
;    Plots a Dustem model and SED. Parameter values and error are
;    printed on plot. Used for plotting results during fit.
; CATEGORY:
;    Dustem
; CALLING SEQUENCE:
;    dustem_plot_fit_sed,st,sed,cont[,/no_spec_error][,res=][,errors=][,chi2=][,rchi2=][/help][_extra=]
; INPUTS:
;    st        = Dustem model output structure
;    sed       = Dustem model SED
;    cont      = Dustem model NIR continuum
; OPTIONAL INPUT PARAMETERS:
;    res       = fit result values. If set values are written on plot.
;    errors    = fit result errors. If set values are written on plot.
;    chi2      = fit chi^2. if set value is written on plot.
;    rchi2     = Reduced fit chi^2. if set value is written on plot.
;    _extra    = extra parameters for the plot routine
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    SED and model are plotted
; RESTRICTIONS:
;    The dustem idl wrapper must be installed
; PROCEDURE:
;    None
; EXAMPLES
;    dustem_plot_fit_sed,st,sed,cont
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard
;    see evolution details on the dustem cvs maintained at CESR
;    Contact J.-Ph. Bernard (Jean-Philippe.Bernard@cesr.fr) in case of problems.
;-

9ccf7615   Jean-Philippe Bernard   modified to fit u...
50
51
;stop

427f1205   Jean-Michel Glorian   version 4.2 merged
52
53
54
55
56
IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_plot_fit_sed'
  goto,the_end
ENDIF

9ccf7615   Jean-Philippe Bernard   modified to fit u...
57
58
59
IF keyword_set(ps) THEN BEGIN
   set_plot, 'PS'
   device, filename=ps, /color, /encapsulated
3b71def5   Jean-Philippe Bernard   improved
60
61
62
63
ENDIF ;ELSE BEGIN
;   set_plot,'X'
;    IF keyword_set(win) then window,win
;ENDELSE
427f1205   Jean-Michel Glorian   version 4.2 merged
64
65
66

fact = 1.e4*1.E20/(4.*!pi)/(3.e8/1.e-6/st.sed.wav)*1.e20/1.e7

9ccf7615   Jean-Philippe Bernard   modified to fit u...
67
68
69
70
;use_col_data_filt=70
;use_col_sed_spec=170
use_col_data_filt='blue'
use_col_sed_spec='red'
427f1205   Jean-Michel Glorian   version 4.2 merged
71
IF not keyword_set(col_sed) THEN BEGIN
9ccf7615   Jean-Philippe Bernard   modified to fit u...
72
73
  ;use_col_sed_filt=250     ;red
  use_col_sed_filt='red'     ;red
427f1205   Jean-Michel Glorian   version 4.2 merged
74
75
76
77
ENDIF ELSE BEGIN
  use_col_sed_filt=col_sed
ENDELSE
IF not keyword_set(col_tot) THEN BEGIN
9ccf7615   Jean-Philippe Bernard   modified to fit u...
78
79
  ;use_col_tot=200
  use_col_tot='black'
427f1205   Jean-Michel Glorian   version 4.2 merged
80
81
82
83
84
85
86
87
ENDIF ELSE BEGIN
  use_col_tot=col_tot
ENDELSE
IF not keyword_set(line_tot) THEN BEGIN
  use_line_tot=0
ENDIF ELSE BEGIN
  use_line_tot=line_tot
ENDELSE
b5ccb706   Jean-Philippe Bernard   improved to fit p...
88
;color and linestyle for continuum
427f1205   Jean-Michel Glorian   version 4.2 merged
89
IF not keyword_set(col_cont) THEN BEGIN
9ccf7615   Jean-Philippe Bernard   modified to fit u...
90
  ;use_col_cont=30
3b71def5   Jean-Philippe Bernard   improved
91
  use_col_cont='Navy'
427f1205   Jean-Michel Glorian   version 4.2 merged
92
93
94
95
ENDIF ELSE BEGIN
  use_col_count=col_cont
ENDELSE
IF not keyword_set(line_cont) THEN BEGIN
9ccf7615   Jean-Philippe Bernard   modified to fit u...
96
  use_line_cont=0
427f1205   Jean-Michel Glorian   version 4.2 merged
97
98
99
ENDIF ELSE BEGIN
  use_line_cont=line_cont
ENDELSE
b5ccb706   Jean-Philippe Bernard   improved to fit p...
100
101
102
;color and linestyle for freefree
IF not keyword_set(col_freefree) THEN BEGIN
  ;use_col_cont=30
3b71def5   Jean-Philippe Bernard   improved
103
  use_col_freefree='Dark Red'
b5ccb706   Jean-Philippe Bernard   improved to fit p...
104
105
106
107
108
109
110
111
112
113
ENDIF ELSE BEGIN
  use_col_freefree=col_freefree
ENDELSE
IF not keyword_set(line_freefree) THEN BEGIN
  use_line_freefree=0
ENDIF ELSE BEGIN
  use_line_freefree=line_freefree
ENDELSE
IF not keyword_set(col_synchrotron) THEN BEGIN
  ;use_col_cont=30
3b71def5   Jean-Philippe Bernard   improved
114
  use_col_synchrotron='Dark Red'
b5ccb706   Jean-Philippe Bernard   improved to fit p...
115
116
117
118
119
120
121
122
ENDIF ELSE BEGIN
  use_col_synchrotron=col_synchrotron
ENDELSE
IF not keyword_set(line_synchrotron) THEN BEGIN
  use_line_synchrotron=0
ENDIF ELSE BEGIN
  use_line_synchrotron=line_synchrotron
ENDELSE
427f1205   Jean-Michel Glorian   version 4.2 merged
123
124
125
126

;spec = st.sed.em_tot * fact + cont
spec = st.sed.em_tot * fact
IF !dustem_idl_continuum THEN spec=spec+cont
b5ccb706   Jean-Philippe Bernard   improved to fit p...
127
128
IF !dustem_idl_freefree THEN spec=spec+freefree
IF !dustem_idl_synchrotron THEN spec=spec+synchrotron
427f1205   Jean-Michel Glorian   version 4.2 merged
129

6730c3f8   Jean-Philippe Bernard   modified to be co...
130
131
;stop

427f1205   Jean-Michel Glorian   version 4.2 merged
132
133
134
;use_cols=[use_col_pah,use_col_vsg,use_col_bg,use_col_cont]
;use_lines=[use_line_pah,use_line_vsg,use_line_bg,use_line_cont]
col_off=30
6730c3f8   Jean-Philippe Bernard   modified to be co...
135
136
;Ngrains=(*!dustem_params).grain.Ngrains
Ngrains=(*!dustem_params).Ngrains
9ccf7615   Jean-Philippe Bernard   modified to fit u...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
;use_cols=long(findgen(Ngrains)/(Ngrains-1)*(255-col_off)+col_off)
use_cols=dustem_grains_colors(Ngrains,/cgplot)

use_lines=replicate(0,Ngrains)

norm = sed * 0. + 1

;IF !dustem_show_plot EQ 2 THEN BEGIN
;	norm = sed
;	yr=[0.,2.]
;	ylog = 0
;ENDIF ELSE BEGIN
;	norm = sed * 0. + 1
;	yr=[1e-4,10]
;	ylog = 1
;ENDELSE

;stop

;plot,(*!dustem_data.sed).wav,(*!dustem_data.sed).values/norm,/nodata,_extra=extra,yr=yr,/ys,ylog=ylog,/xlog
;stop
;===== waring: _extra not well taken by cgplot for unknown keywords ...
;cgplot,(*!dustem_data.sed).wav,(*!dustem_data.sed).values/norm,/nodata,_extra=extra,yr=yr,/ys,ylog=ylog,/xlog
cgplot,(*!dustem_data.sed).wav,(*!dustem_data.sed).values/norm,/nodata,yr=yr,/ys,ylog=ylog,/xlog,_extra=_extra
427f1205   Jean-Michel Glorian   version 4.2 merged
161
162
163
164
165
ind_filt=where((*!dustem_data.sed).filt_names NE 'SPECTRUM',count_filt)
ind_spec=where((*!dustem_data.sed).filt_names EQ 'SPECTRUM',count_spec)
;=== Plot the data
IF count_spec NE 0 THEN BEGIN
  plotsym,0,/fill
9ccf7615   Jean-Philippe Bernard   modified to fit u...
166
167
168
169
  xx=((*!dustem_data.sed).wav)[ind_spec]
  yy=((*!dustem_data.sed).values)[ind_spec]/norm[ind_spec]
  rms=3.*((*!dustem_data.sed).sigma)[ind_spec]/2./norm[ind_spec]
  cgoplot,xx,yy,psym=8,_extra=extra,syms=0.5
427f1205   Jean-Michel Glorian   version 4.2 merged
170
  IF not keyword_set(no_spec_error) THEN BEGIN
9ccf7615   Jean-Philippe Bernard   modified to fit u...
171
172
    cgerrplot,xx,yy-rms,yy+rms
    ;err_bar,((*!dustem_data.sed).wav)(ind_spec),((*!dustem_data.sed).values)(ind_spec)/norm(ind_spec),yrms=3.*((*!dustem_data.sed).sigma)(ind_spec)/2./norm(ind_spec)
427f1205   Jean-Michel Glorian   version 4.2 merged
173
174
175
  ENDIF
ENDIF
IF count_filt NE 0 THEN BEGIN
b5ccb706   Jean-Philippe Bernard   improved to fit p...
176
  ;stop
9ccf7615   Jean-Philippe Bernard   modified to fit u...
177
178
179
  xx=((*!dustem_data.sed).wav)[ind_filt]
  yy=((*!dustem_data.sed).values)[ind_filt]/norm[ind_filt]
  rms=3.*((*!dustem_data.sed).sigma)[ind_filt]/2./norm[ind_filt]
427f1205   Jean-Michel Glorian   version 4.2 merged
180
  plotsym,0,/fill
9ccf7615   Jean-Philippe Bernard   modified to fit u...
181
182
183
  cgoplot,xx,yy,psym=8,_extra=extra,color=use_col_data_filt
  ;err_bar,((*!dustem_data.sed).wav)(ind_filt),((*!dustem_data.sed).values)(ind_filt)/norm(ind_filt),yrms=3.*((*!dustem_data.sed).sigma)(ind_filt)/2./norm(ind_filt),color=use_col_data_filt
  cgerrplot,xx,yy-rms,yy+rms
427f1205   Jean-Michel Glorian   version 4.2 merged
184
185
186
187
ENDIF
;=== Plot the computed SED
IF count_filt NE 0 THEN BEGIN
  plotsym,8
9ccf7615   Jean-Philippe Bernard   modified to fit u...
188
189
190
  xx=((*!dustem_data.sed).wav)[ind_filt]
  yy=sed[ind_filt]/norm[ind_filt]
  cgoplot,xx,yy,color=use_col_sed_filt,psym=8,syms=2
427f1205   Jean-Michel Glorian   version 4.2 merged
191
192
193
ENDIF
IF count_spec NE 0 THEN BEGIN
  plotsym,0
9ccf7615   Jean-Philippe Bernard   modified to fit u...
194
195
196
  xx=((*!dustem_data.sed).wav)[ind_spec]
  yy=sed[ind_spec]/norm[ind_spec]
  cgoplot,xx,yy,color=use_col_sed_spec,psym=8,syms=0.5
427f1205   Jean-Michel Glorian   version 4.2 merged
197
198
199
ENDIF


9ccf7615   Jean-Philippe Bernard   modified to fit u...
200
IF !dustem_show_plot EQ 2 THEN BEGIN
427f1205   Jean-Michel Glorian   version 4.2 merged
201
	norm = spec
9ccf7615   Jean-Philippe Bernard   modified to fit u...
202
ENDIF ELSE BEGIN
427f1205   Jean-Michel Glorian   version 4.2 merged
203
	norm = spec * 0. + 1
9ccf7615   Jean-Philippe Bernard   modified to fit u...
204
ENDELSE
427f1205   Jean-Michel Glorian   version 4.2 merged
205
FOR i=0L,Ngrains-1 DO BEGIN
9ccf7615   Jean-Philippe Bernard   modified to fit u...
206
  cgoplot,st.sed.wav,st.sed.(i+1)*fact/norm,color=use_cols[i],linestyle=use_lines[i]
427f1205   Jean-Michel Glorian   version 4.2 merged
207
208
209
ENDFOR
;NIR continuum
IF !dustem_idl_continuum THEN BEGIN
9ccf7615   Jean-Philippe Bernard   modified to fit u...
210
  cgoplot,st.sed.wav,cont,color=use_col_cont,linestyle=use_line_cont
427f1205   Jean-Michel Glorian   version 4.2 merged
211
ENDIF
b5ccb706   Jean-Philippe Bernard   improved to fit p...
212
213
214
215
216
217
IF !dustem_idl_freefree THEN BEGIN
  cgoplot,st.sed.wav,freefree,color=use_col_freefree,linestyle=use_line_freefree
ENDIF
IF !dustem_idl_synchrotron THEN BEGIN
  cgoplot,st.sed.wav,synchrotron,color=use_col_synchrotron,linestyle=use_line_synchrotron
ENDIF
9ccf7615   Jean-Philippe Bernard   modified to fit u...
218
cgoplot,st.sed.wav,spec/norm,color=use_col_tot,linestyle=use_line_tot
427f1205   Jean-Michel Glorian   version 4.2 merged
219

9ccf7615   Jean-Philippe Bernard   modified to fit u...
220
;==== print the legend
427f1205   Jean-Michel Glorian   version 4.2 merged
221
222
223
frmt0='(A20)'
frmt1='(1E10.2)'
frmt2='(F7.2)'
b5ccb706   Jean-Philippe Bernard   improved to fit p...
224
225
226
227
228
229
230
231
;WE have to find a way to pass this through keywords ...
;use_legend_xpos=30.
;use_legend_ypos=-1
use_legend_xpos=2.e3
use_legend_ypos=2.5
IF keyword_set(legend_xpos) THEN use_legend_xpos=legend_xpos
IF keyword_set(legend_ypos) THEN use_legend_ypos=legend_ypos

427f1205   Jean-Michel Glorian   version 4.2 merged
232
233
IF keyword_set(res) THEN BEGIN
  offset=0.2
b5ccb706   Jean-Philippe Bernard   improved to fit p...
234
235
  ;xy_xpos=30.
  ;ystart=-1
427f1205   Jean-Michel Glorian   version 4.2 merged
236
237
238
239
240
241
  Npar=n_elements(res)
  FOR i=0L,Npar-1 DO BEGIN
;    sstr=(str_sep((*!PDO)(i),'(*!dustem_params).'))
    sstr=(str_sep((*(*!dustem_fit).param_descs)(i),'(*!dustem_params).'))
    ssstr=sstr(n_elements(sstr)-1)
    str=string(ssstr+'=',format=frmt0)+string(res(i),format=frmt1)
9ccf7615   Jean-Philippe Bernard   modified to fit u...
242
    ;stop
427f1205   Jean-Michel Glorian   version 4.2 merged
243
244
245
    IF keyword_set(errors) THEN BEGIN
      str=str+textoidl('\pm')+string(errors(i),format=frmt1)
    ENDIF
b5ccb706   Jean-Philippe Bernard   improved to fit p...
246
    xyouts,use_legend_xpos,10^(use_legend_ypos-(i+1)*offset),str,color=0
427f1205   Jean-Michel Glorian   version 4.2 merged
247
248
249
  ENDFOR
ENDIF
IF keyword_set(chi2) THEN BEGIN
b5ccb706   Jean-Philippe Bernard   improved to fit p...
250
  xyouts,use_legend_xpos,10^(use_legend_ypos-(Npar+1)*offset),string('chi2=',format=frmt0)+string(chi2,format=frmt2),color=0
427f1205   Jean-Michel Glorian   version 4.2 merged
251
252
ENDIF
IF keyword_set(rchi2) THEN BEGIN
b5ccb706   Jean-Philippe Bernard   improved to fit p...
253
  xyouts,use_legend_xpos,10^(use_legend_ypos-(Npar+2)*offset),string('red. chi2=',format=frmt0)+string(rchi2,format=frmt2),color=0
427f1205   Jean-Michel Glorian   version 4.2 merged
254
255
ENDIF

9ccf7615   Jean-Philippe Bernard   modified to fit u...
256
257
258
259
260
261
IF keyword_set(ps) THEN BEGIN
  device,/close
  set_plot,'X'
ENDIF

;stop
427f1205   Jean-Michel Glorian   version 4.2 merged
262
263
264
265

the_end:

END