PyNGL

Note

PyNGL and PyNIO have been set to ‘maintenence mode’, which means that no further developments will be made. The focus of the development team is now on geocat-comp and geocat-viz.

NCAR/GEOCAT: November 2020 Update

https://geocat.ucar.edu/blog/2020/11/11/November-2020-update

The Python language module PyNGL (pronounced “pingle”) is used to visualize scientific data, with an emphasis on high quality 2D visualizations. It is based on the capabilities and functionality of NCL. In addition the PyNIO Python module is used for reading and writing files in several different data formats, including netCDF, netCDF 4, GRIB1, GRIB2, HDF 4, HDF-EOS 2 and HDF-EOS5, and CCM history files, similar to the NCL file input/output functionality.

PyNGL and PyNIO provide Python interfaces to most of the NCL functionality. A knowledge of NCL would give you a leg up in using these modules, but they are meant to be independent from NCL and used as a stand-alone suite of Python functions.

PyNGL/PyNIO is free available: http://www.pyngl.ucar.edu/index.shtml

Most examples use the PyNIO module to read/write data from/to a file independant of the file type but in the future we will use xarray to read NetCDF files, ECMWF’s cfgrib to read GRIB files, and pyshp to read shapefiles.


How to use the example scripts at DKRZ

Copy the example script you want to use to your work space. Not all example data sets are available but most files are stored in

/work/kv0653/NCL/data_examples

Note

PyNio works with Python 2 only. On Mistral you have to load the python module first.

Python 2.7

module load python/2.7-ve0

If you use Python 3 you should use xarray instead of PyNio.

Python 3.x

module load python3/unstable

Modify and execute the script:

python <script name>

For example

python PyNGL_unstructured_ICON_triangles.py

Note

DKRZ has created a GitHub Python repository named PyEarthScience that contains Visualization, Analysis and IO example scripts. The sense of the repository is to establish a kind of a platform for Earth scientists for searching and representing Python scripts and packages using PyNGL/PYNIO, matplotlib, cartopy, xarray etc. The repository is still in progress. https://github.com/KMFleischer/PyEarthScience/

Categories

Maps

map resources, functions, sub-regions

XY-plots

1D data line plots, timeseries, scatter plots, statistics

Contours

2D data line, color fill (shaded), fill pattern, overlays

Vectors

2D vector data, e.g. wind components uv

Slice plots

contour plot of a vertical slice

Overlays

contour line on filled contour plot, vector on contours, different grid resolutions

Panel plots

multiple plots in one frame (page)

Grids

rectilinear, curvilinear, unstructured grids

Special plots

some special plots

Masking

mask the data

Shapefiles

country outlines, compute temperature means of counties

Regridding

regrid curvilinear to rectilinear, regrid to higher resolution

xarray / PyNIO

example scripts using xarray to read data files

Maps

image0 Map using Orthographic projection

PyNGL map settings w400

Map plot with colored land and ocean

image2 Color fill country area by value

PyNGL map tickmarks HighRes Map tickmarks with HighRes

image3 Map tickmarks with gridlines

image4 Map tickmarks for Robinson projection

image100 Map tickmarks for Lambert Conformal Projection

image102 Mask Lambert Conformal Projection

image5

Up

XY-plots

Simple xy-plot Simple xy-plot

PyNGL xy-plot w400 XY-plots drawing 3 lines

image7 Bar chart plot

image8 Scatter plot

image9 Scatter plot with regression line

Box-Whisker plot Compute de-trended variable data and add a Box-Whisker plot

image10 Regression and running mean using numpy

Up

Contours

PyNGL rectilinear grid contour plot w400 Contour plot of rectilinear grid

PyNGL curvilinear grid contour plot w400 Contour plot of curvilinear data

image13 Overlay filled contour plot on polar stereographic map

PyNGL unstructured data contour plot w400 Contour plot of unstructured data (ICON)

PyNGL unstructured ICON triangles w400 Contour plot of unstructured data showing the edges (run time 4.1s)

PyNGL unstructured ICON triangles projections w400 PyNGL unstructured ICON triangles 2 projections w400 ICON plot with Mollweide and Winkel Triple projection

PyNGL Hovmueller plot Default Hovmueller plot

PyNGL Hovmueller plot filled Color filled Hovmueller plot

Up

Vectors

image19 Vectors on a map

PyNGL rectilinear vector 1 w400 PyNGL rectilinear vector 2 w400 Vector plots colored by second variable

image22 Streamline plot

Up

Slice plots

PyNGL rectilinear slice w400 Slice plot

Up

Overlays

image24 Overlay plot

Up

Panel plots

PyNGL panel plot w400

Panel plot 3rows x 1 column

image26

Panel plot without Ngl.panel. This example uses the vp-resources instead.

Up

Grids

PyNGL curvilinear CORDEX

Plot curvilinear grid (python3)

Up

Special plots

image27

Overlay two grids with different resolutions

image28

Scatter plot with two attached histograms

image29

Draw filled circles instead of grid cells. The size depends on a quality value

image30

image31

PyNGL Hovmueller plot Default Hovmueller plot

PyNGL Hovmueller plot filled Color filled Hovmueller plot

image33 Location of stations with marker

image34

Up

Masking

image35

Mask the data using area specifiers

Up

Shapefiles

image36

Plot shapefile contents

Up

Regridding

image37 Regrid from coarse to higher resolution grid

Up

xarray / PyNIO

image38

Contour plot

image39

Timeseries

Demonstrate the use of xarray to read the content of a netCDF file

Demonstrate the use of PyNio to read the content of a netCDF file

Demonstrate the use of xarray to read the content of a GRIB file

Demonstrate the use of PyNio to read the content of a GRIB file

Up