[pyngl-talk] isccp grid with Pyngl

Mary Haley haley at ucar.edu
Mon Oct 24 11:13:21 MDT 2016


Xianoi,

I've already replied offline about the conda issues, and I'm hoping Kevin
can address these.

Meanwhile, with regard to your python script, I think you are on the right
track. However, I don't think you want to transpose the data before you
plot it. If it is dimensioned latitude x longitude, with latitude being the
leftmost dimension, then you don't need to transpose it. If it is
dimensioned longitude by latitude, then you need to transpose it.

To show the figure on the screen (we call it an "X11 window"), then change
"wks_type" to be "x11" instead of "ps". You need to click on the X11 window
with your left mouse button if you want the plot to go away.

Also, you don't want to set these two options:

    resources.nglDraw  = False
    resources.nglFrame = False

because these settings would cause your plot to not be drawn at all.
Either remove those lines or comment them out.  They are both True by
default.

And yes, once you have all the parameters (we call them "resources") set
up, you should be able to use the same ones to plot other data. The
tiMainString is probably the only thing you'll need to change.

However, if you decide you don't like the contour levels that PyNGL chooses
for you, then you might want to change these for your plots. You can look
at the cn05p.py for an example of setting contour levels using a min value,
max value, and a spacing (for equally spaced contours), or ctnccl.py for
example of explicitly setting contour levels to an unequally-spaced array
of values.

Finally, if your data is taking a long time to plot because it is a large
array, then you can try setting:

    resources.cnFillMode          = "RasterFill"    # default is AreaFill

Raster contouring can be noticeably faster than the default "AreaFill",
which is smooth contouring.  You can also set:

 resources.cnRasterSmoothingOn = True

which will smooth your raster contours, but still should be faster than
AreaFill.

I will attach a Python script that plots the "topo" variable from old and
partial ISCCP file that I have.  The data on this file is one-dimensional,
along with the lat/lon arrays. Here's what a dump of the file looks like:

   file global attributes:
      description : ISSCP reduced grid
   dimensions:
      nodes = 6596
   variables:
      float lon ( nodes )
         units :        degrees east
         long_name :    longitude

      float lat ( nodes )
         units :        degrees north
         long_name :    latitude

      float topo ( nodes )
         units :        meters above sea level (I think)
         long_name :    topology


I'll include the script and the second and third images just in case. I use
"png" as the output format.

--Mary

On Mon, Oct 24, 2016 at 6:50 AM, Xiaoni Wang <xiaoni.wang at obspm.fr> wrote:

> Dear colleague,
>       I tried to install Pyngl on my computer in order to draw 2D figures
> with ISCCP grids. Before this, I had used condo to install python2 and
> other python tools in /obs/xxwang/anaconda2/.
>
>       1) To install Pyngl, I followed the suggestion on your website:
>       conda create --name pyn_test python=2
>       source activate pyn_test
>       conda install --channel ncar --channel khallock pynio pyngl
>
>       Then I modified my .bashrc by add the new path :  export
> PATH="/obs/xxw/anaconda2/bin:/obs/xxw/anaconda2/envs/pyn_test/bin:$PATH »
>       I can see the environments:
>       pyn_test              *  /obs/xxw/anaconda2/envs/pyn_test
>       root                     /obs/xxw/anaconda2
>
>       Then I tried to import Nio, but I have an error: ImportError: No
> module named Nio
>
>       Could you help me to figure out why ?
>
>      2) I have another question about using the Pyngl for plotting data on
> ISCCP grids. Maybe this question would be (too) simple….
>
>        I have my data on ISCCP equal area grids (0.25 degree in latitude,
> and varying espace in longitude, with more grids near equator and less
> grids near pole). My data are global data. In my test:
>       ISCCP latitude : lat_isccp, 1D, (256915,) ),
>       ISCCP longitude: lon_isccp, (1D, (256915,))
>       data: emis (1D , (256915,)).
>
>        I would like to plot emis data on 2D map. I do not know if I should
> define resources.mpProjection ? how to show figure on screen, or how to
> save this figure ? or If I have several parameters to plot, I guess that I
> can use these configurations for all the figures (except  resources.tiMainString
>  )?
>        In the below is my example code for plotting one parameter ‘emis’ .
> I adapted from your SEAM example.
>
>       wks_type = "ps"
>       wks = Ngl.open_wks(wks_type, "isccp")
>       resources = Ngl.Resources()
>     resources.sfXArray            = lon_isccp
>     resources.sfYArray            = lat_isccp
>     resources.nglSpreadColorStart = 176
>     resources.nglSpreadColorEnd   = 2
>     resources.cnFillOn            = True
>     resources.cnFillMode          = "AreaFill"
>     resources.cnFillPalette       = "BlAqGrYeOrReVi200"
>     resources.cnLinesOn           = False
>     resources.cnLineLabelsOn      = False
>     resources.lbBoxLinesOn        = False
>     resources.lbLabelFontHeightF  = 0.015
>     resources.tiMainString        = "Emis"
>     resources.nglDraw  = False
>     resources.nglFrame = False
>
>     zt = np.transpose(emis)
>     contour = Ngl.contour(wks,zt,resources)
>     Ngl.end()
>
> Thank you very much for your help in advance !!
>
>
> Best regards
>
> Xiaoni W
>
>
>
>
>
>
> _______________________________________________
> pyngl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20161024/6fe4522f/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: isccp3.png
Type: image/png
Size: 456864 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20161024/6fe4522f/attachment-0002.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: isccp2.png
Type: image/png
Size: 294116 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20161024/6fe4522f/attachment-0003.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: isccp.py
Type: text/x-python-script
Size: 1286 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20161024/6fe4522f/attachment-0001.bin 


More information about the pyngl-talk mailing list