Giter VIP home page Giter VIP logo

pyngl's Introduction

PyNGL

Warning

PyNGL was placed in maintenance mode as of November of 2020. You can find more details in the full announcement here.

PyNGL ("pingle") is a Python module built on top of NCL's graphics library, which produces publication-quality, two-dimensional visualizations tailored for climate and weather data.

Interfaces exist for the display of:

  • Contour plots
  • XY plots
  • World map projections
  • Vector plots
  • Streamline plots

PyNGL is developed by the Computational and Information Systems Lab at the National Center for Atmospheric Research (NCAR).

NCAR is sponsored by the National Science Foundation. Any opinions, findings and conclusions or recommendations expressed in this material do not necessarily reflect the views of the National Science Foundation.

Installation

PyNGL can be installed on Linux and MacOS systems via conda:

conda create --name pyn_env --channel conda-forge pyngl
source activate pyn_env

Documentation and support

Visit the PyNGL website for documentation, examples, support, and installation.

Bug reports and feature requests

Use the GitHub issue tracker to submit a bug or request.

pyngl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyngl's Issues

Ngl contour_map freezing my computer

I try running ngl contour plot with this code

from future import print_function
import numpy

Import the masked array module.

from numpy import ma as MA
import os

Import Ngl support functions.

import Ngl

Import Nio for a NetCDF reader.

import Nio

To use the ScientificPython module to read in the netCDF file,

comment out the above "import" command, and uncomment the

import line below.

from Scientific.IO.NetCDF import NetCDFFile

Open the netCDF files, get variables.

data_dir = Ngl.pynglpath("data")
ice1 = Nio.open_file(os.path.join(data_dir,"cdf","/Users/mada0007/Documents/correct_data/spi_3.nc"),"r")

This is the ScientificPython method for opening a netCDF file.

ice1 = NetCDFFile(data_dir + "/cdf/fice.nc","r")

Create a masked array to accommodate missing values in the fice variable.

fice = ice1.variables["SPI3"] # fice[120,49,100]
ficea = fice[:,:,:]
fill_value = None
if (hasattr(fice,"missing_value")):
fill_value = fice.missing_value
elif (hasattr(fice,"_FillValue")):
fill_value = fice._FillValue
fice_masked = MA.transpose(MA.masked_values(ficea,fill_value),(1,2,0))

hlat = ice1.variables["lat"] # hlat[49]
hlon = ice1.variables["lon"] # hlon[100]

dimf = fice.shape # Define an array to hold long-term monthly means.
ntime = fice.shape[0]
nhlat = fice.shape[1]
nhlon = fice.shape[2]

nmo = 0
month = nmo+1

icemon = MA.zeros((nhlat,nhlon),dtype=float)
for i in range(fice_masked.shape[0]):
for j in range(fice_masked.shape[1]):
icemon[i,j] = MA.average(fice_masked[i,j,0:ntime:12])

Fill the places where icemon is zero with the fill value.

icemon = MA.masked_values(icemon,0.,rtol=0.,atol=1.e-15)
icemon = MA.filled(icemon,fill_value)

                   # Calculate the January (nmo=0) average.

nsub = 16 # Subscript location of northernmost hlat to be plotted.

cmap = numpy.array([
[1.00,1.00,0.50], [0.00,0.00,0.50], [0.50,1.00,1.00],
[0.50,0.00,0.00], [1.00,0.00,1.00], [0.00,1.00,1.00],
[1.00,1.00,0.00], [0.00,0.00,1.00], [0.00,1.00,0.00],
[1.00,0.00,0.00] ],dtype=float)

wks_type = "png"
wks = Ngl.open_wks(wks_type,"ngl09p")

resources = Ngl.Resources()

Add a longitude cyclic point

icemonnew,hlonnew = Ngl.add_cyclic(icemon[0:nsub+1,:],hlon[:])

resources.sfMissingValueV = fill_value
resources.cnFillPalette = cmap
resources.sfXArray = hlonnew # Necessary for overlay on a map.
resources.sfYArray = hlat[0:nsub+1]
resources.tiMainString = "CSM Y00-99 Mean Ice Fraction Month ={}".format(month)

resources.pmTickMarkDisplayMode = "Never"

map = Ngl.contour_map(wks,icemonnew,resources) # Draw a contour
# over a map.

