PyNGL and PyNIO tutorialThis tutorial is a step-by-step guide to PyNGL and PyNIO, introducing new features and concepts through a series of example Python scripts. This section works best if you read through these examples in order, since new concepts are documented only in the example where they are first introduced.
Each example, described below, begins with a short description of that example followed by images of the graphical output, followed by the PyNGL/PyNIO code used to generate the output (with line numbers), followed by a line-by-line description of the code.
Note: Concepts that are used repeatedly in the examples will not be described in every example, so it's important to read them in order. Because of this, not every line of every example will be documented; only those lines that introduce new concepts or that are worth repeating will be described.
|Example 1||This example introduces the basics of PyNGL, like how to begin and end a PyNGL script, how to create and initialize variables, how to create and draw XY plots, and how to set resources to change the look of the XY plots. It also shows how to read data from an ASCII file.|
|Example 2||This example shows how to use PyNIO to read data from a netCDF file, how to change the color map, how to create and draw contour plots, how to print variables, and how to write data to an ASCII file.|
|Example 3||This example shows how to read data from a netCDF file, how to change the color map, and how to create and draw vector plots. It also discusses the concept of having missing values in your data.|
|Example 4||This example shows how to retrieve information about and read data from a GRIB file. It also shows how to use stride values to select part of an array, how to retrieve resource values, and how to create and draw streamline plots.|
|Example 5||This example reads data from a netCDF file and shows how to retrieve the current color map and change its values, how to overlay contour plots on various map projections, how to fill certain contour levels, and how to draw text strings anywhere you want.|
|Example 6||This example reads data from a netCDF file, and shows how to overlay vector plots on various map projections, how to thin your vector data, and how to increase the size of your plots.|
|Example 7||This example shows how to use Fitgrid to do interpolations, how to draw two XY plots in the same frame, and how to use text, polyline, and polymarker procedures to draw text, lines, and markers anywhere on your frame.|
|Example 8||This example reads data from an ASCII file, and shows how to use Natgrid to interpolate randomly-spaced 2-dimensional coordinates with functional values to a user-defined 2-dimensional grid, how to open three different types of workstations, and how to swap dimensions in a multi-dimensioned array. It creates and draws a contour plot and an XY plot to an X11 window, an NCGM, a PostScript file, and a PDF file. It also shows how to use a resource file to set all the fonts in the plot to "Times-Roman".|
|Example 9||This example shows how to use Numerical Python functions for doing averaging and masking, how to set resources after a plot has been created, and how to do a 12-frame contour animation. This example uses an extensive resource file.|
|Example 10||This example shows how to create a publication-quality XY plot, and how to use text function codes to get super/subscripting and line feeds in your text strings.|
|Example 11||This example reads data from an ASCII file and creates both a contour plot and an XY plot. It shows how to have different scales on your Y axis in your contour plot (including changing one of the scales to "log"), how to define your own tick mark labels, and how to retrieve your contour levels and then fill them according to what ranges they fall in.|