[ncl-talk] Setting missing value in table plot

Giorgio Graffino g.graffino at tim.it
Tue Mar 23 10:34:12 MDT 2021


Nevermind, I managed to find a good workaround with a bit of DIY on the original get_color_index and get_color_rgba functions. Now the plot is exactly as I wanted. 
Giorgio  




  ----Messaggio originale---- 
 
 Da: ncl-talk at mailman.ucar.edu 
 
 Data: 21-mar-2021 17.37 
 
 A: <asphilli at ucar.edu> 
 
 Cc: "Ncl-talk"<ncl-talk at ucar.edu> 
 
 Ogg: Re: [ncl-talk] Setting missing value in table plot 
 

 

 
   Hi Adam, 
 
 
  

 
 
   Thanks for the suggestion. I had to work around it a bit, but now it works: 
 
 
  

 
 
     colors           = reshape(get_color_rgba(cmap,levels,data),(/product(dimsizes(data)),4/)) 
  
do i = 0, dimsizes(colors(:,0))-1 
  
print(colors(i,0)) 
  
if (ismissing(colors(i,0))) then 
  
  colors(i,:)      = (/190.,190.,190.,190./)/255.   ; set to Grey with a value of opacity different than 0 and 1 (see 
  https://www.ncl.ucar.edu/Document/glossary.shtml#RGBA)
  
end if 
  
end do   
  
  gnres at gsColors   = colors 
  

 
 
  

 
 
   I have another problem now, but maybe it's an issue of the functions themselves. Some values are set to missing, even if they have non-missing values (see attached). I'm still getting those warnings too. What do you people think? 
 
 
  

 
 
   Cheers, 
 
 
   Giorgio 
  

  
 
 

 
   ----Messaggio originale---- 
  
 Da: asphilli at ucar.edu 
  
 Data: 19-mar-2021 23.37 
  
 A: "Giorgio Graffino"<g.graffino at tim.it> 
  
 Cc: "Ncl-talk"<ncl-talk at ucar.edu> 
  
 Ogg: Re: [ncl-talk] Setting missing value in table plot 
  

  

  
    Hi Giorgio, 
   
     I do not have a feel for what the call to get_color_rgba returns in terms of the dimension of the array. But you could check the output of the call for missing values, and if present, set the color explicitly. 
    

    
      You could do something like this: 
    
    
      temp = reshape(get_color_rgba(cmap,levels,data),(/product(dimsizes(data)),4/)) 
     

    
    
      ; use ind to check for missing values, and replace with a set of rgb values 
    
    
      w_ind = ind(ismissing(temp(0,:)) 
    
    
      temp(:,w_ind) = (/0.5,0.5,0.5,0.5/)   ; set to gray50 
    
    
     

    
    
      gnres at gsColors  = temp 
     

    
    
     

    
    
      The above may not work as coded, but you should be able to apply the idea after some trial and error. 
    
    
      If you have any further issues please respond to the ncl-talk email.  
    
    
      Good luck, 
    
    
      Adam 
    
    
     

    
   
  
  

  
   
     On Thu, Mar 18, 2021 at 11:55 AM Giorgio Graffino via ncl-talk < 
    ncl-talk at mailman.ucar.edu> wrote: 
    

   
   
    
      Dear NCLers, 
    
    
     

    
    
      I'm using NCL 6.6.2 on a Linux cluster. I'm adapting this script ( 
     https://www.ncl.ucar.edu/Applications/Scripts/table_8.ncl) to obtain something like the attached figure. It looks fine, but some of the white triangles are missing values while some aren't. I'm also getting these warnings: 
    
    
     

    
    
     (0)     get_color_index: Error: More or more input values are missing. 
(0)         Returning missing. 
(0)     get_color_rgba: error: invalid input values. Returning missing.


    
    
      The relevant function for drawing the plot is the following: 
    
    
     undef("add_filled_triangles")
procedure add_filled_triangles(wks,plot,data,levels,cmap,location)
local dims, gnres, nc, nr, nrow, ncol, xtri, ytri, xtri2d, ytri2d, irows, icols
begin
  dims = dimsizes(data)
  nrow = dims(0)
  ncol = dims(1)
  ytri2d = new((/nrow,4/),float)
  xtri2d = new((/ncol,4/),float)

  irows = ispan(0,nrow-1,1)
  icols = ispan(0,ncol-1,1)
  if(location.eq."bot") then
    xtri2d(:,0) = icols
    xtri2d(:,1) = icols+1.0
    xtri2d(:,2) = icols+0.5
    xtri2d(:,3) = icols
    ytri2d(:,0) = irows
    ytri2d(:,1) = irows
    ytri2d(:,2) = irows+0.5
    ytri2d(:,3) = irows
  else if(location.eq."top") then
    xtri2d(:,0) = icols
    xtri2d(:,1) = icols+1.0
    xtri2d(:,2) = icols+0.5
    xtri2d(:,3) = icols
    ytri2d(:,0) = irows+1
    ytri2d(:,1) = irows+1
    ytri2d(:,2) = irows+0.5
    ytri2d(:,3) = irows+1
  else if(location.eq."lft") then
    xtri2d(:,0) = icols
    xtri2d(:,1) = icols
    xtri2d(:,2) = icols+0.5
    xtri2d(:,3) = icols
    ytri2d(:,0) = irows
    ytri2d(:,1) = irows+1.0
    ytri2d(:,2) = irows+0.5
    ytri2d(:,3) = irows
  else
    xtri2d(:,0) = icols+1
    xtri2d(:,1) = icols+1
    xtri2d(:,2) = icols+0.5
    xtri2d(:,3) = icols+1
    ytri2d(:,0) = irows
    ytri2d(:,1) = irows+1
    ytri2d(:,2) = irows+0.5
    ytri2d(:,3) = irows
  end if
  end if
  end if
  xtri = conform_dims((/nrow,ncol,4/),xtri2d,(/1,2/))
  ytri = conform_dims((/nrow,ncol,4/),ytri2d,(/0,2/))

  gnres            = True                     ; resource list for filled polygons
  gnres at gsEdgesOn  = True                     ; outline each filled triangle
  gnres at gsSegments = ispan(0,nrow*ncol*4,4)   ; this makes code faster

;--If you have NCL V6.4.0 or older, you must use the "_mod" version of the function
; gnres at gsColors   = reshape(get_color_rgba_mod(cmap,levels,data),(/product(dimsizes(data)),4/))

;---This will only work in NCL V6.5.0 or later.
  gnres at gsColors   = reshape(get_color_rgba(cmap,levels,data),(/product(dimsizes(data)),4/))

  tmpstr = unique_string(location)
  plot@$tmpstr$ = gsn_add_polygon(wks,plot,ndtooned(xtri),ndtooned(ytri),gnres)
end
     I tried including a resource like gnres at gsFillBackgroundColor = "Grey" to change the background color, but nothing changed. Do you know how I can set a specific color (different than white or transparent) for missing values in that function?
     Thanks a lot,
     Giorgio
    _______________________________________________ 
    
 ncl-talk mailing list 
    

    ncl-talk at mailman.ucar.edu
    
 List instructions, subscriber options, unsubscribe: 
    

    https://mailman.ucar.edu/mailman/listinfo/ncl-talk
   
  
  
  
   

  -- 
  

  
   
    
     
      
       
        
         
          
           
            
             Adam Phillips 

            
            Associate Scientist,  
            Climate and Global Dynamics Laboratory, NCAR

           
          
          
           www.cgd.ucar.edu/staff/asphilli/   
           303-497-1726 
          
          
          
           
            

            
             
            
           
          
         
        
       
      
     
    
   
  
  

 
 

 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210323/9aee2172/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HadCM3_plot_maps_cor.000007.png
Type: image/png
Size: 83497 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210323/9aee2172/attachment.png>


More information about the ncl-talk mailing list