Blame view

src/idl/dustemwrap_plot_noobj.pro 26 KB
9aceb888   Ilyes Choubani   Updating the non-...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
PRO dustemwrap_plot_noobj, p_dim,                            $
                           st = st,                          $
                           dustem_sed = dustem_sed,          $
                           SED_spec = SED_spec,              $
                           dustem_qsed = dustem_qsed,        $
                           Q_spec = Q_spec,                  $  
                           dustem_used = dustem_used,        $
                           U_spec = U_spec,                  $
                           dustem_polsed = dustem_polsed,    $
                           P_spec = P_spec,                  $ 
                           dustem_polfrac = dustem_polfrac,  $
                           SP_spec = SP_spec,                $
                           dustem_psi_em = dustem_psi_em,    $
                           PSI_spec = PSI_spec,              $
                           dustem_ext = dustem_ext,          $
                           EXT_spec = EXT_spec,              $
                           dustem_qext = dustem_qext,        $
                           QEXT_spec = QEXT_spec,            $
                           dustem_uext = dustem_uext,        $
                           UEXT_spec = UEXT_spec,            $
                           dustem_polext = dustem_polext,    $
                           POLEXT_spec = POLEXT_spec,        $
                           dustem_fpolext = dustem_fpolext,  $
                           SPEXT_spec = SPEXT_spec,          $
                           dustem_psi_ext = dustem_psi_ext,  $
                           PSIEXT_spec = PSIEXT_spec,        $
                           _extra = _extra,                    $
                           help = help
ed831104   Ilyes Choubani   no obj plotting
29
30
31

;+
; NAME:
bffa7018   Ilyes Choubani   update
32
;    dustemwrap_plot_noobj
ed831104   Ilyes Choubani   no obj plotting
33
; PURPOSE:
bffa7018   Ilyes Choubani   update
34
;    plots dustemwrap observed sed, predicted sed, predicted spectra for total Intensity, polarization in emission and extinction without OOP routines
ed831104   Ilyes Choubani   no obj plotting
35
36
37
; CATEGORY:
;    DustEMWrap
; CALLING SEQUENCE:
bffa7018   Ilyes Choubani   update
38
;    dustemwrap_plot_noobj,p_dim,st,dustem_sed,SED_spec,dustem_qsed,Q_spec,dustem_used,U_spec,dustem_polsed,P_spec,dustem_polfrac,SP_spec,dustem_psi_em,PSI_spec,dustem_ext,EXT_spec,dustem_qext,QEXT_spec,dustem_uext,UEXT_spec,dustem_polext,POLEXT_spec,dustem_fpolext,SPEXT_spec,dustem_psi_ext,PSIEXT_spec,_extra=_extra 
ed831104   Ilyes Choubani   no obj plotting
39
; INPUTS:
52a3c8dc   Jean-Philippe Bernard   mise a jour
40
;    p_dim         = dustemwrap free parameter values
ed831104   Ilyes Choubani   no obj plotting
41
; OPTIONAL INPUT PARAMETERS:
52a3c8dc   Jean-Philippe Bernard   mise a jour
42
;    st            = dustemwrap structure.
ed831104   Ilyes Choubani   no obj plotting
43
44
45
46
47
48
49
50
51
52
53
54
55
;    dustem_sed
;    dustem_qsed
;    dustem_used
;    dustem_polsed
;    dustem_polfrac
;    dustem_psi_em
;    dustem_ext
;    dustem_qext
;    dustem_uext
;    dustem_polext
;    dustem_fpolext
;    dustem_psi_ext
; OUTPUTS:
52a3c8dc   Jean-Philippe Bernard   mise a jour
56
57
58
; OPTIONAL OUTPUT PARAMETERS:
;    st              = currently returns dustemwrap structure if not provided as an entry.
;    dustem_sed      = 
ed831104   Ilyes Choubani   no obj plotting
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;    dustem_qsed
;    dustem_used
;    dustem_polsed
;    dustem_polfrac
;    dustem_psi_em
;    dustem_ext
;    dustem_qext
;    dustem_uext
;    dustem_polext
;    dustem_fpolext
;    dustem_psi_ext
;    SED_spec
;    Q_spec
;    U_spec
;    P_spec
;    SP_spec
;    PSI_spec
;    EXT_spec
;    QEXT_spec
;    UEXT_spec
;    POLEXT_spec
;    SPEXT_spec
;    PSIEXT_spec
ed831104   Ilyes Choubani   no obj plotting
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
; ACCEPTED KEY-WORDS:
;    help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    Does a plot
; RESTRICTIONS:
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
; PROCEDURES AND SUBROUTINES USED:
;
; EXAMPLES
;    
; MODIFICATION HISTORY:
;    Written by Ilyes Choubani
;    Evolution details on the DustEMWrap gitlab.
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'dustemwrap_plot'
  goto,the_end
END

;This is also necessary for the plotting of the results of the fit (Last iteration) 
IF not keyword_set(st) THEN BEGIN
3d0f6b67   Ilyes Choubani   rest of plotting ...
107
;Activation of the plugins is needed because of the plotting of the total emission model that includes them. 
52a3c8dc   Jean-Philippe Bernard   mise a jour
108
  dustem_activate_plugins,p_dim/(*(*!dustem_fit).param_init_values),st=st
