Skip to content

Commit

Permalink
Merge PR #270 (Fix issues in regridding; prevent double-flipping )
Browse files Browse the repository at this point in the history
This merge brings PR #270 (Fix several issues in file regridding;
Also prevent double-flipping of vertical indices, by @yantosca) into
the GCPy 1.4.0 development stream.

This PR adds the following updates & fixes:

1. Routine rename_and_flip_gchp_rst_vars.py now uses inquiry function
   is_cubed_sphere_rst_grid internally. If the data is on the GCHP
   checkpoint/restart grid, then data variables will be renamed
   according to GCHP conventions and vertical levels will be flipped
   so that it is positive down. Otherwise the original data will
   be returned unchanged. This was necessary to prevent a bug in
   which vertical levels were flipped twice.

2. Added the boolean argument gchp_indices to routines get_ilev_coords
   and get_lev_coords. If true, then the coordinates will be returned as
   indices (e.g. 1..72), which is used for the GCHP level dimension.

3. Fixed several logic issues in file_regrid.py (especially related
   to vertical level indexing.

4. Fixed several issues with command-line arguments.  Renamed Python
   arguments to match the command-line arguments.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
  • Loading branch information
yantosca committed Oct 24, 2023
2 parents b021091 + 1cbc921 commit 90b3b68
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 205 deletions.
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 @@ -52,7 +52,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 @@ -37,8 +37,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

0 comments on commit 90b3b68

Please sign in to comment.