dustemcgwin_dataset.pro 29.2 KB
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 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 248 249 250 251 252 253 254 255 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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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
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#################################################################
;############################################################################################
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 
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

 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
 
clrs_plgns = ['Rosy Brown','Gold','Light Coral','Slate Blue','Dark Khaki','Salmon','Dark Green'] ;FOR NOW
scopes=tag_names((*!dustem_scope))

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]
    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  
  
  ENDFOR

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))

;############################################################################################
;############################################################################################



;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 
                    
                    if keyword_set(refresh) then begin ;The data points in the plot that are being refreshed 
                        
                        
                        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'
                        ENDIF
                        
                        
                        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.
                        
                        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
                        
                    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
                            cgoplot,st.sed.wav,st.sed.(i+1)*fact,color=use_cols[i],pos=position,noerase=1
                        ENDFOR
                        
                                                
                        ;Plotting of the plugins.
                        for i=0L,n_plgns-1 do begin
                            cgoplot,st.sed.wav,(*(*!dustem_plugin).(i)),color=clrs_plgns[i],pos=position,noerase=1,linestyle=2               
                        endfor
                                                
                        ;PLotting of the interpolates corresponding to spectrum and filter points
                           
                        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
                        
                        
                        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
                        
                        
                        
                        ;Plotting of the total dust emission spectrum
                        cgoplot,st.sed.wav,spec,pos=position,noerase=1,/xlog,/ys,/xs,/ylog
                         
                                        
                                
                    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)
                            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'                
                            
                            ;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
                        
                            ;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 $
                                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
                            
                            
                            ;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'
                            
                        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
                         
                        ;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
                        
                        if ct_hdnpts ne 0 then begin ;Hidden data points are present 
                            
                            ;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 
                            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                                           
                            
                            ;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 
            
            endelse 
            
        end
        
        'EXT': begin
        
        end
        
        'POLEXT': begin
        
        end
        
        'POLSED': begin
        
        end
        
        'POLFRAC': begin
        
        end
        
        'PSI_EM': begin
        
        end
        
        'PSI_EXT': begin
        
        end
        
        'QSED': begin ; THE ONE I WILL BE WORKING ON
            
            ;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)
            
            
            ;#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 
                ;NOTA BENE: DIVDE THE POSITIONS BY A FACTOR :'(
                if keyword_set(norm) then begin 
                    
                    if keyword_set(refresh) then begin ;The data points in the plot that are being refreshed 
                        
                        ;MAJOR LOOP OVER THE SING??? - YES BECAUSE YOU NEED TO KNOW WHICH ONE IS THE 
                
                        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. 
                            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
                            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
      
                        
                        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.
                            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
                            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'
                        
                        ENDIF 
                        
                    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
                              
                    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
                            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]
                        ENDFOR
                        
                        ;Plotting of the plugins.
                        for i=0L,n_plgns-1 do begin
                            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         
                        endfor
                        
                        ;PLotting of the interpolates corresponding to spectrum and filter points
                        IF ct_filt NE 0 THEN BEGIN
                            xx=((*!dustem_data.qsed).wav)[idx_filt]
                            yy=prediction[idx_filt]
                            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
                            
                        ENDIF
        
                        IF ct_spec NE 0 THEN BEGIN
                        
                            xx=((*!dustem_data.qsed).wav)[idx_spec]
                            yy=prediction[idx_spec]
                            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   
                        ENDIF
                        
                        ;Plotting of the total dust emission spectrum
                        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
                        
                        
                        
                    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)
                            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
                         
                            ;Plotting of the spectrum error points
                            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'

                        endif
                        
                        if ct_filt ne 0 then begin
                            ;Plotting of filter data points (to be fitted) + testing for prior plotting                         
                            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
                            
                            ;Plotting of the filter error points
                            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'
                        
                        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)
                        match2,((*!dustem_data.qsed).wav),((*!dustem_show.qsed).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
                          
                        if ct_hdnpts ne 0 then begin ;Hidden data points are present 
                        
                            ;Locating the hidden spectrum and filter data points                                        
                            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)
                            
                            ;Plotting of hidden spectrum data points
                            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
                            
                            ;Plotting of hidden spectrum error points
                            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'
                                                                        
                            ;Plotting of hidden filter data points 
                            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                                           
                            
                            ;Plotting of hidden filter error point
                            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'
                                                            
                        endif    
                        
                        
                    
                    endelse 
                
                
                
                endelse 
            
            endelse ;
        
        end
        
        'USED': begin
        
        end
        
        'QEXT': begin
        
        end
        
        'UEXT': begin
        
        end
    
    endcase


endif











 


 
  












END