Blame view

src/idl/dustemcgwin_dataset.pro 29.2 KB
b5314324   Ilyes Choubani   updating the plot...
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
29
30
31
32
PRO dustemcgwin_dataset, st, prediction, dataset=dataset, norm=norm, refresh=refresh, nodata=nodata, position=position, _extra=_extra

;######DRAFT HELP SECTION######

;dataset = string. IE: 'SED','POLSED','QSED' etc...
;prediction = array. IE: 'dustem_sed', 'dustem_polsed' ... (discrete dustemwrap model predictions)
;norm = boolean. To indicate that it is the normalized plot.
;refresh = boolen. To indicate that the commands are the be replaced. 

;#1-loop on the data set and find its index in !dustem_data/!dustem_show 

;#prediction will be used whith refresh. 

;#you need to know that the data set has been plotted once in order to replace the commands. That is why you need the command index

;first run requires to be known. 
;To do so I will use this system variable '!dustemcgwin_ncmds' that I will only set after the first run
;.sed.pl and .sed.nrm will tell about the number of commands for each kind of plot. 
;this will also interact with the refresh keyword. 

;except for when nodata is used, the 'prediction' array should always be present for errors not to occur.

;YOU NEED THE INFORMATION INSIDE THE _EXTRA STRUCTURE

;NB: this procedures uses both !dustem_data/!dustem_show to locate hidden filter/spectrum data points


;positions for xyouts on the plots - not using any widgets for now
;using same margins for (placement of xyouts plot titles (ie: I_nu, Q_nu, U_nu etc...)) normalized plots and normal ones.

;######LIST OF THINGS NEEDED#################################################################
;############################################################################################
c8368c6e   Ilyes Choubani   updating plotting...
33
if !run_pol then pospltxt = [position(0)+0.02,position(3)-0.02] else pospltxt = [position(0)+0.02,position(3)-0.05] ;hard-coded but we can find a way 
b5314324   Ilyes Choubani   updating the plot...
34
35
36
37
38
39
40
wavs=dustem_get_wavelengths()
n_plgns = n_tags(*!dustem_plugin)
Ngrains=(*!dustem_params).Ngrains
use_cols=dustem_grains_colors(Ngrains,/cgplot)
use_cols[1]='Cornflower'
fact = 1.e4*(*!dustem_HCD)/(4.*!pi)/(3.e8/1.e-6/st.sed.wav)*1.e20/1.e7 ; st.sed.wav and st.polsed.wav should remain the same
spec = st.sed.em_tot * fact
68598bce   Ilyes Choubani   reducing number o...
41

c8368c6e   Ilyes Choubani   updating plotting...
42
43
44
45
46
47
48
49
50
 if !run_pol then begin
 
 specpol = st.polsed.em_tot * fact
 spec[0:11] = 1.00e-40 ; I can't even test for nans because cgwin won't accept the presence of nans in this ratio.
 specpolfrac =  specpol/spec
 polar_ippsi2iqu,spec,specq,specu,specpolfrac,replicate(!dustem_psi,n_elements(spec)) ;(Q & U) were generated this way to save time. This sysv fixes my problem but still...
 
 endif
 
b5314324   Ilyes Choubani   updating the plot...
51
52
clrs_plgns = ['Rosy Brown','Gold','Light Coral','Slate Blue','Dark Khaki','Salmon','Dark Green'] ;FOR NOW
scopes=tag_names((*!dustem_scope))
c8368c6e   Ilyes Choubani   updating plotting...
53

b5314324   Ilyes Choubani   updating the plot...
54
55
56
IF scopes[0] NE 'NONE' THEN BEGIN
  FOR i=0L,n_tags(*!dustem_scope)-1 DO BEGIN
    IF total(strsplit((*(*!dustem_scope).(i)),'+',/extract) EQ 'ADD_SED') THEN spec+=(*(*!dustem_plugin).(i))[*,0]
68598bce   Ilyes Choubani   reducing number o...
57
58
59
60
61
62
63
64
65
66
67
68
69
    If !run_pol then begin
        IF total(strsplit((*(*!dustem_scope).(i)),'+',/extract) EQ 'REPLACE_POLSED') THEN begin
            specpol=sqrt(((*(*!dustem_plugin).(i))[*,1])^2+((*(*!dustem_plugin).(i))[*,2])^2)
            specq=(*(*!dustem_plugin).(i))[*,1]
            specu=(*(*!dustem_plugin).(i))[*,2]
        endif
        IF total(strsplit((*(*!dustem_scope).(i)),'+',/extract) EQ 'ADD_POLSED') THEN begin
            specpol+=sqrt(((*(*!dustem_plugin).(i))[*,1])^2+((*(*!dustem_plugin).(i))[*,2])^2)
            specq+=(*(*!dustem_plugin).(i))[*,1]
            specu+=(*(*!dustem_plugin).(i))[*,2]
        endif
    ENDIF  
  
b5314324   Ilyes Choubani   updating the plot...
70
  ENDFOR