3d0f6b67   Ilyes Choubani   rest of plotting ...
109
ENDIF 
ed831104   Ilyes Choubani   no obj plotting
110
  
52a3c8dc   Jean-Philippe Bernard   mise a jour
111
112
;==== compute emission and emission polarization SED if not provided
IF NOT keyword_set(dustem_sed) AND isa((*!dustem_data).sed) THEN BEGIN
3d0f6b67   Ilyes Choubani   rest of plotting ...
113
  dustem_sed = dustem_compute_sed(p_dim,st=st,SED_spec=SED_spec)
52a3c8dc   Jean-Philippe Bernard   mise a jour
114
  IF !run_pol AND !run_lin AND tag_exist(*!dustem_show,'qsed') THEN BEGIN
3d0f6b67   Ilyes Choubani   rest of plotting ...
115
116
117
118
     dustem_polsed = dustem_compute_polsed(p_dim,st=st,P_spec=P_spec,SP_spec=SP_spec,dustem_polfrac=dustem_polfrac)
     toto = dustem_compute_stokes(p_dim,st=st,Q_spec=Q_spec,U_spec=U_spec,PSI_spec=PSI_spec,dustem_psi_em=dustem_psi_em) 
     dustem_qsed = toto[0]
     dustem_used = toto[1]   
52a3c8dc   Jean-Philippe Bernard   mise a jour
119
120
  ENDIF         
ENDIF
3d0f6b67   Ilyes Choubani   rest of plotting ...
121

52a3c8dc   Jean-Philippe Bernard   mise a jour
122
123
;==== compute extinction and extinction polarization SED if not provided
IF NOT keyword_set(dustem_ext) AND isa((*!dustem_data).ext) THEN BEGIN
3d0f6b67   Ilyes Choubani   rest of plotting ...
124
    dustem_ext = dustem_compute_ext(p_dim,st=st,EXT_spec=EXT_spec)
52a3c8dc   Jean-Philippe Bernard   mise a jour
125
    IF !run_pol AND !run_lin AND tag_exist(*!dustem_show,'qext') THEN BEGIN
3d0f6b67   Ilyes Choubani   rest of plotting ...
126
      dustem_polext = dustem_compute_polext(p_dim,st=st,polext_spec=POLEXT_spec,spext_spec=SPEXT_spec,dustem_fpolext=dustem_fpolext)
3d0f6b67   Ilyes Choubani   rest of plotting ...
127
128
129
      toto = dustem_compute_stokext(p_dim,st=st,QEXT_spec=QEXT_spec,UEXT_spec=UEXT_spec,PSIEXT_spe=PSIEXT_spec,dustem_psi_ext=dustem_psi_ext) 
      dustem_qext = toto[0]
      dustem_uext = toto[1]   
52a3c8dc   Jean-Philippe Bernard   mise a jour
130
131
    ENDIF
ENDIF
3d0f6b67   Ilyes Choubani   rest of plotting ...
132
  
52a3c8dc   Jean-Philippe Bernard   mise a jour
133
;==== This section is to keep track of chi2 evolution during fit iterations.
bffa7018   Ilyes Choubani   update
134
135
136
137
138
mouchard=*!iteration_mouchard
new_mouchard=mouchard[0]
new_mouchard.iteration=!dustem_iter.act
new_mouchard.chi2=(*!dustem_fit).chi2
new_mouchard.rchi2=(*!dustem_fit).rchi2
bffa7018   Ilyes Choubani   update
139
140
mouchard=[mouchard,new_mouchard]
!iteration_mouchard=ptr_new(mouchard)
ed831104   Ilyes Choubani   no obj plotting
141

9aceb888   Ilyes Choubani   Updating the non-...
142
143
144
;===========Initializing tests
test_sed = isa((*!dustem_data).sed) 
test_ext = isa((*!dustem_data).ext)
ed831104   Ilyes Choubani   no obj plotting
145

9aceb888   Ilyes Choubani   Updating the non-...
146
147
;===========Bunch of tests that are not important now but that
;might be in future releases. To adjust the layout of the dashboard for instance
ed831104   Ilyes Choubani   no obj plotting
148
if !run_pol then begin
9aceb888   Ilyes Choubani   Updating the non-...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    if tag_exist(*!dustem_show,'qsed') then begin ;testing to account for the fact that the user can activate the !run_pol keyword without knowing
    ;ie: using a dust model with polarization w/o polarization data present...
        test_polsed = isa((*!dustem_show).polsed)
        test_polfrac = isa((*!dustem_show).polfrac)
        test_qsed = isa((*!dustem_show).qsed)
        test_used = isa((*!dustem_show).used)
        test_psi_em = isa((*!dustem_show).psi_em)
    endif
    
    if tag_exist(*!dustem_show,'qext') then begin
        test_polext = isa((*!dustem_show).polext)
        test_psi_ext = isa((*!dustem_show).psi_ext)
        test_fpolext = isa((*!dustem_show).fpolext)
        test_qext = isa((*!dustem_show).qext)
        test_uext = isa((*!dustem_show).uext)
    endif
    
    if tag_exist(*!dustem_show,'qsed') then test_m = test_sed or test_polsed $
                                                  or test_polfrac or test_qsed $
                                                  or test_used or test_psi_em
    if tag_exist(*!dustem_show,'qext') then test_x = test_ext or test_polext $
                                                  or test_fpolext or test_qext $
                                                  or test_uext or test_psi_ext
                                                  
    if ~tag_exist(*!dustem_show,'qsed') then test_m = test_sed
    if ~tag_exist(*!dustem_show,'qext') then test_x = test_ext 
                                        