nmos = 12 # Specify the number of months in the loop (max 120).
for nmo in range(1,nmos):
month = nmo+1
for i in range(fice_masked.shape[0]):
for j in range(fice_masked.shape[1]):
icemon[i,j] = MA.average(fice_masked[i,j,nmo:ntime:12])
icemon = MA.masked_values(icemon,0.,rtol=0.,atol=1.e-15)
icemon = MA.filled(icemon,fill_value)

resources.tiMainString = "CSM Y00-99 Mean Ice Fraction Month ={}".format(month)
map =
Ngl.contour_map(wks,Ngl.add_cyclic(icemon[0:nsub+1,:]),resources)

del icemon # Clean up.
del icemonnew
del map

Ngl.end()

Almost the time I use this function, my computer hungs and I have to restart. How can I resolve this? Thanks

ErrorInitialize: Only one instance of ErrorClass is supported

I found an issue that the console shows me
fatal:["Error.c":406]:ErrorInitialize: Only one instance of ErrorClass is supported
fatal:Unable to initialize layer-Can't Create
fatal:Error Creating ErrorClass object
fatal:Unable to initialize layer-Can't Create
fatal:Unable to initialize layer-Can't Create
fatal:_NhlCreate:Unable to access "default" App object

when I repeated call pyngl to draw pictrue.

I would identify that I had closed workstation object and any other objects involved with pyngl.

how can I fix this problem?

fplib.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZGVdN4vv_pow

When I do a

python setup.py build

and install it, I get this afterwards.

>>> import Ngl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/p/project/cesmtst/poshyvailo1/PostProcessing_TSMP/PYTHON_post/iris/lib/python3.8/site-packages/Ngl.py", line 1, in <module>
    from ngl import __all__ as _ngl_all
  File "/p/project/cesmtst/poshyvailo1/PostProcessing_TSMP/PYTHON_post/iris/lib/python3.8/site-packages/ngl/__init__.py", line 49, in <module>
    from . import fplib
ImportError: /p/project/cesmtst/poshyvailo1/PostProcessing_TSMP/PYTHON_post/iris/lib/python3.8/site-packages/ngl/fplib.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZGVdN4vv_pow

gsn_contour_shade functionality missing in PyNGL

Hi!!
I am trying to switch from NCL to PyNGL for my plotting requirements. I require to plot stippling over my contour plots using t-test. The functionality for stippling is available in NCL using function gsn_contour_shade but this functionality is missing in PyNGL. I would hope that this functionality is added to PyNGL.

Regards
Puneet

nice_cntr_levels returns nsteps instead of step size

It appears as though the nice_cntr_levels function ultimately returns the number of steps, instead of the step size. Consequently, we get very misleading behavior when we pass the returnLevels argument. For example, if we pass lmin = 0, lmax = 457.8073, and specify a max step size of max_steps=15, we get back 41 levels:

>>> from ngl import nice_cntr_levels
>>> nice_min, nice_max, cint, levels = nice_cntr_levels(0.0, 457.8073, max_steps=15, returnLevels=True)
>>> print(levels)
[  0.  12.  24.  36.  48.  60.  72.  84.  96. 108. 120. 132. 144. 156.
 168. 180. 192. 204. 216. 228. 240. 252. 264. 276. 288. 300. 312. 324.
 336. 348. 360. 372. 384. 396. 408. 420. 432. 444. 456. 468. 480.]
>>> print(len(levels))
41

The reason for this is the following block of code in nice_cntr_levels:

        try:
            index = numpy.where(cints < max_steps)[0][0]
        except IndexError:
            return None

        if returnLevels:
            return am1[index], ax1[index], cints[index], numpy.arange(am1[index], ax1[index]+cints[index], cints[index])
        else:
            return am1[index], ax1[index], cints[index]

At this point in the code, cints is a list of candidate number of steps, while t is a list of candidate step sizes. Thus, the numpy.where call correctly finds the index we want. However, the return statements use cints, where they should be indexing into the t list, which represents the candidate list of step sizes. Replacing this block with the following gives me the expected behavior:

        try:
            index = numpy.where(cints < max_steps)[0][0]
        except IndexError:
            return None

        if returnLevels:
            return am1[index], ax1[index], t[index], numpy.arange(am1[index], ax1[index]+t[index], t[index])
        else:
            return am1[index], ax1[index], t[index]

