Plotting
This page describes in depth the general plotting capabilities of GCPy, including possible argument values for every plotting function.
For information about GCPy functions that are specific to the GEOS-Chem benchmark workflow, please see our Benchmarking chapter.
Six-panel comparison plots
Functions gcpy.plot.compare_single_level() and
gcpy.plot.compare_zonal_mean() generate six-panel plots
comparing each variable between two datasets. These plots can either
be saved to PDFs or generated sequentially for visualization in the
Matplotlib GUI using matplotlib.pyplot.show(). Each plot uses
data passed from a reference (Ref) dataset and a
development (Dev) dataset. Both functions share
significant structural overlap both in output appearance and code
implementation.
You can import these routines into your code with these statements:
from gcpy.plot.compare_single_level import compare_single_level
from gcpy.plot.compare_zonal_mean import compare_zonal_mean
Each panel has a title describing the type of panel, a colorbar for
the values plotted in that panel, and the units of the data plotted in
that panel. The upper two panels of each plot show actual values from
the Ref (left) and Dev (right) datasets for a
given variable. The middle two panels show the difference
(Dev - Ref) between the values in the Dev
dataset and the values in the Ref dataset. The left middle
panel uses a full dynamic color map, while the right middle panel caps
the color map at the 5th and 95th percentiles. The bottom two panels
show the ratio (Dev/Ref) between the values in the Dev
dataset and the values in the Ref Dataset. The left bottom panel uses
a full dynamic color map, while the right bottom panel caps the color
map at 0.5 and 2.0.
Function compare_single_level
This function generates a comparison plot such as:
For a list of input parameters, click on this link:
gcpy.plot.compare_single_level().
Function compare_zonal_mean
This function generates a comparison plot such as:
For a list of input parameters, click on this link:
gcpy.plot.compare_single_level().
Example script
Here is a basic script that calls both gcpy.plot.compare_zonal_mean() and
gcpy.plot.compare_single_level():
#!/usr/bin/env python
import xarray as xr
import matplotlib.pyplot as plt
from gcpy.plot.compare_single_level import compare_single_level
from gcpy.plot.compare_zonal_mean import compare_zonal_mean
file1 = '/path/to/ref'
file2 = '/path/to/dev'
ds1 = xr.open_dataset(file1)
ds2 = xr.open_dataset(file2)
compare_zonal_mean(ds1, 'Ref run', ds2, 'Dev run')
plt.show()
compare_single_level(ds1, 'Ref run', ds2, 'Dev run')
plt.show()
Single panel plots
Function gcpy.plot.single_panel() is used to create plots
containing only one panel of GEOS-Chem data. This function is used
within gcpy.plot.compare_single_level() and
gcpy.plot.compare_zonal_mean() to generate each panel plot. It
can also be called directly on its own to quickly plot GEOS-Chem data
in zonal mean or single level format.
The gcpy.plot.single_panel() function expects data with a 1-length
(or non-existent) T (time) dimension, as well as a 1-length
or non-existent Z (vertical level) dimension. It also
contains a few amenities to help with plotting GEOS-Chem data,
including automatic grid detection for lat/lon or standard
cubed-sphere xarray.DataArray()-s. You can also pass NumPy
arrays to plot, though you’ll need to manually pass grid info in this
case (with the gridtype, pedge, and
pedge_ind keyword arguments).
The sample script shown below shows how you can data at a single level
and timestep from an xarray.DataArray() object.
#!/usr/bin/env python
import xarray as xr
import matplotlib.pyplot as plt
from gcpy.plot.single_panel import single_panel
# Read data from a file into an xr.Dataset object
dset = xr.open_dataset('GEOSChem.SpeciesConc.20160701_0000z.nc4')
# Extract ozone (v/v) from the xr.Dataset object,
# for time=0 (aka first timestep) and lev=0 (aka surface)
sfc_o3 = dset['SpeciesConcVV_O3'].isel(time=0).isel(lev=0)
# Plot the data!
single_panel(sfc_o3)
plt.show()