ed831104   Ilyes Choubani   no obj plotting
176
177
178
179
180
181
182
183
184
185
186
187
188
189
endif else begin
    test_m = test_sed 
    test_x = test_ext 
endelse

;testing on the fitting of emission vs extinction data

n_plgns = n_tags(*!dustem_plugin)

frmt0='(A36)'
frmt1='(1E10.2)'
frmt2='(10F10.2)'

;Instead of setting the extra tags for plotting in dustemcgwin, we'll place them in this (parent) procedure. 
9aceb888   Ilyes Choubani   Updating the non-...
190
;tgnms_extra = tag_names(_extra)
ed831104   Ilyes Choubani   no obj plotting
191

3d0f6b67   Ilyes Choubani   rest of plotting ...
192
dustem_set_plot_range,test_sed, test_ext,_extra= _extra
ed831104   Ilyes Choubani   no obj plotting
193

9aceb888   Ilyes Choubani   Updating the non-...
194
195
196
197
;change starts form here!!!!


;===========Retrieving some data relevant to the plotting
ed831104   Ilyes Choubani   no obj plotting
198
if isa((*!dustem_fit).current_param_errors) then begin
9aceb888   Ilyes Choubani   Updating the non-...
199
    errors = (*(*!dustem_fit).current_param_errors) ;* (*(*!dustem_fit).param_init_values) ;multiplied internally in dustem_mpfit. Should maybe be changed.
ed831104   Ilyes Choubani   no obj plotting
200
endif else begin
9aceb888   Ilyes Choubani   Updating the non-...
201
    errors = (*(*!dustem_fit).param_init_values)*0.;+la_undef();Initialized to 0 instead of la_undef() 
ed831104   Ilyes Choubani   no obj plotting
202
203
204
205
206
ENDELSE 

if isa((*!dustem_fit).chi2) then begin
    chi2 = (*!dustem_fit).chi2    
endif else begin
9aceb888   Ilyes Choubani   Updating the non-...
207
    chi2 = la_undef();maybe not the best initialization 
ed831104   Ilyes Choubani   no obj plotting
208
209
210
211
212
endelse 

if isa((*!dustem_fit).rchi2) then begin
    rchi2 = (*!dustem_fit).rchi2    
endif else begin
9aceb888   Ilyes Choubani   Updating the non-...
213
    rchi2 = la_undef();maybe not the best initialization 
ed831104   Ilyes Choubani   no obj plotting
214
215
216
endelse 


9aceb888   Ilyes Choubani   Updating the non-...
217
218
;===========Window positionning parameters
if !run_pol and tag_exist(*!dustem_show,'qsed') then BEGIN
ed831104   Ilyes Choubani   no obj plotting
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    wdelta_x=60
    main_wxsize=910
    main_wysize=658

    param_wxpos=main_wxsize+wdelta_x
    param_wypos=15
    param_wxsize=350
    param_wysize=200

    plugin_wxpos=main_wxsize+wdelta_x
    plugin_wypos=300
    plugin_wxsize=350
    plugin_wysize=200
ENDIF ELSE BEGIN
    wdelta_x=60
    main_wxsize=640  ;default of cgwindow
    main_wysize=512  ;default of cgwindow

    param_wxpos=main_wxsize+wdelta_x;700
    param_wypos=15
    param_wxsize=350
    param_wysize=200

    plugin_wxpos=main_wxsize+wdelta_x;700
    plugin_wypos=300
    plugin_wxsize=350
    plugin_wysize=200
ENDELSE

a7d7a5d5   Jean-Philippe Bernard   cleaned the code....
248
249
250
251
252
253
;JPB: I moved these 3 lines out of the if test, so that they apply also
;when only extinction is present
TVLCT, 255, 255, 255, 254 ; White color
!P.Color = 253
!P.Background = 254

ed831104   Ilyes Choubani   no obj plotting
254
255
if test_m then begin
    ;Generating emission window and saving window ID
9aceb888   Ilyes Choubani   Updating the non-...
256
257
    IF !d.name NE 'PS' THEN BEGIN  ;What if we're trying to create a ps file with the exact display of the dashboard?  
        window,0, xsize=main_wxsize,ysize=main_wysize,title='DUSTEMWRAP '+!dustem_version.version+' (EMISSION)',xpos=0,ypos=0 
134c5e51   Jean-Philippe Bernard   modfied to be abl...
258
    ENDIF
ed831104   Ilyes Choubani   no obj plotting
259
    ;Plotting model string (legend)
134c5e51   Jean-Philippe Bernard   modfied to be abl...
260
    xxpos = 0.015 
ed831104   Ilyes Choubani   no obj plotting
261
262
    yypos = 0.97
    ;Plotting Hydrogen column density string (legend)