And demonstrating the same example:

>>> from utils import nice_cntr_levels
>>> nice_min, nice_max, cint, levels = nice_cntr_levels(0.0, 457.8073, max_steps=15, returnLevels=True)
>>> print(levels)
[  0.  40.  80. 120. 160. 200. 240. 280. 320. 360. 400. 440. 480.]
>>> print(len(levels))
13

Not an issue, just a quick question

Does PyNGL use all the functions that were written in the original NCL command language? I looked at functions and examples, and it looked like it was missing quite a lot from the original functions library. Specifically I am looking for the original NCL command dv2uvf which worked with creating irrotational wind from the given data file's wind fields. If not, why aren't these functions included? Computations such as this are exceedingly difficult to compute without prior knowledge on solving Poisson's Equation so having them available would be very useful.

Thank you!

Must use "source activate ncl_to_python"?

My system has to call a python script, and can not type the "source activate ncl_to_python". Is there a way to automatically access the "ncl_to_python" environment?

windows version

Will the windows version be released in the future? If so, is there a planned date?

Installing the Ngl and Nio libraries into CDAT

Dear Forum

I mainly use the python based Climate Data Analysis Tool (CDAT) environment for processing my datasets
I would like to use some of the functions provided by Ngl within CDAT

For example, Ngl.vinth2p would be very useful if I can access it separately through the CDAT environment rather than still having it in the pyn_env environment

Is it possible to import CDAT libraries (such as cdms2, cdutil, vcs etc.) within pyn_env or the vice-versa (importing Nio and Ngl within CDAT) ?

Please let me know

Thank you very much

how using pyngl character chinese ?

i have a question, how using pyngl in titles encoding to chinese, i watch source code in support unicode

%module hlu