68598bce   Ilyes Choubani   reducing number o...
71

b5314324   Ilyes Choubani   updating the plot...
72
73
74
75
76
77
ENDIF
tgnms_extra = tag_names(_extra)
ind_xr = where(strmid(tgnms_extra,0,2) eq 'XR')
ind_yr = where(strmid(tgnms_extra,0,2) eq 'YR')
if ind_xr EQ -1 then xr=[1.00E+00,1.00E+05] else xr=(_extra.(ind_xr))
if ind_yr EQ -1 then yr=[5.00E-03,1.00E+08] else yr=(_extra.(ind_yr))
c8368c6e   Ilyes Choubani   updating plotting...
78

b5314324   Ilyes Choubani   updating the plot...
79
80
81
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
107
108
109
110
111
112
113
114
115
116
117
;############################################################################################
;############################################################################################



;NB: because of small issue you forgot in the main code. Add xtit=xtit when convenient

if keyword_set(dataset) then begin
;!run_pol is implied for QSED/USED/POLSED etc...
    Case strupcase(dataset) of 
    
        'SED': begin
            
            idx_filt=where((*!dustem_data.sed).filt_names NE 'SPECTRUM',ct_filt)
            idx_spec=where((*!dustem_data.sed).filt_names EQ 'SPECTRUM',ct_spec)
            
            ;#1) get the plotting keywords (pertaining to each data set) @here when the _extra structure is ready
            
            if keyword_set(nodata) then begin ;when the data is not present
            
                if keyword_set(norm) then begin ;normalized plot
                    
                    xtit=textoidl('\lambda (\mum)')
                    if !run_pol then xtit = ''
                    cgplot,wavs,wavs/wavs,/xlog,/ys,xs=1,pos=position,noerase=1,xtickformat='(A1)',color='Black',xr=xr,xtit=xtit,yr=[0.0,2.0],yticks=2,ymino=2,xticklen=0.1,ytickformat='(F6.2)',charsize=1.0
                    xyouts,pospltxt[0],pospltxt[1],textoidl('norm'),color=0,/normal,charsize=1.1                        
                
                endif else begin ;normal plot
                    
                    cgplot,wavs,wavs,/nodata,/ylog,/xlog,/ys,xs=9,pos=position,noerase=1,charsize=1.15,xtickformat='(A1)',color='Powder Blue',xr=xr,xtit='',yr=yr,psym=8,syms=0.8  
                    cgaxis, xaxis=1 ,xlog=1 ,xrange=((!const.c*1E6/xr)*1E-9),charsize=1.15,title=textoidl('\nu (GHz)'),xticklen=0.05,xminor=10
                    xyouts,pospltxt[0],pospltxt[1],textoidl('I_{\nu} (MJy/sr)'),color=0,/normal,charsize=1.1
                  
                endelse  
                
            
            endif else begin ;when the data is present 
            
                if keyword_set(norm) then begin 
c8368c6e   Ilyes Choubani   updating plotting...
118
                    
b5314324   Ilyes Choubani   updating the plot...
119
120
                    if keyword_set(refresh) then begin ;The data points in the plot that are being refreshed 
                        
b5314324   Ilyes Choubani   updating the plot...
121
122
123
124
125
126
127
                        
                        IF ct_spec NE 0 THEN BEGIN
                            xx=((*!dustem_data.sed).wav)[idx_spec]
                            yy=prediction[idx_spec]
                            rms=3.*((*!dustem_data.sed).sigma)(idx_spec)/2.
                            cgoplot,xx,((*!dustem_data.sed).values)[idx_spec]/yy,color='Powder Blue',psym=16,syms=0.8,noerase=1,pos=position
                            cgerrplot,((*!dustem_data.sed).wav)(idx_spec),(((*!dustem_data.sed).values)[idx_spec]-rms)/yy,(((*!dustem_data.sed).values)[idx_spec]+rms)/yy,color='Powder Blue'
c8368c6e   Ilyes Choubani   updating plotting...
128
                        ENDIF
b5314324   Ilyes Choubani   updating the plot...
129
                        
c8368c6e   Ilyes Choubani   updating plotting...
130
131
132
133
134
135
136
137
138
139
140
                        
                        IF ct_filt NE 0 THEN BEGIN
                            xx=((*!dustem_data.sed).wav)[idx_filt]
                            yy=prediction[idx_filt]
                            rms=3.*((*!dustem_data.sed).sigma)(idx_filt)/2. 
                            cgoplot,xx,((*!dustem_data.sed).values)[idx_filt]/yy,psym=16,color='Dodger Blue',syms=0.8,noerase=1,pos=position
                            cgerrplot,((*!dustem_data.sed).wav)(idx_filt),(((*!dustem_data.sed).values)[idx_filt]-rms)/yy,(((*!dustem_data.sed).values)[idx_filt]+rms)/yy,color='Dodger Blue' 
                        ENDIF
                            
                        
                    endif else begin ;The data points in the plot that remain unchanged ; UNNECESSARY BLOCK but needede to limit erros when calls are made with missing keywords.