134c5e51   Jean-Philippe Bernard   modfied to be abl...
263
    cgtext,  xxpos, yypos,'Model : '+!dustem_model,color=0,/normal,charsize = 1.2;,/addcmd ;& cmdind_m+=1 This is the first command in the window
ed831104   Ilyes Choubani   no obj plotting
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    yypos = 0.95
    cgtext, xxpos, yypos,textoidl('N_{H}')+textoidl(' (H/cm^2) : ')+strmid(string(*!dustem_HCD,format='(1E10.2)'),2),color=0,/normal,charsize = 1.2;,/addcmd & cmdind_m+=1
    
    ;Plotting of the number of iterations completed by the fitter
    
    ;Plotting of the number of runs
    ;Getting the width of the unrefreshed string
    widthtot=0.
    ;cgtext, xxpos, yypos,'Runs : ',color=0,/normal,charsize=-1,width=thiswidth,/addcmd & cmdind_m+=1
    cgtext, xxpos, yypos,'Iteration : ',color=0,/normal,charsize=-1,width=thiswidth 
    widthtext = thiswidth
    widthtot+= thiswidth ;fixed width
    !dustemcgwin_ncmds.runs.txtwdth = thiswidth
    
    ;Getting the width of the refreshed string
    cgtext, xxpos, yypos,strtrim(!dustem_iter.act,2),color=0,/normal,charsize=-1,width=thiswidth 
    widthtot+= thiswidth;varying width        
    
    ;These two lines will also have to      be modified when plotting the refreshed values
    xxpos = 0.015 ;1.0 - widthtot - 0.03
    yypos = 0.015
    
    ;Displaying fixed part
    ;cgtext, xxpos, yypos,'Runs : ',color=0,/normal,charsize = 1.35,/addcmd & cmdind_m+=1
    cgtext, xxpos, yypos,'Iteration : ',color=0,/normal,charsize = 1.35 
9aceb888   Ilyes Choubani   Updating the non-...
289
    ;Displaying refreshed part 
7d129a82   Ilyes Choubani   updating minor di...
290
    cgtext, xxpos + widthtext*1.35 + 0.015 , yypos,strtrim(!dustem_iter.act,2),color=0,/normal,charsize = 1.0 
ed831104   Ilyes Choubani   no obj plotting
291
292
293
294
295
296
297
298
299
300
301
302
303
304
    
    ;plotting of (mostly) fixed data for rchi2
    ;Since the format of the strings is specified, the length/width of the string in thex direction is fixed. 
    
    
    ;Getting the width of the unrefreshed string
    widthtot=0.
    cgtext, xxpos, yypos,textoidl('\chi^{2} : '),color=0,/normal,charsize=-1,width=thiswidth 
    widthtext = thiswidth
    widthtot+= thiswidth ;fixed width
    
    ;Getting the width of the refresh.ed string
    cgtext, xxpos, yypos,strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize=-1,width=thiswidth 
    widthtot+= thiswidth;varying width        
9aceb888   Ilyes Choubani   Updating the non-...
305
   
ed831104   Ilyes Choubani   no obj plotting
306
307
308
309
310
311
312
    
    xxpos = 1.0 - widthtot - 0.03
    
    yypos = 0.97
    
    ;Displaying fixed part
    cgtext, xxpos, yypos,textoidl('\chi^{2} : '),color=0,/normal,charsize = 1.0 
9aceb888   Ilyes Choubani   Updating the non-...
313
    
ed831104   Ilyes Choubani   no obj plotting
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
    
    cgtext, xxpos + widthtext , yypos,strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize = 1.0 
   
    
    ;plotting of (mostly) fixed data for rchi2
    
    ;Getting the width of the unrefreshed string
    widthtot=0.
    cgtext, xxpos, yypos,textoidl('r_{\chi^{2}} : '),color=0,/normal,charsize=-1,width=thiswidth 
    widthtext = thiswidth
    widthtot+= thiswidth ;fixed width
    ;!dustemcgwin_ncmds.rchi2.txtwdth1 = thiswidth
    ;Getting the width of the refreshed string
    cgtext, xxpos, yypos,strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize=-1,width=thiswidth 
    widthtot+= thiswidth;varying width        
    
    
    ;These two lines will also have to      be modified when plotting the refreshed values
    xxpos = 1.0 - widthtot - 0.03
    yypos = 0.95
    
    ;Displaying fixed part
    cgtext, xxpos, yypos,textoidl('r_{\chi^{2}} : '),color=0,/normal,charsize = 1.35 
ed831104   Ilyes Choubani   no obj plotting
337
    
9aceb888   Ilyes Choubani   Updating the non-...
338
339
340
    
    cgtext, xxpos + widthtext , yypos,strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize = 1.0 
   
ed831104   Ilyes Choubani   no obj plotting
341
342
343
344
345
    ;Plotting of the title of the dashboard (plot(s))
    
    
    ;NB issue here because the user can't modify the title after the dustem_mpfit_data call at the main procedure level (user proc)
    ;Getting the width of the title 
ed831104   Ilyes Choubani   no obj plotting
346
    