2 |  
3 | %{
4 | /* Python 3.7 changes the unicode char* to const char* */
5 | #if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 7
… |  
9 | #endif

like this code:

txres = Ngl.Resources()
txres.txFontHeightF = fnth

txres.txJust = "chinese" ....

how using?

Lack code completion for res attribute

Hello all,

I generally use VSCode with "Remote - WSL" extension to edit and run code.
I found that there is no code completion for Ngl.Resources() attribute,
For example, I want to type "res.cnFillOn = True", but no "cnFillOn" code completion for me to use.

is the reason come from my misconfiguration, or the pyngl itself lack of completion support...?

Thank you.

Missing example netCDF Files in Tutorials

I'm following the PyNGL tutorials and I can't find the netCDF files found in the tutorials.

Example 2 for contour plots (https://www.pyngl.ucar.edu/Tutorial/ngl02p.shtml):
runs:
cdf_file = Nio.open_file(Ngl.pynglpath("data") + "/cdf/contour.cdf","r")

I can't find anywhere where I can download contour.cdf

Same thing for the rest of the example files. Could those be added or made available for download somewhere?

Hatching pattern 3 with pyNgl

Dear pyNgl team,

I have a simple need and I can't do it by myself: on a map, I want to hatch values greater than 0.9 with pattern number 3 (diagonal black lines).
The absolute bonus would be to also control the lines thickness.

My data is a mask field, with 0 and 1 values.

Here is the portion of my code associated with it:

   f    = Nio.open_file(mask_file)
   dat  = f.variables["mask"][:,:]
   lat  = f.variables["lat"][:]
   lon  = f.variables["lon"][:]

   cnres                 = Ngl.Resources()
   cnres.nglDraw  = False
   cnres.nglFrame = False
   cnres.nglMaximize = False

   # Contour resources
   cnres.cnFillOn        = True

   cnres.cnMonoFillPattern = False

And now is the problematic section: what should I give to those resources to get hatching only for values above 0.9 (i.e. where the mask == 1)?

   cnres.cnFillPatterns = ?
   cnres.cnFillColors      = ?
   cnres.cnMinLevelValF = ?
   cnres.cnMaxLevelValF = ?

   Ngl.contour_map(wks,dat,cnres)

I've been struggling for quite a while, trying various combinations but I can’t actually control the hatching (color, pattern).

Could you help me with this issue?

(I've posted on pyngl-talk but haven't received any answer yet, and since the figures are for the IPCC AR6 report we really need to find a solution)

Many thanks in advance

PyNGL equivalent to gsnFillColors with transparency

Using Ncl, you can use gsnXYFillColors together with colors defined by a quadruplet (RGB+transparency) for creating graphs where an enveloppe between two curves can be lightly shaded, and superimposed on another enveloppe.

This is e.g. useful when showing time evolution of a climate variable, and its confidence interval, under two forcing scenarios

I have not been able to figure out from PyNGL doc how to do that : If ressource nglXYFillColors allow to fill the area between two curves, it only allows for named colors or color indices, and not color quadruplet such as with gsnXYFillColors; and PyNGL explanations about named colors and color indices make no mention of opacity tuning

So I assume this is a PyNGL shortcoming (vs NCL). Insnt'it ? Any hope for a fix, sooner or later ?

Unable to install PyNIO and PyNGL in Debian Linux

Hi, I try to install pynio and pyngl in Debian Linux (running in a virtual machine) by using "conda create --name pyn_env --channel conda-forge pynio pyngl", but it failed.

These are details:

  • Virtual machine version: VMware® Workstation 14 Pro 14.1.2 build-8497320
  • Operating system: Windows 10, 64-bit (Build 17134) 10.0.17134
  • Debian version: Linux debian 4.9.0-7-amd64 #1 SMP Debian 4.9.110-3+deb9u1 (2018-08-03) x86_64 GNU/Linux
  • Enter commands at the console:
shigan@debian:~$ conda create --name pyn_env --channel conda-forge pynio pyngl
Fetching package metadata .............
Solving package specifications: .


UnsatisfiableError: The following specifications were found to be in conflict:
  - pynio
Use "conda info <package>" to see the dependencies for each package.


shigan@debian:~$ conda create --name pyn_env --channel conda-forge pyngl
Fetching package metadata .............
Solving package specifications: .


UnsatisfiableError: The following specifications were found to be in conflict:
  - pyngl
Use "conda info <package>" to see the dependencies for each package.

  • conda list:
shigan@debian:~$ conda list
# packages in environment at /home/shigan/miniconda2:
#
cffi                      1.9.1                    py27_0    defaults
conda                     4.3.14                   py27_0    defaults
conda-env                 2.6.0                         0    defaults
cryptography              1.7.1                    py27_0    defaults
enum34                    1.1.6                    py27_0    defaults
idna                      2.2                      py27_0    defaults
ipaddress                 1.0.18                   py27_0    defaults
libffi                    3.2.1                         1    defaults
openssl                   1.0.2k                        1    defaults
pip                       9.0.1                    py27_1    defaults
pyasn1                    0.1.9                    py27_0    defaults
pycosat                   0.6.1                    py27_1    defaults
pycparser                 2.17                     py27_0    defaults
pyopenssl                 16.2.0                   py27_0    defaults
python                    2.7.13                        0    defaults
readline                  6.2                           2    defaults
requests                  2.12.4                   py27_0    defaults
ruamel_yaml               0.11.14                  py27_1    defaults
setuptools                27.2.0                   py27_0    defaults
six                       1.10.0                   py27_0    defaults
sqlite                    3.13.0                        0    defaults
tk                        8.5.18                        0    defaults
wheel                     0.29.0                   py27_0    defaults
yaml                      0.1.6                         0    defaults
zlib                      1.2.8                         3    defaults

  • conda info:
shigan@debian:~$ conda info
Current conda install:

               platform : linux-64
          conda version : 4.3.14
       conda is private : False
      conda-env version : 4.3.14
    conda-build version : not installed
         python version : 2.7.13.final.0
       requests version : 2.12.4
       root environment : /home/shigan/miniconda2  (writable)
    default environment : /home/shigan/miniconda2
       envs directories : /home/shigan/miniconda2/envs
                          /home/shigan/.conda/envs
          package cache : /home/shigan/miniconda2/pkgs
                          /home/shigan/.conda/pkgs
           channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch
                          https://repo.continuum.io/pkgs/free/linux-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/linux-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/linux-64
                          https://repo.continuum.io/pkgs/pro/noarch
            config file : /home/shigan/.condarc
           offline mode : False
             user-agent : conda/4.3.14 requests/2.12.4 CPython/2.7.13 Linux/4.9.0-7-amd64 debian/9.5 glibc/2.24
                UID:GID : 1000:1000

lbLineLabelStrings

Are there any plans to add lbLineLabelStrings and lbExplicitLineLabelsOn as valid resources in contour?

warning:lbLineLabelStrings is not a valid resource in contour at this time
warning:lbExplicitLineLabelsOn is not a valid resource in contour at this time

Thanks!

Panel Function Resource name error

From "pyngl_version.py";
version: 1.5.0-beta
array_module: numpy
array_module_version: 1.9.2
python_version: 2.7.9

uname -a output;
Linux mlogin101 2.6.32-754.14.2.el6.x86_64 #1 SMP Wed Apr 24 16:18:30 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux

Error output;
_set_spc_res: Unknown special resource nglPanelLabelBarFontHeightF

Cannot include simplified script.

When using Resources() and setting the attribute 'lbLabelFontHeightF' for panel this error is experienced.

Tracked in the pyngl.py module file on the institute server (I am not a root user) to line 4959 where the resource name 'PanelLabelBarFontHeightF' is passed to function '_set_spc_res' where at line 1366 it fails to be recognised when compared with the resource key 'PanelLabelBarLabelFontHeightF'.

Can you confirm that this was changed in the current version so that I can address this with the server moderators or please make this correction to line 4959 so that the resource call succeeds.

Thanks.

Copying an instance of Ngl.Resources() passes as reference

Hi,

I've ran into a curious behaviour when defining a "base" resource variable, for resources shared between different plots in the same script. Take for example:

resbase = Ngl.Resources() 
resbase.nglDraw = False 
res1 = resbase 
res1.nglFrame = False
res2 = resbase 
res2.nglFrame = True

After this, not only resbase has a nglFrame resource, both it's and res1s are True, implying perhaps that Ngl.resources() are passed as reference instead of copy.

This is very different from what NCL used to do, and can get very confusing. Is this the intended behaviour? If it is, is there a way to pass it as a copy instead?

Thanks,
Gabriel

ImportError libgfortran.so.4: cannot open shared object file: No such file or directory

Attempting a new conda env on Ubuntu 21 and python 3.8 gives the following error

Python 3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 21:59:51) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Ngl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/waffleboy/anaconda3/envs/isohyet/lib/python3.8/site-packages/Ngl.py", line 1, in <module>
    from ngl import __all__ as _ngl_all
  File "/home/waffleboy/anaconda3/envs/isohyet/lib/python3.8/site-packages/ngl/__init__.py", line 49, in <module>
    from . import fplib
ImportError: libgfortran.so.4: cannot open shared object file: No such file or directory

Gcc-7 isnt available anymore - is there a way to solve this? Or are there alternaties for the natural neighbour interpolation?

gc_inout issue

Hi,
I found a bug in the pyngl when I used the gc_inout.

For example:

Ngl.gc_inout(30,120,[30,70,70,30,30],[120,120,160,160,120])
array([1], dtype=int32)
Ngl.gc_inout(31,120,[30,70,70,30,30],[120,120,160,160,120])
array([1], dtype=int32)
Ngl.gc_inout(31,121,[30,70,70,30,30],[120,120,160,160,120])
array([1], dtype=int32)
Ngl.gc_inout(30,121,[30,70,70,30,30],[120,120,160,160,120])
array([0], dtype=int32)

Obviously the point 30N 121E is in the box?
So why it is?

Python 3.9 Support on Conda

Hi there!
Would it be possible to support Python 3.9 with pyngl on conda? (pynio not needed since there are simple alternatives)
Currently there are versions for Python 3.5-3.8 available on conda. At least for me porting pyngl plotting code to cartopy requires a real lot more work than pynio file reading code and it would be nice to continue supporting old pyngl plotting scripts!

Under the pyngl ucar faq site in "General questions 2." it states that Python 3.x is supported so if you can't make it to support any further versions than Python 3.8 with pyngl maybe you could update this page to let everyone know that support ends with Python 3.8. Thanks!

Add equivalent functionality to gsnLeftString and gsnRightString

Hi, I'd like to request that pyngl add functionality equivalent to the gsnLeftString and gsnRightString resources in NCL. I use those when plotting gridded model forecast data, using one to indicate the initialization time, and the other to indicate the valid time. I'm starting to play around with pyngl now, and that's one feature I've discovered that's missing from NCL that I use all the time.

Jared

Import Ngl error

I installed pyNGL (version 1.6.1) onto my Mac (OS 10.14.6) using the following commands:

conda create --name pyn_env --channel conda-forge pynio pyngl
source activate pyn_env

I then tested pyNGL and pyNIO;

import Nio
import Ngl

pyNio is fine, but I got the following error with pyNGL;

ImportError: dlopen(/Users/jen/anaconda3/envs/pyn_env/lib/python3.7/site-packages/ngl/fplib.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libgfortran.3.dylib
Referenced from: /Users/jen/anaconda3/envs/pyn_env/lib/python3.7/site-packages/ngl/fplib.cpython-37m-darwin.so
Reason: image not found

Can you help me with this error? Thank you.

Can`t find the generated image file

I used pyNGL and pyNio to plot a MOD06 data in jupyter like [http://www.pyngl.ucar.edu/Examples/Scripts/hdf2.py]. After I run the script, there is no output like errors and warnings, but I can`t find the hdf2.png(plotted image) anywhere.
Here is the contour.dict :{'nbase': 1, 'base': [-4], 'ncontour': 1, 'contour': [-4], 'nvector': 0, 'vector': None, 'nstreamline': 0, 'streamline': None, 'nmap': 1, 'map': [-4], 'nxy': 0, 'xy': None, 'nxydspec': 0, 'xydspec': None, 'ntext': 0, 'text': None, 'nprimitive': 0, 'primitive': None, 'nlabelbar': 0, 'labelbar': None, 'nlegend': 0, 'legend': None, 'ncafield': 0, 'cafield': None, 'nsffield': 1, 'sffield': [-4], 'nvffield': 0, 'vffield': None}

Custom tickmarks in contour_map()

Hi, I used PYNGL to draw a contour on the map by using the Ngl.contour_map() function. I want to specify the interval of the X coordinate tickmarks (adjust the the lat and lon labels to tenths of a degree), but when I specify the tmXBValues resource, it will prompt warning: tmXBValues is not a valid resource in contour.PlotManager at this time.

This can be achieved in NCL through the gsn_csm_contour_map function. I guess the contour_map() in Pyngl corresponds to the gsn_contour_map() in NCL, which is also impossible to customize ticks. I read all the functions provided by Pyngl, and it seems that there is no one that can custom tickmarks of contour on map.

Is there a way to custom tickmarks in contour_map(), or will the csm_contour_map() be added in a future update?

Thanks!

Reusing the interpreter after Ngl.end()

Hello all,

I generally use python on a jupyter notebook in Atom. In that context, it
would be useful to rerun just the plotting part of a script when iterating
with resources and such. However, after calling Ngl.end() apparently something is
flushed/closed and you can't open a workspace again.

Is there something one can do after Ngl.end() to make the Ngl stuff work
again, short of restarting the kernel/interpreter and losing everything
else the script did? I supposed that would also be useful for creating plots inside a reusable function and similar applications.

Thank you,

ImportError: libtbb.so.2

Just wanted to note that here since i couldn't find an issue on that. I recently got this error, when installing pyngl in a fresh conda environment:

ImportError: libtbb.so.2: cannot open shared object file: No such file or directory

I could solve this by downgrading tbb:

conda install tbb=2020.2

similar to this: https://www.biostars.org/p/494922/

Problems with running PyNgl function Ngl.gc_inout on local computer

To whom it may concern,

My name is Austin Reed and I am conducting research on precipitation. I have been coding in python and have been using your PyNgl module to analyze data. I am using PyNgl version 1.6.1 and python 3.7.4 and have installed them using anaconda using conda-forge and have it in a seperate environment in conda . While working on my research, I have noticed a few issues regarding the Ngl.gc_inout function. I copied your example on the PyNgl website for Ngl.gc_inout and all of them produce "None" instead of the output listed on the website. In addition to this, I have been getting a fatal error of "deallocating none" when I use the function with lat/lon data, whether it be for precip data or just dummy data. I checked with a colleague who has the same package which was run on her local computer and she obtained the correct result [1] , instead of the "None" that I am getting. I am not quite sure why I've been getting this error or how I could diagnose it. Any help would be greatly appreciated!

Thank you,
Austin

No module named '_hlu'

When I try import Ngl in a jupyter notebook, I get the following error, how do I solve it?
ModuleNotFoundError: No module named '_hlu'

Changes in the function of the taylor diagram.

Hello!!
I made some modifications to the function of the taylor diagram to better adapt to my needs here at INPE, in Brazil. After some modifications I managed to arrive at a pleasant result, however I cannot remove the semicircle from the values ​​0.50 in Y and 0.50 in X. Any suggestions on how it can be done?

  • Taylor diagram image

taylor diagram
taylor_diagram_SUDESTE_B6

Unable to install pynio or pyngl

Hello,
I keep getting the following error when I try to install:

(base) PS C:> conda create --name pyn_env --channel conda-forge pynio pyngl
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  • pyngl
  • pynio

Current channels:

To search for alternate channels that may provide the conda package you're
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

(base) PS C:>

ModuleNotFoundError foy PyNIO and PyNGL

I'm trying to get started with PyNIO and PyNGL, and I'm having issues getting the packages to import once I've activated the environment. I'm a Linux user on CentOS 7 with Anaconda 4.8.5 installed. I was able to install the packages into a new environment as shown on the main page, but when I try to import the packages I get a ModuleNotFoundError return. Once the environment is activated, I can import common packages like Numpy without issue, but I'm unable to import both PyNIO and PyNGL. I have not installed other packages into the environment, and the source for all packages is conda-forge. I am using the following import commands:

import Nio
import Ngl

pyngl equivalent to NCL gsnBoxMaximize

I want to convert a process I previously coded in NCL to pyngl.

I want to create a 4000x2000 png image for a special display. In NCL, since the workspace is always square, I simply create a 4000x4000 image and then crop it with ImageMagick. In order to get the final image to occupy the full space, I use the gsnMaximize and gsnBoxMargin resources in NCL. I can use Ngl.maximize_plot in pyngl to maximize the plot, but I can't seem to get rid of the white space surrounding the plot.

What can I do to get a full 4000 pixel width plot?

lbLabelStrings

Hello!!!
when I used 'Ngl.contour_map', the lbLabelStrings was useless.
Such as :
cnres.cnExplicitLabelBarLabelsOn = True
cnres.lbLabelStrings = ['0','0.1','0.2','0.3','0.4','0.5','0.6','0.7','0.8','0.9','1.0']
But didn't work.

Contour Plot with Latitude on the X-Axis

I am currently attempting to recreate some of the figures of this paper, in particular the first part of Figure 5. This plot shows the zonally-averaged zonal wind-speed at various latitudes (horizontal axis) and vertical axis (altitude, in pressure).

With regard to software version and installation, I have the latest version of PyNGL and have successfully run several of the example codes found on the PyNGL website.

Unfortunately, the data file I am using is too large to include here, so I will only be able to attached the script. If the data file would also be helpful, I can probably put it on Google Drive and include a link.

Most of the script is processing the data which is output by the atmospheric component of the E3SM. After the processing, I have three arrays:

  • A 1-D array of latitudes in ascending order, which I shall call uniqueLatitudes (as it is in the script). It is of shape (5651,).
  • A 1-D array of altitudes in ascending order, which I shall call lev (as it is in the script). It is of shape `(72,).
  • A 2-D array of zonally-averaged zonal-wind speeds, which I shall call sortedZonalMeans (as it is in the script). It is of shape (72, 5651).

I am attempting to make a contour plot of sortedZonalMeans with lev on the vertical axis and uniqueLatitudes on the horizontal axis. To do this, I tried to follow the example of irregular.py (found on the PyNGL website) and so the plotting part of the code is:

# Set up the plot
wks_type = "png"
wks = Ngl.open_wks(wks_type,"zonal_3Y")

cnres                 = Ngl.Resources()

# Plot title
cnres.tiMainString        = "3-Year Climatology of Zonal Wind (Zonally-Averaged)"
cnres.tiMainFontHeightF   = 0.02

# Scalar field resources
cnres.sfXArray        = uniqueLatitudes
cnres.sfYArray        = lev

contour = Ngl.contour(wks,sortedZonalMeans,cnres)

Running the entire Python script with the necessary data files, I obtain the error message:

warning:_NhlCreateSplineCoordApprox: Attempt to create spline approximation for X axis failed: consider adjusting trXTensionF value
warning:IrTransInitialize: error creating spline approximation for trXCoordPoints; defaulting to linear

Following the advice of these error messages and the documentation, I tried adjusting the trXTensionF value

# Set up the plot
wks_type = "png"
wks = Ngl.open_wks(wks_type,"zonal_3Y")

cnres                 = Ngl.Resources()

# Plot title
cnres.tiMainString        = "3-Year Climatology of Zonal Wind (Zonally-Averaged)"
cnres.tiMainFontHeightF   = 0.02

# Scalar field resources
cnres.sfXArray        = uniqueLatitudes
cnres.sfYArray        = lev
cnres.trXtensionF   = 0.1

contour = Ngl.contour(wks,sortedZonalMeans,cnres)

which didn't change the error messages.

Hypothesis 1: I think this issue is from the non-linearity of the latitudes in the uniqueLatitudes array, as shown in this ListPlot generated with Mathematica

image

I don't know how to resolve this issue if this is the cause.

Hypothesis 2: Another possible issue might be with the precision of the latitudes in uniqueLatitudes. The original latitudes array gives the latitude of each column of air that is simulated, meaning that many latitudes are repeated in the original latitudes list. I use a dict to create a list of key-value pairs where the key is a latitude and the value is a list of indices of the original latitudes lists corresponding to that latitude.

I think the precision of the latitudes in the key of uniqueLatitudes may be greater than when it is used as the sfXArray, such that the sfXArray has duplicate entries. (I just thought of this, so I will work to amend that issue in the creation of uniqueLatitudes).

UPDATE: I don't believe the issue is Hypothesis 2, I tried rounding all of the latitudes to the nearest hundredth, tenth, and integer and received the same error.

Any ideas for resolving this?

clim_zonal.py.txt

Thicker lines for shading patterns

Hello,
I would like to have thicker lines on my shading pattern #3 (hatching), and haven't found a way to do it, is it possible?
Thank you in advance
J.

global font type

I am very grateful to you for reading my issue. I want to know is there a res to change the global default font type ?

Ngl.regline causes segmentation fault

Hi,

I've just tested Ngl.regline with python 3 and run into a segmentation fault. The simple example below from the PyNGL Ngl.regline function description page demonstrates what happend.

import Ngl

x = [ 1190.,1455.,1550.,1730.,1745.,1770.,
1900.,1920.,1960.,2295.,2335.,2490.,
2720.,2710.,2530.,2900.,2760.,3010. ]
y = [ 1115.,1425.,1515.,1795.,1715.,1710.,
1830.,1920.,1970.,2300.,2280.,2520.,
2630.,2740.,2390.,2800.,2630.,2970. ]

print('--> regline')
rc,attrs = Ngl.regline(x,y,return_info=True)
print (rc)
print (attrs)

Note use of dictionary items

df = attrs["nptxy"]-2
tval = attrs["tval"]
yint = attrs["yintercept"]
prob = (1 - Ngl.betainc(df/(df+tval^2), df/2.0, 0.5) )

yReg = rc*x + yint
print ("prob",prob)
print (yReg)

Bye, Karin

python 3 development snapshot?

In a similar vein to NCAR/pynio#17, I was wondering if a development snapshot of a python 3-compatible version of pyngl was in the works? I'm in the process of making the move to python 3, and have some code that I inherited that uses pyngl for plotting soundings that I'd like to be able to port over.

Thanks for any info you can give!

Could background color to be changed?

Hi there,

I was wondering if we could change the background color in a contour. I want to change my blue background color into white one. And I have already tried to change "mpFillDrawOrder", "mpFillColor", "mpFillPatternBackground". But they didn't work. Is there a way to achieve it in ngl?

Thanks,
Lixu

Raise warning 'tmEqualizeXYSizes ' when plotting wrfout file

When I was plotting my wrfout file by using an example program: wrf1.py on PyNGL website (https://www.pyngl.ucar.edu/Examples/Scripts/wrf1.py), I encountered the warning: 'warning:tmEqualizeXYSizes is not a valid resource in contour.PlotManager at this time'.

I think this warning appears when I get lon and lat from wrfout file and set them to sfXArray and sfYArray. (This is not sure but seems true.)

Judging from ncl-talk, this problem seems not to be fixed for a long time.

The best choice is to fix it, but I can't. So, I want to avoid this warning by setting like 'warning verbose = False'.

Is There any setting like 'verbose = False' in PyNGL or other methods avoid tmEqualizeXYSizes warning?
Give me some idea, ty :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.