b5314324   Ilyes Choubani   updating the plot...
141
142
143
144
145
146
147
148
149
150
                        
                        xtit=textoidl('\lambda (\mum)')
                        if !run_pol then xtit = ''
                        cgplot,wavs,wavs/wavs,/xlog,/ys,xs=1,pos=position,noerase=1,xtickformat='(A1)',color='Black',xr=xr,xtit=xtit,yr=[0.0,2.0],yticks=2,ymino=2,xticklen=0.1,ytickformat='(F6.2)',charsize=1.0
                        xyouts,pospltxt[0],pospltxt[1],textoidl('norm'),color=0,/normal,charsize=1.1
                    
                    endelse
                    
                
                endif else begin ; normal plot
c8368c6e   Ilyes Choubani   updating plotting...
151
                        
b5314324   Ilyes Choubani   updating the plot...
152
153
                    if keyword_set(refresh) then begin ;The data points in the plot are being refreshed
                        
b5314324   Ilyes Choubani   updating the plot...
154
155
156
157
158
                        ;Plotting of the spectra of the dust species
                        FOR i=0L,Ngrains-1 DO BEGIN
                            cgoplot,st.sed.wav,st.sed.(i+1)*fact,color=use_cols[i],pos=position,noerase=1
                        ENDFOR
                        
c8368c6e   Ilyes Choubani   updating plotting...
159
                                                
b5314324   Ilyes Choubani   updating the plot...
160
161
                        ;Plotting of the plugins.
                        for i=0L,n_plgns-1 do begin
c8368c6e   Ilyes Choubani   updating plotting...
162
                            cgoplot,st.sed.wav,(*(*!dustem_plugin).(i)),color=clrs_plgns[i],pos=position,noerase=1,linestyle=2               
b5314324   Ilyes Choubani   updating the plot...
163
                        endfor
c8368c6e   Ilyes Choubani   updating plotting...
164
                                                
b5314324   Ilyes Choubani   updating the plot...
165
                        ;PLotting of the interpolates corresponding to spectrum and filter points
c8368c6e   Ilyes Choubani   updating plotting...
166
                           
b5314324   Ilyes Choubani   updating the plot...
167
168
169
170
171
172
173
                        IF ct_spec NE 0 THEN BEGIN
                        
                            xx=((*!dustem_data.sed).wav)[idx_spec]
                            yy=prediction[idx_spec]
                            cgoplot,xx,yy,color='red',pos=position,psym=7,syms=2,noerase=1   
                        ENDIF
                        
c8368c6e   Ilyes Choubani   updating plotting...
174
175
176
177
178
179
180
                        
                        IF ct_filt NE 0 THEN BEGIN
                            xx=((*!dustem_data.sed).wav)[idx_filt]
                            yy=prediction[idx_filt]
                            cgoplot,xx,yy,color='red',pos=position,psym=6,syms=2,noerase=1
                        ENDIF
                        
b5314324   Ilyes Choubani   updating the plot...
181
182
                        
                        
c8368c6e   Ilyes Choubani   updating plotting...
183
184
185
186
187
                        ;Plotting of the total dust emission spectrum
                        cgoplot,st.sed.wav,spec,pos=position,noerase=1,/xlog,/ys,/xs,/ylog
                         
                                        
                                
b5314324   Ilyes Choubani   updating the plot...
188
189
190
191
192
193
                    endif else begin ;The data points in the plot that remain unchanged.
                        
                        ;Spectrum points are treated before for plotting reasons. 
                        if ct_spec ne 0 then begin 
                            
                            ;Plotting of spectrum data points (to be fitted)
c8368c6e   Ilyes Choubani   updating plotting...
194
                            cgplot,((*!dustem_data.sed).wav)(idx_spec),((*!dustem_data.sed).values)(idx_spec),/ylog,/xlog,/ys,xs=9,pos=position,noerase=1,xtit=' ',charsize=1.15,xtickformat='(A1)',color='Powder Blue',xr=xr,yr=yr,psym=8,syms=0.8,ytickformat='dstmwrp_exp'                
b5314324   Ilyes Choubani   updating the plot...
195
196
197
198
199
200
201
202
                            
                            ;Plotting of the spectrum error points
                            rms=3.*((*!dustem_data.sed).sigma)(idx_spec)/2.
                            cgerrplot,((*!dustem_data.sed).wav)(idx_spec),((*!dustem_data.sed).values)(idx_spec)-rms,((*!dustem_data.sed).values)(idx_spec)+rms,color='Powder Blue'

                        endif
                        
                        if ct_filt ne 0 then begin
c8368c6e   Ilyes Choubani   updating plotting...
203
                        
