A simple plotting example for unstructured grid
Output from MUSICAv0 is on an unstructured grid (an unsorted vector of columns for defined latitude-longitude coordinates) making it difficult to visualize in standard plotting frameworks. NCAR has developed a small set of routines in Python as Jupyter notebooks that can be used for plotting results. A simple plotting routine with some examples is shown here:
Using a pre-defined python module for plotting
For people who are not familiar with python, we have developed a python module that people can easily import and plot CAM-chem results (either structured or unstructured) with a single line command. First, download this python module for plotting (you may need to "right click" on the link and choose "Save link as..." from the menu, or find it here: https://github.com/NCAR/CAM-chem/blob/main/docs_sphinx/examples/functions/Plot_2D.py) and put it in your directory. If you are new to python, you need to know how to import a library, and you have to install required libraries for plotting (xarray, matplotlib, cartopy, etc.). See this python tutorial (or contents on this webpage) if you are new to python.
If you want reproduce the example plots below, download these files:
- structured grid (0.95 x 1.25) model output (sample.nc)
- unstructured grid (ne30x16) model output (sample_se.nc)
- SCRIP grid file for unstructured grid (sample_se_scrip.nc)
Of course, you can use your own CAM-chem history files instead of example files, unless you want to get the exactly same example plots below for checking.
NOTE: As of 10-MAR-2021, the Plot_2D script will be maintained in CAM-chem python Github. We shall keep examples here for reference, as those could still be helpful for beginners.
NOTE 2: As of 04-OCT-2021, the Plot_2D script can be installed using the PyPI package: https://pypi.org/project/vivaldi-a/
First, you need to import built-in python libraries and Plot_2D module you just downloaded. Make sure Plot_2D.py file is in your directory.
Let's read the model output files using the xarray module.
As a side note, you can check the variables in the file like below.
To demonstrate the examples below, you will need to use Jupyter notebook. If you are using the local machine, Jupyter notebook is OK to use (https://jupyter.org/). However, if you use a separate server that needs remote access, you may want to install JupyterLab (https://jupyterlab.readthedocs.io/en/stable/) to use Jupyter notebook. You can still use Jupyter notebook on your server but it could be slow. If you are using Cheyenne or Casper machines, Jupyterhub is another option you can use (https://www2.cisl.ucar.edu/resources/jupyterhub-ncar). Jupyterhub is the easiest option you can start with if you are new to python, because you don't have to install python and required packages (already installed).
A simple plot
Just pass your surface CO. "-1" corresponds to the surface level as CESM writes the output from the top of the atmosphere to the surface.
You can simply change the colormap with the "cmap" keyword. Check out this website for built-in colormaps in matplotlib python library.
Multiplying scale factors
You can simply multiply any numbers (1e9 in the example below) in the input value.
Pretty tick option
If you set pretty_tick=True, the routine will automatically find the colorbar ticks like below.
Plotting a region of interest only
You can set "lon_range" and "lat_range" keywords to plot a region.
Setting maximum value for the plot
Use "cmax" keyword to force the maximum value to what you want.
Adding state/province boundary lines
You can also easily add state boundary lines with the "state" keyword.
Adding a title in the plot
You can also add a title in the plot with a title keyword.
Plotting on unstructured grid
You can use exactly the same function and interface to plot unstructured grid model output.
The only difference is you have to specify the location of corresponding SCRIP grid file.
Adding a unit
You can add a unit with a unit keyword.
Adjusting unit position can also be done using the "unit_offset" keyword.
For advanced users: Adding more custom things you want
If you are an experienced user, you can add anything you want by getting an instance. As an example, we provide how to add a location point on top of the plot. Note "p = Plot_2D(...)" instead of "Plot_2D(...)", it creates a new instance of the class and assigns this object to the local variable "p".
More custom options and keywords
There are a lot of custom options you can explore, such as changing map projections, grid line settings, coast/country/state lines, passing parent axes for multi-plot, colorbar orientation and size, etc. For more information, type "Plot_2D?" in your python or jupyter notebook shell prompt. You will find detailed information of each keyword like below.