-
Notifications
You must be signed in to change notification settings - Fork 36
Timeseries Plotting Tutorial
barronh edited this page Apr 20, 2016
·
4 revisions
Below are two methods for making time series plots. The first is in the python environment and the second is from the command line interface. These tutorials show work with CMAQ, but can easily be modified for CAMx or GEOS-Chem (see [modifications](Tutorial Modifications))
# input must exist on your machine
inpath = '/path/to/inputfile'
# import plotting library to save figures
from matplotlib import pyplot as plt
# import NetCDF Processing loading functions
from PseudoNetCDF.pncparse import pncparse
# import coordinate processing functions
from PseudoNetCDF.coordutil import gettimes
# Read in all inputs with the following options
# returns all files and an archive of arguments (including defaults)
# implicit option '-f', 'netcdf' opens the file as netcdf (other -f options "bpch", "uamiv")
# option '--from-conv', 'ioapi' uses the ioapi meta-data to derive latitudes, longitudes, and time variables
# option '--slice', 'LAY,0' takes the first layer
# option '--reduce', 'ROW,mean' takes the average over rows (use any function in the numpy library)
# option '--reduce', 'COL,mean' takes the average over columns (use any function in the numpy library)
infiles, args = pncparse(args = [inpath, '--from-conv', 'ioapi', '--variables', 'O3', '--slice', 'LAY,0', '--reduce', 'ROW,mean', '--reduce', 'COL,mean'])
infile = infiles[0]
times = gettimes(infile)
# Remove singleton dimensions LAY,ROW,COL
infile.variables['O3'][:, 0, 0, 0]
plt.plot(times, O3, ls = '-', color = 'k', linewidth = 2)
# uncomment out the next line to add observations
# you must define obstimes and obsO3
#plt.plot(obstimes, obsO3, ls = 'none', marker = 'o', color = 'k', linewidth = 2)
plt.xlabel('Time (UTC)')
plt.ylabel('Ozone (ppm)')
plt.savefig('ozone_ts.png')
This method uses the default script for time series. The color of figures is controlled by the image.cmap.
pncts.py --matplotlibrc="image.cmap=Greys" --remove-singleton=ROW,COL,LAY -v O3 -r COL,mean -r ROW,mean /path/to/inputfile outputroot