b5314324   Ilyes Choubani   updating the plot...
204
205
                            ;Plotting of filter data points (to be fitted) + testing for prior plotting                         
                            if ct_spec ne 0 then cgoplot,((*!dustem_data.sed).wav)(idx_filt),((*!dustem_data.sed).values)(idx_filt),charsize=1.15,color='Dodger Blue',psym=8,syms=0.8,pos=position,/ys,xs=9,noerase=1,xtickformat='(A1)',xr=xr,yr=yr,ytickformat='dstmwrp_exp',/ylog,/xlog else $
c8368c6e   Ilyes Choubani   updating plotting...
206
207
                                cgplot,((*!dustem_data.sed).wav)(idx_filt),((*!dustem_data.sed).values)(idx_filt),charsize=1.15,color='Dodger Blue',psym=8,syms=0.8,pos=position,/ys,xs=9,noerase=1,xtickformat='(A1)',xtit=' ',xr=xr,yr=yr,ytickformat='dstmwrp_exp',/ylog,/xlog
                            
b5314324   Ilyes Choubani   updating the plot...
208
209
210
211
                            
                            ;Plotting of the filter error points
                            rms=3.*((*!dustem_data.sed).sigma)(idx_filt)/2.;/dustem_sed(idx_filt)
                            cgerrplot,((*!dustem_data.sed).wav)(idx_filt),((*!dustem_data.sed).values)(idx_filt)-rms,((*!dustem_data.sed).values)(idx_filt)+rms,color='Dodger Blue'
c8368c6e   Ilyes Choubani   updating plotting...
212
                            
b5314324   Ilyes Choubani   updating the plot...
213
                        endif
c8368c6e   Ilyes Choubani   updating plotting...
214
215
                        
                        
b5314324   Ilyes Choubani   updating the plot...
216
                        ;Plotting of frequency axis
c8368c6e   Ilyes Choubani   updating plotting...
217
218
                        cgaxis, xaxis=1, xlog=1, xs=1, xminor=10, xticklen=0.05, xrange=((!const.c*1E6/(_extra.(ind_xr)))*1E-9),charsize=1.15,title=textoidl('\nu (GHz)')
                        
b5314324   Ilyes Choubani   updating the plot...
219
                        xyouts,pospltxt[0],pospltxt[1],textoidl('I_{\nu} (MJy/sr)'),color=0,/normal,charsize=1.1
c8368c6e   Ilyes Choubani   updating plotting...
220
                         
b5314324   Ilyes Choubani   updating the plot...
221
222
223
                        ;Locating all the hidden data points (spectrum+filter)
                        match2,((*!dustem_data.sed).wav),((*!dustem_show.sed).wav),fit_sedpts,show_sedpts ;only show_sedpts is needed
                        idx_rmv_sed=where(show_sedpts eq -1, ct_hdnpts) ; indices of the points to hide
b5314324   Ilyes Choubani   updating the plot...
224
                        
c8368c6e   Ilyes Choubani   updating plotting...
225
226
                        if ct_hdnpts ne 0 then begin ;Hidden data points are present 
                            
b5314324   Ilyes Choubani   updating the plot...
227
228
229
230
231
232
233
234
235
236
237
238
                            ;Locating the hidden spectrum and filter data points                                        
                            idx_filt_hdn = where(((*!dustem_show.sed).filt_names)(idx_rmv_sed) NE 'SPECTRUM',ct_filt_hdn)
                            idx_spec_hdn = where(((*!dustem_show.sed).filt_names)(idx_rmv_sed) EQ 'SPECTRUM',ct_spec_hdn)
                            
                            ;Plotting of hidden spectrum data points
                            cgoplot,((*!dustem_show.sed).wav)(idx_spec_hdn),((*!dustem_show.sed).values)(idx_spec_hdn),pos=position,/ylog,/xlog,/ys,xs=9,noerase=1,charsize=1.15,xtickformat='(A1)',color='Black',xr=xr,yr=yr,psym=8,syms=0.8
                            
                            ;Plotting of hidden spectrum error points
                            rms=3.*((*!dustem_show.sed).sigma)(idx_spec_hdn)/2.
                            cgerrplot,((*!dustem_show.sed).wav)(idx_spec_hdn),((*!dustem_show.sed).values)(idx_spec_hdn)-rms,((*!dustem_show.sed).values)(idx_spec_hdn)+rms,color='Black'
                                                                        
                            ;Plotting of hidden filter data points 
c8368c6e   Ilyes Choubani   updating plotting...
239
                            cgoplot,((*!dustem_show.sed).wav)(idx_filt_hdn),((*!dustem_show.sed).values)(idx_filt_hdn),pos=position,/ylog,/xlog,/ys,xs=9,noerase=1,charsize=1.15,xtickformat='(A1)',color='Black',xr=xr,yr=yr,psym=8,syms=0.8                                           
