[pyngl-talk] Updates for using Pyngl

Mary Haley haley at ucar.edu
Tue Oct 25 08:30:08 MDT 2016


Xiaoni,

To help answer some of your graphical questions, I suggest looking at our
large collection of NCL examples at:

http://www.ncl.ucar.edu/Applications/

While these are written in NCL, they use the same plot options as PyNGL,
and may help you find the answers you need.

Please see my answers interspersed:


On Tue, Oct 25, 2016 at 4:38 AM, Xiaoni Wang <xiaoni.wang at obspm.fr> wrote:

> Hi Mary
>     Thank you very much for all your useful information ! Now my plots
> work well. Just I have a few more questions to clarify some confusion.
>
> 1) In my data, I do not have any data over the ocean. I noticed that there
> is strong interpolation over ocean in the figure (see any figure attached),
> which are not necessary. It seems that I could use resources.
> *mpGridMaskMode*
> <http://www.ncl.ucar.edu/Document/Graphics/Resources/mp.shtml#mpGridMaskMode>
> = "MaskOcean » , but it seems not working.
>    PS: I prefer that ocean would be white color for example. What shall I
> do ?
>

​The easiest thing to do is turn on map fill, and then draw the ocean fill
in white:

res.mpFillOn = True
res.mpOceanFillColor = "white"

​If that doesn't work, you might also need:

res.mpFillDrawOrder = "PostDraw"
​


> 2) Over small islands, the interpolation method also produced some effects
> (see large yellow areas on the ocean in figure isccp_19V.00001.png). Again
> I do not need the ocean around the island, just the results over (small)
> islands.
>

​This is simply an artifact of having a few values surrounded by a lot of
missing values.  In order to plot data like this correctly, you need to
have some kind of cell boundary or grid corner information, so the
interpolation stays within these bounds.

If you look at our NCL examples for geodesic and MPAS grids, they set these
two special resources:

  res at sfXCellBounds        = cx
  res at sfYCellBounds        = cy
​which were read off a file, and are usually dimensioned something like N x
4 or N x 3 where N is the number of cell centers, and the 3 or 4 represents
the number of vertices of a polygon that surrounds each cell center.

You can see the NCL code for these examples at:

http://www.ncl.ucar.edu/Applications/geodesic.shtml
http://www.ncl.ucar.edu/Applications/mpas.shtml  (see example
mpas_cell_3.ncl)
​

>
> 3) I would like to increase the figure size of figure. I tried :
> 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
>

​These resources change the size of the image within a unit square.  If you
are trying to increase the size of the PNG image, then you need to do this
when you open the workstation:

wkres =  Ngl.Resources()
wkres.wkWidth
​ = 2500      # Set the pixel size, must be a square
​
wkres.wkHeight  =  2500
wks_type = 'png'
wks = Ngl.open_wks(wks_type,"%s/isccp_%s" %(figure_dir, channelname)
​,wkres)​


> But when I open the figure, it remains the same size, seems to me.
>
> 4) I would like to put the larger values in color red, and small values in
> blue for example. (Now it is the inverse). How to modify it ?
>

​You can use the "read_colormap_file" function in PyNGL to read in the
colormap as an N x 4 RGBA array, and then reverse the first dimension:​


    resources.cnFillPalette       =
​Ngl.read_colormap_file(​
"BlAqGrYeOrReVi200"
​)[::-1,:]​


>
> 5) Yes, indeed I have several figures to plot. I found that they are named
> as isccp.000001.png for example. Could I name it as isccp.model.png ?
>     In my code, I will loop over several files (current figures from only
> do 1-time iteration). Do I have to clear something after each iteration is
> finished ? Actually it does not work for more than 1 iteration
> (message Invalid workstation).
>

​You can only have one image per PNG file, so it's not possible to put all
images in one file called "isccp.model.png".

It is possible to open a new workstation every time inside your do loop,
but you will want to change the PNG name​.

For example, if you had:

varnames = ["t","p","rh"]
for vname in varnames:
  wks = Ngl.open_wks(wks_type,vname,wkres)

  . . . code that creates a plot


--Mary


>     I attach the code and also a few figures to you. Thank you in advance
> for your help !
>
> Best wishes,
>
> Xiaoni
>
>
>
>
> Le 24 oct. 2016 à 19:31, Mary Haley <haley at ucar.edu> a écrit :
>
> Xiaoni,
>
> I think the issue is that you are using "resources" to set wsMaximizeSize,
> and then you also pass this list into the contour_map call. You don't want
> to do this, so I suggest using a different resource list to set
> wsMaximizeSize:
>
> wresources = Ngl.Resources()
> wresources.wsMaximumSize = 33554432
> Ngl.set_values(ws_id,wresources)
>
> Since you have a large grid, I recommend setting res.cnFillMode =
> "RasterFill" if you haven't already. This may fix the warning as well.
>
> You can then use "resources" for setting your contour plot options.
>
> Also, I don't think you need to do all that stuff with calling get_float
> to retrieve a bunch of values and creating the contours twice.
>
> See the modified version of your script attached.  It looks like you just
> sent me a partial script, so what I've modified is just an example of how
> you can change your original script.
>
> --Mary
>
>
>
>
> On Mon, Oct 24, 2016 at 9:52 AM, Xiaoni Wang <xiaoni.wang at obspm.fr> wrote:
>
>> Dear Sir or Madam,
>>       Sorry to write to you several emails !  I would like to update the
>> news and questions since I have wrote to you.  I solved the installation
>> problem of Pyngl and Pynio. I can import them without problem.
>>
>>      Now I tried to run a python code to plot data on ISCCP grids. As I
>> mentioned to you in my previous email, I have data such as:
>>       ISCCP latitude : lat_isccp, 1D, (256915,)
>>       ISCCP longitude: lon_isccp, (1D, (256915,))
>>       data: emis, (1D , (256915,))
>>       I also have the horizontal width for each grid (in km).
>>
>>      I would like to make 2D plot on ISCCP grids. When I launched my
>> program, it has fatal errors:
>>         fatal:ContourPlotDraw: Workspace reallocation would exceed
>> maximum size 100000000
>>
>>      After reading the FAQ, I added the following lines in my codes:
>> ws_id = Ngl.get_workspace_id()
>>         resources = Ngl.Resources()
>>         resources.wsMaximumSize = 33554432
>>         Ngl.set_values(ws_id,resources)
>>
>>     But then I got another error:
>>        fatal:["Error.c":406]:ErrorInitialize:Only one instance of
>> ErrorClass is supported.
>>
>>
>>     I do not understand….. I will look again at your tutorial to get more
>> information. The attached is the code that I used. Thank you in advance if
>> you could give some clue.
>>
>> Best regards
>>
>> Xiaoni
>>
>>
>>
>>
>>
>>
>>
>>
> <test_mod.py>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20161025/14f266f9/attachment.html 


More information about the pyngl-talk mailing list