3d0f6b67   Ilyes Choubani   rest of plotting ...
347
348
349
350
351
352
353
354
355
356
357
358
359
    tit=!dustem_plot_range.title_m
    
    xxpos = 0.5
    yypos =0.96
    
    ;the runs inbetween
    if !dustem_end EQ 0 then cgtext, xxpos , yypos,tit+' (RUNNING)',color=0,/normal,charsize = 1.6,alignment=0.5
    
    ;subsequent iterations to the end of the fit
    if !dustem_end EQ -1 then cgtext, xxpos , yypos,tit,color=0,/normal,charsize = 1.6,alignment=0.5
    
    ;last iteration of the fit
    if !dustem_end EQ 1 then cgtext, xxpos , yypos,tit+' (FINAL RUN)',color=0,/normal,charsize = 1.6,alignment=0.5
ed831104   Ilyes Choubani   no obj plotting
360
     
ed831104   Ilyes Choubani   no obj plotting
361
    
9aceb888   Ilyes Choubani   Updating the non-...
362
   if !run_pol and tag_exist(*!dustem_show,'qsed') then begin
ed831104   Ilyes Choubani   no obj plotting
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
        ;,wback='grey'
        
        ;position arrays for plot and normalized graph
        
        ;THIS IS HARD-CODED IN A VERY SILLY WAY
        
        p_sed = [0.05,0.67,0.475,0.90]
        p_psed = [0.525,0.67,0.95,0.90]
        p_spsed = [0.05,0.375,0.475,0.575]
        p_psised = [0.525,0.375,0.95,0.575]
        p_qsed = [0.05,0.12,0.475,0.35]  
        p_used = [0.525,0.12,0.95,0.35]
        
        np_sed = [0.05,0.60,0.475,0.67]
        np_psed = [0.525,0.60,0.95,0.67]
        np_qsed = [0.05,0.05,0.475,0.12] 
        np_used = [0.525,0.05,0.95,0.12]
        
        p_sed[1]+= 0.0125 & p_sed[3]+= 0.0125 
        p_psed[1]+= 0.0125 & p_psed[3]+= 0.0125
        p_spsed[1]+= 0.0125 & p_spsed[3]+= 0.0125
        p_psised[1]+= 0.0125 & p_psised[3]+= 0.0125
        p_qsed[1]+= 0.0125 & p_qsed[3]+= 0.0125
        p_used[1]+= 0.0125 & p_used[3]+= 0.0125
        
        np_sed[1]+= 0.0125 & np_sed[3]+= 0.0125 
        np_psed[1]+= 0.0125 & np_psed[3]+= 0.0125
        np_qsed[1]+= 0.0125 & np_qsed[3]+= 0.0125
        np_used[1]+= 0.0125 & np_used[3]+= 0.0125
        
        
          
    endif else begin
        p_sed  = [0.07,0.30,0.97,0.85]
        np_sed = [0.07,0.10,0.97,0.30]
    
    endelse

9aceb888   Ilyes Choubani   Updating the non-...
401
    plotsym,0,/fill
ed831104   Ilyes Choubani   no obj plotting
402
    
9aceb888   Ilyes Choubani   Updating the non-...
403
404
405
406
    ;block for the collective plotting of the datasets - copied as is
    if !run_pol and tag_exist(*!dustem_show,'qsed') then begin
        ;This part can be adjusted for future releases if the user wants to plot 
        ;specific datasets 
ed831104   Ilyes Choubani   no obj plotting
407
        
9aceb888   Ilyes Choubani   Updating the non-...
408
409
410
411
412
413
        ;lists because elements have different dimensions and/or we want entire arrays as elements
        dustem_interp = list(dustem_sed,dustem_polfrac,dustem_qsed,dustem_used,dustem_psi_em,dustem_polsed) ;DustEmWrap SED predictions
        dustem_spec = list(SED_spec,SP_spec,Q_spec,U_spec,PSI_spec,P_spec) ;DustEM spectra predictions
        extra_spec = list(0,SED_spec,0,0,0,0) ;extra spectra that the dataset needs in order to be plotted. 
        ;This (extra_spec use) actually should not be generalized since the only case we need an extra spectrum is when plotting the polarization fraction.
        position = list(list(p_sed,np_sed),list(p_spsed),list(p_qsed,np_qsed),list(p_used,np_used),list(p_psised),list(p_psed,np_psed))
ed831104   Ilyes Choubani   no obj plotting
414
        
9aceb888   Ilyes Choubani   Updating the non-...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
        ;these don't have to be lists
        datasets = ['SED','POLFRAC','QSED','USED','PSI_EM','POLSED']
        ;but these can be combined using a list but we're leaving it as is for the moment...
        positiveonly = [0,0,1,1,0,0] ;used for q and u
        negativeonly = [0,0,1,1,0,0] ;used for q and u
    ENDIF ELSE BEGIN
    
        dustem_interp = list(dustem_sed) ;DustEmWrap SED predictions . 
        dustem_spec = list(SED_spec) ;DustEM spectra predictions
        position = list(p_sed,np_sed);list(list(p_sed,np_sed)) ; I think I need this ...
        ;position_n =list(np_sed) 
        datasets = ['SED']
        ;replace by one keyword?
        positiveonly=[0] ;kept it for completeness. Also this loop reminds me that JP also wants the user to be able to display one dataset. 
        negativeonly=[0]
    ENDELSE
9aceb888   Ilyes Choubani   Updating the non-...
431
    ; PLOTTING OF DATA THAT IS UNCHAED  