b5314324   Ilyes Choubani   updating the plot...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
                            
                            ;Plotting of hidden filter error point
                            rms=3.*((*!dustem_show.sed).sigma)(idx_filt_hdn)/2.
                            cgerrplot,((*!dustem_show.sed).wav)(idx_filt_hdn),((*!dustem_show.sed).values)(idx_filt_hdn)-rms,((*!dustem_show.sed).values)(idx_filt_hdn)+rms,color='Black'
                                                           
                        endif    
                        
                        
                    
                    endelse 
                
                
                
                endelse 
            
c8368c6e   Ilyes Choubani   updating plotting...
255
            endelse 
b5314324   Ilyes Choubani   updating the plot...
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
            
        end
        
        'EXT': begin
        
        end
        
        'POLEXT': begin
        
        end
        
        'POLSED': begin
        
        end
        
        'POLFRAC': begin
        
        end
        
        'PSI_EM': begin
        
        end
        
        'PSI_EXT': begin
        
        end
        
bc224f3e   Ilyes Choubani   Update of plottin...
283
        'QSED': begin ; THE ONE I WILL BE WORKING ON
c8368c6e   Ilyes Choubani   updating plotting...
284
285
286
287
288
289
290
            
            ;SIGN-RELATED PARAMETERS/LOOPS HERE?
            ;negative & positive values regardless of data type (SPECTRUM or FILTER data points)
            varvar=where(specq LT 0, testsgq)
            idx_filt=where((*!dustem_data.qsed).filt_names NE 'SPECTRUM', ct_filt)
            idx_spec=where((*!dustem_data.qsed).filt_names EQ 'SPECTRUM' , ct_spec)
            
bc224f3e   Ilyes Choubani   Update of plottin...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
            
            ;#1) get the plotting keywords (pertaining to each data set) @here when the _extra structure is ready
            
            if keyword_set(nodata) then begin ;when the data is not present
            
                if keyword_set(norm) then begin ;normalized plot
                    
                    xtit=textoidl('\lambda (\mum)')
                    if !run_pol then xtit = ''
                    cgplot,wavs,wavs/wavs,/xlog,/ys,xs=1,pos=position,noerase=1,xtickformat='(A1)',color='Black',xr=xr,xtit=xtit,yr=[0.0,2.0],yticks=2,ymino=2,xticklen=0.1,ytickformat='(F6.2)',charsize=1.0
                    xyouts,pospltxt[0],pospltxt[1],textoidl('norm'),color=0,/normal,charsize=1.1                        
                
                endif else begin ;normal plot
                    
                    cgplot,wavs,wavs,/nodata,/ylog,/xlog,/ys,xs=9,pos=position,noerase=1,charsize=1.15,xtickformat='(A1)',color='Powder Blue',xr=xr,xtit='',yr=yr,psym=8,syms=0.8  
                    cgaxis, xaxis=1 ,xlog=1 ,xrange=((!const.c*1E6/xr)*1E-9),charsize=1.15,title=textoidl('\nu (GHz)'),xticklen=0.05,xminor=10
                    xyouts,pospltxt[0],pospltxt[1],textoidl('Q_{\nu} (MJy/sr)'),color=0,/normal,charsize=1.1
                  
                endelse  
                
            
            endif else begin ;when the data is present 
c8368c6e   Ilyes Choubani   updating plotting...
313
                ;NOTA BENE: DIVDE THE POSITIONS BY A FACTOR :'(
bc224f3e   Ilyes Choubani   Update of plottin...
314
                if keyword_set(norm) then begin 
c8368c6e   Ilyes Choubani   updating plotting...
315
                    
bc224f3e   Ilyes Choubani   Update of plottin...
316
317
                    if keyword_set(refresh) then begin ;The data points in the plot that are being refreshed 
                        
c8368c6e   Ilyes Choubani   updating plotting...
318
319
                        ;MAJOR LOOP OVER THE SING??? - YES BECAUSE YOU NEED TO KNOW WHICH ONE IS THE 
                
bc224f3e   Ilyes Choubani   Update of plottin...
320
321
322
323
                        IF ct_filt NE 0 THEN BEGIN
                            xx=((*!dustem_data.qsed).wav)[idx_filt]
                            yy=prediction[idx_filt]
                            rms=3.*((*!dustem_data.qsed).sigma)(idx_filt)/2. 
c8368c6e   Ilyes Choubani   updating plotting...
324
325
                            if testsgq ne 0 then dustem_plot_mlog,xx,((*!dustem_data.qsed).values)(idx_filt),ppositions=position,((*!dustem_data.qsed).values)[idx_filt]/yy,psym=16,color='Dodger Blue',syms=0.8,noerase=1,/negative_only,/overplot else $
                                dustem_plot_mlog,xx,((*!dustem_data.qsed).values)(idx_filt),ppositions=position,((*!dustem_data.qsed).values)[idx_filt]/yy,psym=16,color='Dodger Blue',syms=0.8,noerase=1,/positive_only,/overplot
bc224f3e   Ilyes Choubani   Update of plottin...
326
327
                            cgerrplot,((*!dustem_data.qsed).wav)(idx_filt),(((*!dustem_data.qsed).values)[idx_filt]-rms)/yy,(((*!dustem_data.qsed).values)[idx_filt]+rms)/yy,color='Dodger Blue' 
                        ENDIF
