Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several issues in file regridding; Also prevent double-flipping of vertical indices #270

Merged
merged 7 commits into from
Oct 24, 2023
30 changes: 12 additions & 18 deletions gcpy/benchmark_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3016,13 +3016,11 @@ def make_benchmark_mass_tables(
# Update GCHP restart dataset (if any)
# ==================================================================

# Ref
if any(v.startswith("SPC_") for v in refds.data_vars.keys()):
refds = util.rename_and_flip_gchp_rst_vars(refds)

# Dev
if any(v.startswith("SPC_") for v in devds.data_vars.keys()):
devds = util.rename_and_flip_gchp_rst_vars(devds)
# If the data is from a GCHP restart file, rename variables and
# flip levels to match the GEOS-Chem Classic naming and level
# conventions. Otherwise no changes will be made.
refds = util.rename_and_flip_gchp_rst_vars(refds)
devds = util.rename_and_flip_gchp_rst_vars(devds)

# ==================================================================
# Make sure that all necessary meteorological variables are found
Expand Down Expand Up @@ -3288,17 +3286,13 @@ def make_benchmark_mass_accumulation_tables(
# Update GCHP restart dataset if needed
# ==================================================================

# Ref
if any(v.startswith("SPC_") for v in refSds.data_vars.keys()):
refSds = util.rename_and_flip_gchp_rst_vars(refSds)
if any(v.startswith("SPC_") for v in refEds.data_vars.keys()):
refEds = util.rename_and_flip_gchp_rst_vars(refEds)

# Dev
if any(v.startswith("SPC_") for v in devSds.data_vars.keys()):
devSds = util.rename_and_flip_gchp_rst_vars(devSds)
if any(v.startswith("SPC_") for v in devEds.data_vars.keys()):
devEds = util.rename_and_flip_gchp_rst_vars(devEds)
# If the data is from a GCHP restart file, rename variables and
# flip levels to match the GEOS-Chem Classic naming and level
# conventions. Otherwise no changes will be made.
refSds = util.rename_and_flip_gchp_rst_vars(refSds)
refEds = util.rename_and_flip_gchp_rst_vars(refEds)
devSds = util.rename_and_flip_gchp_rst_vars(devSds)
devEds = util.rename_and_flip_gchp_rst_vars(devEds)

# Add area to start restart dataset if area in end but not start
# Need to consider area variable names used in both GC-Classic and GCHP
Expand Down
16 changes: 15 additions & 1 deletion gcpy/examples/diagnostics/compare_diags.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def read_data(config):
msg = "Error reading " + dev_file
raise Exception(msg) from exc

# Special handling for GCHP restart files
# If the data is from a GCHP restart file, rename variables and
# flip levels to match the GEOS-Chem Classic naming and level
# conventions. Otherwise no changes will be made.
refdata = util.rename_and_flip_gchp_rst_vars(refdata)
devdata = util.rename_and_flip_gchp_rst_vars(devdata)

Expand Down Expand Up @@ -261,6 +263,14 @@ def compare_data(config, data):
varlist_level = [v for v in varlist_level if v in restrict_vars]
varlist_zonal = [v for v in varlist_zonal if v in restrict_vars]

# Determine if we need to flip levels in the vertical
flip_ref = False
flip_dev = False
if "flip_levels" in config["data"]["ref"]:
flip_ref = config["data"]["ref"]["flip_levels"]
if "flip_levels" in config["data"]["dev"]:
flip_dev = config["data"]["dev"]["flip_levels"]

# ==================================================================
# Generate the single level comparison plot
# ==================================================================
Expand All @@ -275,6 +285,8 @@ def compare_data(config, data):
config["data"]["ref"]["label"],
devdata,
config["data"]["dev"]["label"],
flip_ref=flip_ref,
flip_dev=flip_dev,
ilev=config["options"]["level_plot"]["level_to_plot"],
varlist=varlist_level,
pdfname=pdfname,
Expand All @@ -296,6 +308,8 @@ def compare_data(config, data):
config["data"]["ref"]["label"],
devdata,
config["data"]["dev"]["label"],
flip_ref=flip_ref,
flip_dev=flip_dev,
varlist=varlist_zonal,
pdfname=pdfname,
weightsdir=config["paths"]["weights_dir"],
Expand Down
4 changes: 3 additions & 1 deletion gcpy/examples/plotting/plot_comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def plot_comparisons(
drop_variables=skip_these_vars
)

# Special handling is needed for GCHP restart files
# If the data is from a GCHP restart file, rename variables and
# flip levels to match the GEOS-Chem Classic naming and level
# conventions. Otherwise no changes will be made.
ref_ds = rename_and_flip_gchp_rst_vars(ref_ds)
dev_ds = rename_and_flip_gchp_rst_vars(dev_ds)

Expand Down
7 changes: 5 additions & 2 deletions gcpy/examples/plotting/plot_single_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ def plot_single_panel(infile, varname, level):
# xarray allows us to read in any NetCDF file
dset = xr.open_dataset(infile)

# Special handling if the file is a GCHP restart file
dset = rename_and_flip_gchp_rst_vars(dset)
# If the data is from a GCHP restart file, rename variables and
# flip levels to match the GEOS-Chem Classic naming and level
# conventions. Otherwise no changes will be made.
ref_ds = rename_and_flip_gchp_rst_vars(ref_ds)
dev_ds = rename_and_flip_gchp_rst_vars(dev_ds)

# You can easily view the variables available for plotting
# using xarray. Each of these variables has its own xarray
Expand Down
Loading