Installing Python, Python modules, and development version of NCL

[go back to main page]

The NCL / Python Tutorial at the 17th Annual WRF Users' Workshop will mostly be focused on NCL, but we will also use Jupyter Notebooks to do some demos on using Python for reading WRF output files, calculating diagnostics, and plotting results.

If you are interested in learning more about Python or you want to follow along with the Jupyter Notebook demos, then you will need to install Python itself and some Python modules on your laptop before the tutorial starts. These installations can take awhile if you have a slow internet connection.

These are the four steps:

  1. Install Python and conda
  2. Create conda environment with the required modules
  3. Activate conda environment
  4. Test your conda enviornment

1. Install Python and conda

Install miniconda, which gives you both Python and conda. Conda is a package management system for installing Python modules.

2. Create conda environment with the required modules

These instructions show how to install the suggested packages in a conda environment called "wrf_tutorial".

Not all packages are listed explicitly, because some of them get installed as dependencies of others (for example, "numpy" will get installed when you asked for "jupyter").

To create a conda environment and install the desired packages, type the following in a UNIX terminal window:

conda create -n wrf_tutorial -c ncar -c khallock -c bladwig pynio basemap jupyter pyngl wrf-python xarray

This will cause quite a few packages to be installed, because many of these packages depend on other packages. As an added bonus, the "pyngl" package will also cause a development version of "NCL" to be installed.

3. Activate conda environment

Once the conda environment is created, you must activate the "wrf_tutorial" environment:

source activate wrf_tutorial

You can continue to install other packages in this environment, for example:

conda install netcdf4

For more information about conda environments, see the Managing environments document put out by the conda folks.

4. Test your conda environment

Test whether your various Python modules installed successfully by typing "python" in a UNIX terminal window, and loading the desired pacakge with "import".

For example, here's how to import numpy and PyNIO and print their versions:

import numpy,Nio,Ngl
numpy.__version__
Nio.__version__
Ngl.__version__
quit

Python modules information

Below is a list of Python modules we will be using in the tutorial.

Jupyter notebook - (required for this tutorial)

We will be using Jupyter notebook in our Python demos. This is a powerful documentation and teaching tool that allows instructors and students to easily change and execute Python code snippets.

We will provide students with Jupyter Notebook files that they can run from their own machines.

numpy - (required for this tutorial)

Numpy is a required package if you are going to do any kind of scientific computing with Python.

PyNIO - (required for this tutorial)

PyNIO is a Python module built on top of NCL's file I/O library for opening NetCDF, GRIB1, GRIB2, HDF4, HDF5, HDF-EOS2, HDF-EOS5, and shapefiles. We will use this module to demonstrate opening WRF output files, and adding shapefile outlines to WRF graphics.

PyNGL - (optional for this tutorial)

PyNGL is a Python module based on NCL's 2D graphics capabilities. It uses the same "graphical resources" as NCL for creating customized graphics.

matplotlib and basemap (optional, but useful, for this tutorial)

Matplotlib is for generating 2D graphics (like contours or XY plots), and basemap works with matplotlib to plot data over maps.

netcdf4-python (optional for this tutorial)

netcdf4-python is a Python module for opening NetCDF files. It has full support for NetCDF4 files.

WRF-Python (this is a new package still under development)

WRF-Python is a Python module that is still in development. It will provide a full implemention of all the WRF-NCL diagnostics available via wrf_user_getvar.