Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Environment files `docs/environment_files/gcpy_requirements.txt` and `docs/environment_files/read_the_docs_requirements.txt`
- New benchmark script `gcpy/benchmark/modules/benchmark_models_vs_sondes.py`
- Added fixed level budget diagnostic to budget operations table
- Function `rename_speciesconc_to_speciesconcvv` in `gcpy/benchmark/modules/benchmark_utils.py`
- Function `copy_file_to_dir` in `gcpy/util.py`. This is a wrapper for `shutil.copyfile`.

### Changed
- Bump pip from 23.2.1 to 23.3 (dependabot suggested this)
Expand All @@ -33,15 +35,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Refactored `get_vert_grid.py` (in `gcpy/grid.py`) to accept the `p_sfc` argument; Also never-nested the if-block logic.
- `benchmark_slurm.sh` script now saves output to a log file with the same base name as the YAML config file
- `benchmark_models_vs_obs.py` now reads the observational data paths and metadata from `1yr_fullchem_benchmark.yml`
- Moved benchmark code from `gcpy/` to `gcpy/benchmark/modules/`
- Benchmark functions now call `rename_speciesconc_to_speciesconcvv`
- Create radionuclide, STE flux, and mass conservation tables for Ref and Dev versions in TransportTracers benchmarks
- Use new function `copy_file_to_dir` to copy the benchmark script and configuration file to the benchmark results folders

### Fixed
- CS inquiry functions in `gcpy/cstools.py` now work properly for `xr.Dataset` and `xr.DataArray` objects
- Prevent an import error by using `seaborn-v0_8-darkgrid` in`gcpy/benchmark/modules/benchmark_models_vs_obs.py`
- `gcpy/file_regrid.py` now creates GCHP files with `DELP_DRY` instead of `DELPDRY`
- Fixed bugs in GCHP vs GCHP sections of 1-yr benchmark run scripts to allow comparison of GCHP runs with different grid resolutions
- Fixed silent bug in transport tracer benchmark GCC vs GCHP mass tables preventing them from being generated
- Fixed silent bug in transport tracer benchmark GCC vs GCHP mass
tables preventi ng them from being generated
- Import error in `gcpy/examples/diagnostics/compare_diags.py`
- Added missing `n_cores` to `gcpy/examples/diagnostics/compare_diags.yml`
- Add `docs/requirements.txt` symbolic link to `docs/environment_files/read_the_docs_requirements.txt` for RTD builds

### Removed
- Example script `gcpy/examples/plotting/mda8_o3_timeseries.py`
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
6 changes: 0 additions & 6 deletions gcpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@
from .examples import *

from .append_grid_corners import *
from .benchmark_funcs import *
from .budget_ox import *
from .budget_tt import *
from .constants import *
from .cstools import *
from .date_time import *
from .file_regrid import *
from .grid import *
from .grid_stretching_transforms import *
from .mean_oh_from_logs import *
from .oh_metrics import *
from .plot import *
from .raveller_1D import *
from .regrid import *
from .regrid_restart_file import *
from .ste_flux import *
from .units import *
from .util import *
from ._version import *
2 changes: 1 addition & 1 deletion gcpy/benchmark/benchmark_slurm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ config="1yr_fullchem_benchmark.yml"
#config="1yr_tt_benchmark.yml"

# Call the run_benchmark script to make the plots
python -m gcpy.benchmark.run_benchmark "${config}" > "${config/.yml/.log}: 2>&1
python -m gcpy.benchmark.run_benchmark "${config}" > "${config/.yml/.log}" 2>&1

# Turn off python environment
mamba deactivate
Expand Down
File renamed without changes.
14 changes: 8 additions & 6 deletions gcpy/benchmark/modules/benchmark_drydep.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import numpy as np
from gcpy import util
from gcpy.plot.compare_single_level import compare_single_level
import gcpy.benchmark.modules.benchmark_utils as bmk_util
from gcpy.benchmark.modules.benchmark_utils import \
get_lumped_species_definitions, make_output_dir, \
pdf_filename, print_sigdiffs, read_ref_and_dev