52a3c8dc   Jean-Philippe Bernard   mise a jour
432
433
    dustem_plot_dataset,st,dataset=datasets,position=position $
                       ,positive_only=positiveonly,negative_only=negativeonly, _extra=_extra
9aceb888   Ilyes Choubani   Updating the non-...
434
    ; REFRESHING DATA - to plot the refreshed data for the first time.
52a3c8dc   Jean-Philippe Bernard   mise a jour
435
436
437
438
    dustem_plot_dataset,st,dustem_interp,dustem_spec,extra_spec=extra_spec $
                       ,dataset=datasets,positive_only=positiveonly,negative_only=negativeonly $
                       ,/refresh,position=position,_extra=_extra
ENDIF
ed831104   Ilyes Choubani   no obj plotting
439

ee57e2f7   Jean-Philippe Bernard   removed stops
440
;stop
ed831104   Ilyes Choubani   no obj plotting
441
442
if test_x then begin
    ;Generating extinction window and saving window ID
ed831104   Ilyes Choubani   no obj plotting
443
    
9aceb888   Ilyes Choubani   Updating the non-...
444
445
446
    ;the 'PS' condition pertaining to fawlty debugging is not present here...
    window,1,xsize=main_wxsize,ysize=main_wysize,title='DUSTEMWRAP '+!dustem_version.version+' (EXTINCTION)' 
                      
ed831104   Ilyes Choubani   no obj plotting
447
    
55275be6   Ilyes Choubani   allowing no_obj p...
448
449
450
451
452
453
454
    ;Plotting model string (legend)
    xxpos = 0.015
    yypos = 0.97
    ;Plotting Hydrogen column density string (legend)
    cgtext, xxpos, yypos,'Model : '+!dustem_model,color=0,/normal,charsize = 1.2;,/addcmd ;& cmdind_m+=1 This is the first command in the window
    yypos = 0.95
    cgtext, xxpos, yypos,textoidl('N_{H}')+textoidl(' (H/cm^2) : ')+strmid(string(*!dustem_HCD,format='(1E10.2)'),2),color=0,/normal,charsize = 1.2
ed831104   Ilyes Choubani   no obj plotting
455
    
55275be6   Ilyes Choubani   allowing no_obj p...
456
    ;Plotting of the number of iterations completed by the fitter
ed831104   Ilyes Choubani   no obj plotting
457
    
55275be6   Ilyes Choubani   allowing no_obj p...
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
    ;Plotting of the number of runs
    ;Getting the width of the unrefreshed string
    widthtot=0.
    ;cgtext, xxpos, yypos,'Runs : ',color=0,/normal,charsize=-1,width=thiswidth,/addcmd & cmdind_x+=1
    cgtext, xxpos, yypos,'Iteration : ',color=0,/normal,charsize=-1,width=thiswidth
    widthtext = thiswidth
    widthtot+= thiswidth ;fixed width
    
    ;Getting the width of the refreshed string
    cgtext, xxpos, yypos,strtrim(!dustem_iter.act,2),color=0,/normal,charsize=-1,width=thiswidth
    widthtot+= thiswidth;varying width        
    
    ;These two lines will also have to      be modified when plotting the refreshed values
    xxpos = 0.015 ;1.0 - widthtot - 0.03
    yypos = 0.015
    
    ;Displaying fixed part
    ;cgtext, xxpos, yypos,'Runs : ',color=0,/normal,charsize = 1.35,/addcmd & cmdind_x+=1
    cgtext, xxpos, yypos,'Iteration : ',color=0,/normal,charsize = 1.35
55275be6   Ilyes Choubani   allowing no_obj p...
477
478
    
    
9aceb888   Ilyes Choubani   Updating the non-...
479
480
    cgtext, xxpos + widthtext + 0.015 , yypos,strtrim(!dustem_iter.act,2),color=0,/normal,charsize = 1.0
    
55275be6   Ilyes Choubani   allowing no_obj p...
481
482
483
484
485
486
487
488
489
490
491
492
493
    ;plotting of (mostly) fixed data for rchi2
    ;Since the format of the strings is specified, the length/width of the string in thex direction is fixed. 
    
    
    ;Getting the width of the unrefreshed string
    widthtot=0.
    cgtext, xxpos, yypos,textoidl('\chi^{2} : '),color=0,/normal,charsize=-1,width=thiswidth
    widthtext = thiswidth
    widthtot+= thiswidth ;fixed width
    
    ;Getting the width of the refresh.ed string
    cgtext, xxpos, yypos,strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize=-1,width=thiswidth
    widthtot+= thiswidth;varying width        
55275be6   Ilyes Choubani   allowing no_obj p...
494
495
496
497
498
499
500
501
    
    
    xxpos = 1.0 - widthtot - 0.03
    
    yypos = 0.97
    
    ;Displaying fixed part
    cgtext, xxpos, yypos,textoidl('\chi^{2} : '),color=0,/normal,charsize = 1.0
55275be6   Ilyes Choubani   allowing no_obj p...
502
503
504
    
    cgtext, xxpos + widthtext , yypos,strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize = 1.0
    
