[pyngl-talk] plot masked array on irregular grids

Xiaoni Wang xiaoni.wang at obspm.fr
Tue Oct 25 08:02:22 MDT 2016


Hi Mary,
     Sorry to bother you with another question about masked array.
 
    1) I am also looking at some other data in the globe (swath data on irregular grids). The original data was in netcdf format and I imported them by using netcdf4. They are masked array with filled value -32768. Then I do further selection by choosing only data over ocean. Then I  plot out the 2D figure for ocean data. The python code ran without error, but I got nothing on my figure, except the map and grids ! 
     If I type tbwater on python terminal, it shows:
Out[2]:
masked_array(data = [135.11 135.11 137.95 ..., 137.56 138.49 132.27],
             mask = [False False False ..., False False False],
            fill_value = -32768)


I do not understand. The part of code is shown below.

    2) Similarly , I can also get data over coasts by applying some selection. I have also downloaded a coastal database as suggested in your website. I export PYNGL_RANGS with the right path in .bashrc. I also add mpDataBaseVersion = « HighRes  in python code. But on my figure, I have results everywhere, not just on coast.  Apparently, I met the same problem as I mentioned in the last email. 


     Many thanks again if you can give some clue !


Xiaoni




-----------------------------------------------------------------------------
# select only ocean data from the whole data. a masked array.
tbwater = tb_lo_clean[(sft_lo_clean == 0 )]
latwater = lat_lo_clean[(sft_lo_clean == 0 )]
lonwater = lat_lo_clean[(sft_lo_clean == 0 )]

# select only data over coasts
tbcoast = tb_lo_clean[(sft_lo_clean == 2 )]
latcoast = lat_lo_clean[(sft_lo_clean == 2 )]
loncoast = lon_lo_clean[(sft_lo_clean == 2 )]

# preparing to plot
fill_value = -32768

wks_type = "png"
wks = Ngl.open_wks(wks_type,’data_on_ocean')
ws_id = Ngl.get_workspace_id()

resources = Ngl.Resources()

resources.sfXArray            = lonwater
resources.sfYArray            = latwater

resources.sfMissingValueV = fill_value
resources.nglSpreadColorStart = 176
resources.nglSpreadColorEnd   = 2
resources.mpDataBaseVersion     = "MediumRes"
#resources.mpGridMaskMode        = "MaskLand"
resources.cnFillOn            = True
resources.cnFillMode          = "RasterFill"  
resources.cnFillPalette       = "BlAqGrYeOrReVi200"
resources.cnLinesOn           = False
resources.cnLineLabelsOn      = False
resources.lbBoxLinesOn        = False
resources.lbLabelFontHeightF  = 0.005
resources.cnLevelSelectionMode = "ManualLevels"
resources.cnMinLevelValF       = 120
resources.cnMaxLevelValF       = 250
resources.cnLevelSpacingF      = 10
resources.vpXF      = 0.1    # Change the size and location of the
resources.vpYF      = 0.9    # plot on the viewport.
resources.vpWidthF  = 0.4
resources.vpHeightF = 0.8

# create plot for data over ocean
resources.tiMainString        = "data over ocean  on 20030701"
map = Ngl.contour_map(wks,tbwater,resources)

# plot data on coasts
resources.sfXArray            = loncoast
resources.sfYArray            = latcoast
resources.cnMinLevelValF       = 200
resources.cnMaxLevelValF       = 300
resources.cnLevelSpacingF      = 10
mpDataBaseVersion = "HighRes"
resources.tiMainString        = "data over coasts on 20030701"
map = Ngl.contour_map(wks,tbcoast,resources)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20161025/d8b0d567/attachment.html 


More information about the pyngl-talk mailing list