# Suppress numpy divide by zero warnings to prevent output spam
np.seterr(divide="ignore", invalid="ignore")
Expand Down Expand Up @@ -90,23 +92,23 @@ def make_benchmark_drydep_plots(
"""

# Create directory for plots (if it doesn't exist)
dst = bmk_util.make_output_dir(
dst = make_output_dir(
dst,
collection,
subdst,
overwrite=overwrite,
)

# Read data
refdata, devdata = bmk_util.read_ref_and_dev(
refdata, devdata = read_ref_and_dev(
ref,
dev,
time_mean=time_mean
)

# Get common variables between Ref and Dev
if varlist is None:
varlist = bmk_util.get_common_varnames(
varlist = get_common_varnames(
refdata,
devdata,
prefix="DryDepVel_",
Expand All @@ -115,7 +117,7 @@ def make_benchmark_drydep_plots(

# Create surface plots
sigdiff_list = []
pdfname = bmk_util.pdf_filename(
pdfname = pdf_filename(
dst,
collection,
subdst,
Expand Down Expand Up @@ -145,7 +147,7 @@ def make_benchmark_drydep_plots(
)

# Write significant differences to file (if there are any)
bmk_util.print_sigdiffs(
print_sigdiffs(
sigdiff_files,
sigdiff_list,
sigdiff_type="sfc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
from gcpy.constants import COL_WIDTH, MW_AIR_g, skip_these_vars, TABLE_WIDTH
from gcpy.plot.compare_single_level import compare_single_level
from gcpy.plot.compare_zonal_mean import compare_zonal_mean
from gcpy.benchmark.modules.benchmark_utils import \
AOD_SPC, EMISSION_SPC, EMISSION_INV, add_lumped_species_to_dataset, \
archive_lumped_species_definitions, get_species_categories, \
archive_species_categories, rename_speciesconc_to_speciesconcvv

# Suppress numpy divide by zero warnings to prevent output spam
np.seterr(divide="ignore", invalid="ignore")

# YAML files
AOD_SPC = "aod_species.yml"
EMISSION_SPC = "emission_species.yml"
EMISSION_INV = "emission_inventories.yml"


def create_total_emissions_table(
refdata,
Expand Down Expand Up @@ -1031,14 +1030,8 @@ def make_benchmark_conc_plots(

# Rename SpeciesConc_ to SpeciesConcVV_ for consistency with new
# naming introduced in GEOS-Chem 14.1.0
for v in refds.data_vars.keys():
if v.startswith('SpeciesConc_'):
spc = v.replace('SpeciesConc_', '')
refds = refds.rename({v: 'SpeciesConcVV_' + spc})
for v in devds.data_vars.keys():
if v.startswith('SpeciesConc_'):
spc = v.replace('SpeciesConc_', '')
devds = devds.rename({v: 'SpeciesConcVV_' + spc})
refds = rename_speciesconc_to_speciesconcvv(refds)
devds = rename_speciesconc_to_speciesconcvv(devds)

# -----------------------------------------------------------------
# Kludge, rename wrong variable name
Expand Down Expand Up @@ -1229,22 +1222,22 @@ def make_benchmark_conc_plots(
print("\nComputing lumped species for full chemistry benchmark")

print("-->Adding lumped species to ref dataset")
refds = util.add_lumped_species_to_dataset(refds)
refds = add_lumped_species_to_dataset(refds)

print("-->Adding lumped species to dev dataset")
devds = util.add_lumped_species_to_dataset(devds)
devds = add_lumped_species_to_dataset(devds)

if diff_of_diffs:
print("-->Adding lumped species to dev datasets")
second_refds = util.add_lumped_species_to_dataset(second_refds)
second_devds = util.add_lumped_species_to_dataset(second_devds)
second_refds = add_lumped_species_to_dataset(second_refds)
second_devds = add_lumped_species_to_dataset(second_devds)

util.archive_lumped_species_definitions(dst)
archive_lumped_species_definitions(dst)
print("Lumped species computation complete.\n")

# Get the list of species categories
catdict = util.get_species_categories(benchmark_type)
util.archive_species_categories(dst)
catdict = get_species_categories(benchmark_type)
archive_species_categories(dst)

# Make sure that Ref and Dev datasets have the same variables.
# Variables that are in Ref but not in Dev will be added to Dev
Expand Down Expand Up @@ -1618,7 +1611,7 @@ def make_benchmark_emis_plots(
Set this flag to True to separate plots into PDF files
according to the benchmark species categories (e.g. Oxidants,
Aerosols, Nitrogen, etc.) These categories are specified
in the YAML file benchmark_species.yml.
in the YAML file benchmark_categories.yml.
Default value: False
plot_by_hco_cat: bool
Set this flag to True to separate plots into PDF files
Expand Down Expand Up @@ -1898,7 +1891,7 @@ def createfile_hco_cat(c):
# ==================================================================
if plot_by_spc_cat:

catdict = util.get_species_categories(benchmark_type)
catdict = get_species_categories(benchmark_type)
# in case any emissions are skipped (for use in nested pdf bookmarks)
warninglist = ([])
# for checking if emissions species not defined in benchmark category
Expand Down Expand Up @@ -4037,10 +4030,11 @@ def make_benchmark_aerosol_tables(
mw["Air"] = MW_AIR_g

# Get the list of relevant AOD diagnostics from a YAML file
ifile= AOD_SPC
aod = util.read_config_file(
os.path.join(
os.path.dirname(__file__),
"aod_species.yml"
ifile,
),
quiet=True
)
Expand Down Expand Up @@ -4085,10 +4079,7 @@ def make_benchmark_aerosol_tables(

# Rename SpeciesConc_ to SpeciesConcVV_ for consistency with new
# naming introduced in GEOS-Chem 14.1.0
for v in ds_spc.data_vars.keys():
if v.startswith('SpeciesConc_'):
spc = v.replace('SpeciesConc_', '')
ds_spc = ds_spc.rename({v: 'SpeciesConcVV_' + spc})
ds_spc = rename_speciesconc_to_speciesconcvv(ds_spc)

# Get troposphere mask
tropmask = get_troposphere_mask(ds_met)
Expand Down Expand Up @@ -4941,15 +4932,6 @@ def make_benchmark_mass_conservation_table(
Path names of restart files.
runstr: str
Name to put in the filename and header of the output file
refstr: str
A string to describe ref (e.g. version number)
dev: str
Path name of "Dev" (aka "Development") data set file.
The "Dev" data set will be compared against the "Ref" data set.
devmet: list of str
Path name of dev meteorology data set.
devstr: str
A string to describe dev (e.g. version number)

Keyword Args (optional):
dst: str
Expand Down Expand Up @@ -5074,7 +5056,7 @@ def make_benchmark_mass_conservation_table(
# Print masses to file
# ==================================================================
# Create file
outfilename = os.path.join(dst, "Passive_mass.txt")
outfilename = os.path.join(dst, f"Passive_mass.{runstr}.txt")

with open(outfilename, 'w') as f:
titlestr = ' Global Mass of Passive Tracer in ' + runstr + ' '
Expand Down
40 changes: 7 additions & 33 deletions gcpy/benchmark/modules/benchmark_models_vs_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from gcpy.util import verify_variable_type, dataset_reader, make_directory
from gcpy.cstools import extract_grid
from gcpy.grid import get_nearest_model_data
from gcpy.benchmark.modules.benchmark_utils import get_geoschem_level_metadata
from gcpy.benchmark.modules.benchmark_utils import \
get_geoschem_level_metadata, rename_speciesconc_to_speciesconcvv


def read_nas(
Expand Down Expand Up @@ -199,38 +200,11 @@ def read_model_data(
multi_files=True,
verbose=verbose,
)

# Set temporary variable name for use below
varname_tmp = varname

# First try reading the data as-is
try:
dataset = reader(
filepaths,
drop_variables=skip_these_vars,
data_vars=[varname_tmp]
).load()

# If we encounter a ValueError, it may be because the data is
# older # and may have e.g. SpeciesConc fields instead of
# SpeciesConcVV fields. Reset the varname_tmp and try again.
except ValueError:
varname_tmp = varname_tmp.replace("VV", "")
dataset = reader(
filepaths,
drop_variables=skip_these_vars,
data_vars=[varname_tmp]
).load()

# Rename to the original name to avid confusion with data
# from GEOS-Chem versions prior to 14.1.0
with xr.set_options(keep_attrs=True):
dataset = dataset.rename({varname_tmp: varname})

# If we fail again, then throw an error!
except [FileNotFoundError, OSError, IOError] as exc:
msg = f"get_model_data: Could not read Ref data for {varname}!"
raise exc(msg) from exc

# Read data and rename SpeciesConc_ to SpeciesConcVV_, if necessary
# (needed for backwards compatibility with older versions.)
dataset = reader(filepaths,drop_variables=skip_these_vars).load()
dataset = rename_speciesconc_to_speciesconcvv(dataset)

# Create a DataArray object and convert to ppbv (if necessary)
with xr.set_options(keep_attrs=True):
Expand Down
8 changes: 7 additions & 1 deletion gcpy/benchmark/modules/benchmark_models_vs_sondes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from gcpy.cstools import extract_grid
from gcpy.grid import get_nearest_model_data, get_vert_grid
from gcpy.util import make_directory, verify_variable_type
from gcpy.benchmark.modules.benchmark_utils import read_ref_and_dev
from gcpy.benchmark.modules.benchmark_utils import \
read_ref_and_dev, rename_speciesconc_to_speciesconcvv

# Tell matplotlib not to look for an X-window
os.environ["QT_QPA_PLATFORM"] = "offscreen"
Expand Down Expand Up @@ -42,6 +43,11 @@ def get_ref_and_dev_model_data(
multi_file=True
)

# Rename variables starting with "SpeciesConc_" to "SpeciesConcVV_",
# for backwards compatibility with GC versions prior to 14.1.0.
ref_data = rename_speciesconc_to_speciesconcvv(ref_data)
dev_data = rename_speciesconc_to_speciesconcvv(dev_data)

# Return the species of interest and convert to ppbv
return ref_data[varname]*1.0e9, dev_data[varname]*1.0e9

Expand Down
Loading