55275be6   Ilyes Choubani   allowing no_obj p...
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
    ;plotting of (mostly) fixed data for rchi2
    
    ;Getting the width of the unrefreshed string
    widthtot=0.
    cgtext, xxpos, yypos,textoidl('r_{\chi^{2}} : '),color=0,/normal,charsize=-1,width=thiswidth
    widthtext = thiswidth
    widthtot+= thiswidth ;fixed width
    ;!dustemcgwin_ncmds.rchi2.txtwdth1 = thiswidth
    ;Getting the width of the refreshed string
    cgtext, xxpos, yypos,strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize=-1,width=thiswidth
    widthtot+= thiswidth;varying width        
    
    ;These two lines will also have to      be modified when plotting the refreshed values
    xxpos = 1.0 - widthtot - 0.03
    yypos = 0.95
    
    ;Displaying fixed part
    cgtext, xxpos, yypos,textoidl('r_{\chi^{2}} : '),color=0,/normal,charsize = 1.35
9aceb888   Ilyes Choubani   Updating the non-...
523
   
55275be6   Ilyes Choubani   allowing no_obj p...
524
    cgtext, xxpos + widthtext , yypos,strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize = 1.0
9aceb888   Ilyes Choubani   Updating the non-...
525
  
3d0f6b67   Ilyes Choubani   rest of plotting ...
526
527
   ;plotting of title 
    tit=!dustem_plot_range.title_x
55275be6   Ilyes Choubani   allowing no_obj p...
528
    
3d0f6b67   Ilyes Choubani   rest of plotting ...
529
530
    xxpos = 0.5
    yypos =0.96
55275be6   Ilyes Choubani   allowing no_obj p...
531
    
3d0f6b67   Ilyes Choubani   rest of plotting ...
532
533
    ;the runs inbetween
    if !dustem_end EQ 0 then cgtext, xxpos , yypos,tit+' (RUNNING)',color=0,/normal,charsize = 1.6,alignment=0.5
55275be6   Ilyes Choubani   allowing no_obj p...
534
    
3d0f6b67   Ilyes Choubani   rest of plotting ...
535
536
    ;subsequent iterations to the end of the fit
    if !dustem_end EQ -1 then cgtext, xxpos , yypos,tit,color=0,/normal,charsize = 1.6,alignment=0.5
55275be6   Ilyes Choubani   allowing no_obj p...
537
    
3d0f6b67   Ilyes Choubani   rest of plotting ...
538
539
    ;last iteration of the fit
    if !dustem_end EQ 1 then cgtext, xxpos , yypos,tit+' (FINAL RUN)',color=0,/normal,charsize = 1.6,alignment=0.5
55275be6   Ilyes Choubani   allowing no_obj p...
540
    
55275be6   Ilyes Choubani   allowing no_obj p...
541
    
9aceb888   Ilyes Choubani   Updating the non-...
542
    if !run_pol  and tag_exist(*!dustem_show,'qext') then begin
bffa7018   Ilyes Choubani   update
543
       
ed831104   Ilyes Choubani   no obj plotting
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
        ;position arrays for plot and normalized graph
        
        ;THIS IS HARD-CODED IN A VERY SILLY WAY
        
        p_ext = [0.05,0.67,0.475,0.90]
        p_pext = [0.525,0.67,0.95,0.90]
        p_spext = [0.05,0.375,0.475,0.575] ; Should we plot this? tau_polext/tau_ext_tot. YES FOR NOW...
        p_psiext = [0.525,0.375,0.95,0.575]
        p_qext = [0.05,0.12,0.475,0.35]  
        p_uext = [0.525,0.12,0.95,0.35]
        
        np_ext = [0.05,0.60,0.475,0.67]
        np_pext = [0.525,0.60,0.95,0.67]
        np_qext = [0.05,0.05,0.475,0.12] 
        np_uext = [0.525,0.05,0.95,0.12]
        
        p_ext[1]+= 0.0125 & p_ext[3]+= 0.0125 
        p_pext[1]+= 0.0125 & p_pext[3]+= 0.0125
        p_spext[1]+= 0.0125 & p_spext[3]+= 0.0125
        p_psiext[1]+= 0.0125 & p_psiext[3]+= 0.0125
        p_qext[1]+= 0.0125 & p_qext[3]+= 0.0125
        p_uext[1]+= 0.0125 & p_uext[3]+= 0.0125
        
        np_ext[1]+= 0.0125 & np_ext[3]+= 0.0125 
        np_pext[1]+= 0.0125 & np_pext[3]+= 0.0125
        np_qext[1]+= 0.0125 & np_qext[3]+= 0.0125
        np_uext[1]+= 0.0125 & np_uext[3]+= 0.0125
        
        
          
    endif else begin
        p_ext  = [0.07,0.30,0.97,0.85]
        np_ext = [0.07,0.10,0.97,0.30]
    
    endelse

ed831104   Ilyes Choubani   no obj plotting
580
    
9aceb888   Ilyes Choubani   Updating the non-...
581
    plotsym,0,/fill ; what's the reason behind this?
ed831104   Ilyes Choubani   no obj plotting
582

9aceb888   Ilyes Choubani   Updating the non-...
583
584
585
    if !run_pol and tag_exist(*!dustem_show,'qext') then begin
        ;This part can be adjusted for future releases if the user wants to plot 
        ;specific datasets 