c8368c6e   Ilyes Choubani   updating plotting...
328
      
bc224f3e   Ilyes Choubani   Update of plottin...
329
330
331
332
333
                        
                        IF ct_spec NE 0 THEN BEGIN
                            xx=((*!dustem_data.qsed).wav)[idx_spec]
                            yy=prediction[idx_spec]
                            rms=3.*((*!dustem_data.qsed).sigma)(idx_spec)/2.
c8368c6e   Ilyes Choubani   updating plotting...
334
335
                            if testsgq ne 0 then dustem_plot_mlog,xx,((*!dustem_data.qsed).values)(idx_spec),ppositions=position,((*!dustem_data.qsed).values)[idx_spec]/yy,psym=16,color='Powder Blue',syms=0.8,noerase=1,/negative_only,/overplot else $
                                dustem_plot_mlog,xx,((*!dustem_data.qsed).values)(idx_spec),ppositions=position,((*!dustem_data.qsed).values)[idx_spec]/yy,psym=16,color='Powder Blue',syms=0.8,noerase=1,/positive_only,/overplot
bc224f3e   Ilyes Choubani   Update of plottin...
336
                            cgerrplot,((*!dustem_data.qsed).wav)(idx_spec),(((*!dustem_data.qsed).values)[idx_spec]-rms)/yy,(((*!dustem_data.qsed).values)[idx_spec]+rms)/yy,color='Powder Blue'
c8368c6e   Ilyes Choubani   updating plotting...
337
338
                        
                        ENDIF 
bc224f3e   Ilyes Choubani   Update of plottin...
339
340
341
342
343
344
345
346
347
348
349
350
                        
                    endif else begin ;The data points in the plot that remain unchanged
                        
                        xtit=textoidl('\lambda (\mum)')
                        if !run_pol then xtit = ''
                        cgplot,wavs,wavs/wavs,/xlog,/ys,xs=1,pos=position,noerase=1,xtickformat='(A1)',color='Black',xr=xr,xtit=xtit,yr=[0.0,2.0],yticks=2,ymino=2,xticklen=0.1,ytickformat='(F6.2)',charsize=1.0
                        xyouts,pospltxt[0],pospltxt[1],textoidl('norm'),color=0,/normal,charsize=1.1
                    
                    endelse
                    
                
                endif else begin ; normal plot - STOPPED HERE FOR QSED
c8368c6e   Ilyes Choubani   updating plotting...
351
                              
bc224f3e   Ilyes Choubani   Update of plottin...
352
353
354
355
                    if keyword_set(refresh) then begin ;The data points in the plot are being refreshed
                        
                        ;Plotting of the spectra of the dust species
                        FOR i=0L,Ngrains-1 DO BEGIN
c8368c6e   Ilyes Choubani   updating plotting...
356
357
358
                            polar_ippsi2iqu,st.sed.(i+1)*fact,specqgrain,specugrain,st.polsed.(i+1)*fact/spec,replicate(!dustem_psi,n_elements(spec)) ;temporary solution
                            if testsgq ne 0 then dustem_plot_mlog,st.polsed.wav,specqgrain,ppositions=position,/negative_only,/overplot,noerase=1,color=use_cols[i] else $
                                dustem_plot_mlog,st.polsed.wav,specqgrain,ppositions=position,/positive_only,/overplot,noerase=1,color=use_cols[i]
bc224f3e   Ilyes Choubani   Update of plottin...
359
360
361
362
                        ENDFOR
                        
                        ;Plotting of the plugins.
                        for i=0L,n_plgns-1 do begin
c8368c6e   Ilyes Choubani   updating plotting...
363
364
                            if testsgq ne 0 then dustem_plot_mlog,st.polsed.wav,(*(*!dustem_plugin).(i))[*,1],ppositions=position,/negative_only, /overplot, noerase=1, color=clrs_plgns[i], linestyle=2 else $
                                dustem_plot_mlog,st.polsed.wav,(*(*!dustem_plugin).(i))[*,1],ppositions=position,/positive_only, /overplot, noerase=1, color=clrs_plgns[i], linestyle=2         
bc224f3e   Ilyes Choubani   Update of plottin...
365
366
367
368
                        endfor
                        
                        ;PLotting of the interpolates corresponding to spectrum and filter points
                        IF ct_filt NE 0 THEN BEGIN
c8368c6e   Ilyes Choubani   updating plotting...
369
                            xx=((*!dustem_data.qsed).wav)[idx_filt]
bc224f3e   Ilyes Choubani   Update of plottin...
370
                            yy=prediction[idx_filt]
c8368c6e   Ilyes Choubani   updating plotting...
371
372
373
                            if testsgq ne 0 then dustem_plot_mlog,xx,yy,ppositions=position,/negative_only, /overplot, noerase=1, color='red',psym=6,syms=2 else $
                                dustem_plot_mlog,xx,yy,ppositions=position,/positive_only, /overplot, noerase=1, color='red',psym=6,syms=2
                            
