gcpy.examples.timeseries.plot_timeseries

Example of plotting timeseries data from GEOS-Chem and saving the output to a PDF file. You can modify this for your particular diagnostic output. This also contains a good overview of

This example script creates a PDF file with 2 pages.

Page 1:

O3 from the first model layer (from the “SpeciesConc” diagnostic collection is) plotted in blue.

O3 at 10 meter height (from the “SpeciesConc_10m” diagnostic collection) is plotted in red.

Page 2:

HNO3 from the first model layer (from the SpeciesConc diagnostic collection is) plotted in blue.

HNO3 at 10 meter height (from the SpeciesConc_10m diagnostic collection) is plotted in red.

You can of course modify this for your own particular applications.

Examples

  1. Copy this file to a different folder and navigate to that folder.

  2. Edit file paths, collection names, and coordinates in the main() routine.

  3. Run the following commands.

    $ conda activate gcpy_env
    (gcpy_env) $ ./plot_timeseries.py
    

References

Author: Bob Yantosca (GitHub: @yantosca), 23 Aug 2019

Functions

find_files_in_dir(path, substrs)

Returns a list of all files in a directory that match one or more substrings.

find_value_index(seq, val)

Finds the index of a numpy array that is close to a value.

main()

Main program.

plot_timeseries_data(ds, site_coords)

Plots a timseries of data at a given (lat,lon) location.

read_geoschem_data(path, collections)

Returns an xarray Dataset containing timeseries data.

gcpy.examples.timeseries.plot_timeseries.find_files_in_dir(path, substrs)[source]

Returns a list of all files in a directory that match one or more substrings.

Parameters:
  • path (str) – Path to the directory in which to search for files.

  • substrs (list of str) – List of substrings used in the search for files.

Returns:

file_list – List of files in the directory (specified by path) that match all substrings (specified in substrs).

Return type:

list of str

gcpy.examples.timeseries.plot_timeseries.find_value_index(seq, val)[source]

Finds the index of a numpy array that is close to a value.

Parameters:
  • seq (numpy ndarray) – An array of numeric values.

  • val (number) – The value to search for in seq.

Returns:

result – The index of seq that has a value closest to val.

Return type:

integer

gcpy.examples.timeseries.plot_timeseries.read_geoschem_data(path, collections)[source]

Returns an xarray Dataset containing timeseries data.

Parameters:
  • path (str) – Directory path where GEOS-Chem diagnostic output files may be found.

  • collections (list of str) – List of GEOS-Chem collections. Files for these collections will be read into the xarray Dataset.

Returns:

ds – A Dataset object containing the GEOS-Chem diagnostic output corresponding to the collections that were specified.

Return type:

xarray Dataset

gcpy.examples.timeseries.plot_timeseries.plot_timeseries_data(ds, site_coords)[source]

Plots a timseries of data at a given (lat,lon) location.

Parameters:
  • ds (xarray Dataset) – Dataset containing GEOS-Chem timeseries data.

  • site_coords (tuple) – Contains the coordinate (lat, lon) of a site location at which the timeseries data will be plotted.

gcpy.examples.timeseries.plot_timeseries.main()[source]

Main program.