ed831104   Ilyes Choubani   no obj plotting
586
        
9aceb888   Ilyes Choubani   Updating the non-...
587
588
589
590
591
592
        ;lists because elements have different dimensions and/or we want entire arrays as elements
        dustem_interp = list(dustem_ext,dustem_fpolext,dustem_qext,dustem_uext,dustem_psi_ext,dustem_polext) ;DustEmWrap SED predictions
        dustem_spec = list(EXT_spec,SPEXT_spec,QEXT_spec,UEXT_spec,PSIEXT_spec,POLEXT_spec) ;DustEM spectra predictions
        extra_spec = list(0,EXT_spec,0,0,0,0) ;extra spectra that the dataset needs in order to be plotted. 
        ;This (extra_spec use) actually should not be generalized since the only case we need an extra spectrum is when plotting the polarization fraction.
        position = list(list(p_ext,np_ext),list(p_spext),list(p_qext,np_qext),list(p_uext,np_uext),list(p_psiext),list(p_pext,np_pext))
55275be6   Ilyes Choubani   allowing no_obj p...
593
        
9aceb888   Ilyes Choubani   Updating the non-...
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
        ;these don't have to be lists
        datasets = ['EXT','FPOLEXT','QEXT','UEXT','PSI_EXT','POLEXT']
        ;but these can be combined using a list but we're leaving it as is for the moment...
        positiveonly = [0,0,1,1,0,0] ;used for q and u
        negativeonly = [0,0,1,1,0,0] ;used for q and u
    ENDIF ELSE BEGIN
    
        dustem_interp = list(dustem_ext) ;DustEmWrap EXT predictions . 
        dustem_spec = list(EXT_spec) ;DustEM spectra predictions
        position = list(p_ext,np_ext);list(list(p_sed,np_sed)) ; I think I need this ...
        ;position_n =list(np_sed) 
        datasets = ['EXT']
        ;replace by one keyword?
        positiveonly=[0] ;kept it for completeness. Also this loop reminds me that JP also wants the user to be able to display one dataset. 
        negativeonly=[0]
    ENDELSE
ed831104   Ilyes Choubani   no obj plotting
610
      
9aceb888   Ilyes Choubani   Updating the non-...
611
612
613
614
615
    ; PLOTTING OF DATA THAT IS UNCHAED 
    dustem_plot_dataset, st, dataset=datasets, position=position,positive_only=positiveonly,negative_only=negativeonly, _extra=_extra
    
    ; REFRESHING DATA - to plot the refreshed data for the first time.
    dustem_plot_dataset, st, dustem_interp,dustem_spec,extra_spec=extra_spec,dataset=datasets,positive_only=positiveonly,negative_only=negativeonly, /refresh ,position=position, _extra=_extra
ed831104   Ilyes Choubani   no obj plotting
616
617
618
619
          
ENDIF 


3d0f6b67   Ilyes Choubani   rest of plotting ...
620
621
if !dustem_end then !dustem_end = -1 ;so that the last iteration is only plotted once.

55275be6   Ilyes Choubani   allowing no_obj p...
622
;PLOTTING OF THE PARAMETERS
9aceb888   Ilyes Choubani   Updating the non-...
623
624

IF !d.name NE 'PS' THEN BEGIN ;What happens when we want to create a ps file of the exact content of the parameters' window?
134c5e51   Jean-Philippe Bernard   modfied to be abl...
625
626
    window,2,xpos=param_wxpos,ypos=param_wypos,xsize=param_wxsize,ysize=param_wysize,title='DUSTEMWRAP '+!dustem_version.version+' (PARAMETERS)' ; keeping the same y dimension of the emission/extinction plot? 
ENDIF
9aceb888   Ilyes Choubani   Updating the non-...
627
628
629

dustem_plot_dataset, st, p_dim, errors,dataset=['PARAMETERS'],_extra=_extra 
dustem_plot_dataset, st,  p_dim,errors,dataset=['PARAMETERS'],/refresh, _extra=_extra 
ed831104   Ilyes Choubani   no obj plotting
630

55275be6   Ilyes Choubani   allowing no_obj p...
631
;PLOTTING OF THE PLUGINS
ed831104   Ilyes Choubani   no obj plotting
632
IF (tag_names(*!dustem_plugin))(0) NE 'NONE' THEN BEGIN  
134c5e51   Jean-Philippe Bernard   modfied to be abl...
633
634
635
    IF !d.name NE 'PS' THEN BEGIN
        window,3,xpos=plugin_wxpos,ypos=plugin_wypos,xsize=plugin_wxsize,ysize=plugin_wysize,title='DUSTEMWRAP '+!dustem_version.version+' (PLUGINS)' ; keeping the same y dimension of the emission/extinction plot? 
    ENDIF
9aceb888   Ilyes Choubani   Updating the non-...
636
637
    dustem_plot_dataset, st, p_dim, errors,dataset=['PLUGINS'],_extra=_extra ;& cmdind_prms+=1
    dustem_plot_dataset, st, p_dim, errors,dataset=['PLUGINS'], /refresh , winid=winid_plgns, _extra=_extra 
ed831104   Ilyes Choubani   no obj plotting
638
639
640
641
642
643
     
ENDIF

the_end:

END