bc224f3e   Ilyes Choubani   Update of plottin...
374
375
376
377
                        ENDIF
        
                        IF ct_spec NE 0 THEN BEGIN
                        
c8368c6e   Ilyes Choubani   updating plotting...
378
                            xx=((*!dustem_data.qsed).wav)[idx_spec]
bc224f3e   Ilyes Choubani   Update of plottin...
379
                            yy=prediction[idx_spec]
c8368c6e   Ilyes Choubani   updating plotting...
380
381
                            if testsgq ne 0 then dustem_plot_mlog,xx,yy,ppositions=position,/negative_only, /overplot, noerase=1, color='red',psym=7,syms=2 else $
                                dustem_plot_mlog,xx,yy,ppositions=position,/positive_only, /overplot, noerase=1, color='red',psym=7,syms=2   
bc224f3e   Ilyes Choubani   Update of plottin...
382
383
384
                        ENDIF
                        
                        ;Plotting of the total dust emission spectrum
c8368c6e   Ilyes Choubani   updating plotting...
385
386
387
                        if testsgq ne 0 then dustem_plot_mlog,st.polsed.wav,specq,ppositions=position,/negative_only, /overplot, noerase=1 else $
                            dustem_plot_mlog,st.polsed.wav,specq,ppositions=position,/positive_only, /overplot, noerase=1
                        
bc224f3e   Ilyes Choubani   Update of plottin...
388
389
390
391
392
393
394
395
                        
                        
                    endif else begin ;The data points in the plot that remain unchanged.
                        
                        ;Spectrum points are treated before for plotting reasons. 
                        if ct_spec ne 0 then begin 
                            
                            ;Plotting of spectrum data points (to be fitted)
c8368c6e   Ilyes Choubani   updating plotting...
396
397
398
                            if testsgq ne 0 then  dustem_plot_mlog,((*!dustem_data.qsed).wav)(idx_spec),((*!dustem_data.qsed).values)(idx_spec),ppositions=position,/negative_only, noerase=1,xtit='',charsize=1.15,xtickformat='(A1)',color='Powder Blue',/ys,xs=9,psym=8,syms=0.8 else $
                                  dustem_plot_mlog,((*!dustem_data.qsed).wav)(idx_spec),((*!dustem_data.qsed).values)(idx_spec),ppositions=position,/positive_only, noerase=1,xtit='',charsize=1.15,xtickformat='(A1)',color='Powder Blue',/ys,xs=9,psym=8,syms=0.8
                         
bc224f3e   Ilyes Choubani   Update of plottin...
399
                            ;Plotting of the spectrum error points
c8368c6e   Ilyes Choubani   updating plotting...
400
401
                            rms=3.*((*!dustem_data.qsed).sigma)(idx_spec)/2.
                            cgerrplot,((*!dustem_data.qsed).wav)(idx_spec),((*!dustem_data.qsed).values)(idx_spec)-rms,((*!dustem_data.qsed).values)(idx_spec)+rms,color='Powder Blue'
bc224f3e   Ilyes Choubani   Update of plottin...
402
403
404
405
406

                        endif
                        
                        if ct_filt ne 0 then begin
                            ;Plotting of filter data points (to be fitted) + testing for prior plotting                         
c8368c6e   Ilyes Choubani   updating plotting...
407
408
409
410
411
412
413
414
415
416
                            if ct_spec ne 0 then begin
                            
                            if testsgq ne 0 then dustem_plot_mlog,((*!dustem_data.qsed).wav)(idx_filt),((*!dustem_data.qsed).values)(idx_filt),ppositions=position,charsize=1.15,color='Dodger Blue',psym=8,syms=0.8,pos=position,/ys,xs=9, /overplot, /negative_only else $
                                dustem_plot_mlog,((*!dustem_data.qsed).wav)(idx_filt),((*!dustem_data.qsed).values)(idx_filt),ppositions=position,charsize=1.15,color='Dodger Blue',psym=8,syms=0.8,pos=position,/ys,xs=9, /overplot, /positive_only
                            endif else begin
                            
                            cgoplot,,,charsize=1.15,color='Dodger Blue',psym=8,syms=0.8,pos=position,/ys,xs=9,noerase=1,xtickformat='(A1)',xr=xr,yr=yr,ytickformat='dstmwrp_exp',/ylog,/xlog else $
                            
                            endelse 
                                cgplot,((*!dustem_data.qsed).wav)(idx_filt),((*!dustem_data.qsed).values)(idx_filt),charsize=1.15,color='Dodger Blue',psym=8,syms=0.8,pos=position,/ys,xs=9,noerase=1,xtickformat='(A1)',xtit='',xr=xr,yr=yr,ytickformat='dstmwrp_exp',/ylog,/xlog
bc224f3e   Ilyes Choubani   Update of plottin...
417
418
                            
                            ;Plotting of the filter error points
c8368c6e   Ilyes Choubani   updating plotting...
419
420
                            rms=3.*((*!dustem_data.qsed).sigma)(idx_filt)/2.;/dustem_sed(idx_filt)
                            cgerrplot,((*!dustem_data.qsed).wav)(idx_filt),((*!dustem_data.qsed).values)(idx_filt)-rms,((*!dustem_data.qsed).values)(idx_filt)+rms,color='Dodger Blue'
bc224f3e   Ilyes Choubani   Update of plottin...
421
422
423
424
425
426
427
                        
                        endif
                        ;Plotting of frequency axis
                        cgaxis, xaxis=1, xlog=1, xs=1, xminor=10, xticklen=0.05, xrange=((!const.c*1E6/(_extra.(ind_xr)))*1E-9),charsize=1.15,title=textoidl('\nu (GHz)') 
                        xyouts,pospltxt[0],pospltxt[1],textoidl('I_{\nu} (MJy/sr)'),color=0,/normal,charsize=1.1
                        ;stop
                        ;Locating all the hidden data points (spectrum+filter)
c8368c6e   Ilyes Choubani   updating plotting...
428
                        match2,((*!dustem_data.qsed).wav),((*!dustem_show.qsed).wav),fit_sedpts,show_sedpts ;only show_sedpts is needed
bc224f3e   Ilyes Choubani   Update of plottin...
429
                        idx_rmv_sed=where(show_sedpts eq -1, ct_hdnpts) ; indices of the points to hide
c8368c6e   Ilyes Choubani   updating plotting...
430
                          
bc224f3e   Ilyes Choubani   Update of plottin...
431
432
433
                        if ct_hdnpts ne 0 then begin ;Hidden data points are present 
                        
                            ;Locating the hidden spectrum and filter data points                                        
c8368c6e   Ilyes Choubani   updating plotting...
434
435
                            idx_filt_hdn = where(((*!dustem_show.qsed).filt_names)(idx_rmv_sed) NE 'SPECTRUM',ct_filt_hdn)
                            idx_spec_hdn = where(((*!dustem_show.qsed).filt_names)(idx_rmv_sed) EQ 'SPECTRUM',ct_spec_hdn)
bc224f3e   Ilyes Choubani   Update of plottin...
436
437
                            
                            ;Plotting of hidden spectrum data points
c8368c6e   Ilyes Choubani   updating plotting...
438
                            cgoplot,((*!dustem_show.qsed).wav)(idx_spec_hdn),((*!dustem_show.qsed).values)(idx_spec_hdn),pos=position,/ylog,/xlog,/ys,xs=9,noerase=1,charsize=1.15,xtickformat='(A1)',color='Black',xr=xr,yr=yr,psym=8,syms=0.8
bc224f3e   Ilyes Choubani   Update of plottin...
439
440
                            
                            ;Plotting of hidden spectrum error points
c8368c6e   Ilyes Choubani   updating plotting...
441
442
                            rms=3.*((*!dustem_show.qsed).sigma)(idx_spec_hdn)/2.
                            cgerrplot,((*!dustem_show.qsed).wav)(idx_spec_hdn),((*!dustem_show.qsed).values)(idx_spec_hdn)-rms,((*!dustem_show.qsed).values)(idx_spec_hdn)+rms,color='Black'
bc224f3e   Ilyes Choubani   Update of plottin...
443
444
                                                                        
                            ;Plotting of hidden filter data points 
c8368c6e   Ilyes Choubani   updating plotting...
445
                            cgoplot,((*!dustem_show.qsed).wav)(idx_filt_hdn),((*!dustem_show.qsed).values)(idx_filt_hdn),pos=position,/ylog,/xlog,/ys,xs=9,noerase=1,charsize=1.15,xtickformat='(A1)',color='Black',xr=xr,yr=yr,psym=8,syms=0.8                                           
bc224f3e   Ilyes Choubani   Update of plottin...
446
447
                            
                            ;Plotting of hidden filter error point
c8368c6e   Ilyes Choubani   updating plotting...
448
449
450
                            rms=3.*((*!dustem_show.qsed).sigma)(idx_filt_hdn)/2.
                            cgerrplot,((*!dustem_show.qsed).wav)(idx_filt_hdn),((*!dustem_show.qsed).values)(idx_filt_hdn)-rms,((*!dustem_show.qsed).values)(idx_filt_hdn)+rms,color='Black'
                                                            
bc224f3e   Ilyes Choubani   Update of plottin...
451
452
453
454
455
456
457
458
459
460
461
                        endif    
                        
                        
                    
                    endelse 
                
                
                
                endelse 
            
            endelse ;
b5314324   Ilyes Choubani   updating the plot...
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
        
        end
        
        'USED': begin
        
        end
        
        'QEXT': begin
        
        end
        
        'UEXT': begin
        
        end
    
    endcase


endif











 


 
  












END