Skip to content

Conversation

yantosca
Copy link
Contributor

@yantosca yantosca commented May 23, 2025

Name and Institution (Required)

Name: Bob Yantosca
Institution: Harvard + GCST

Describe the update

This is the companion PR to #361 by @nicodgomez. We have now added the method keyword argument (with default value conservative) to the following routines in gcpy/regrid.py:

  • make_regridder_L2L
  • make_regridder_C2L
  • make_regridder_S2S
  • make_regridder_L2S

This will allow the value of method passed to these routines to be in turn passed to the xesmf.Regridder function.

Also, some minor fixes suggested by the Pylint linter were applied to gcpy/file_regrid.py and gcpy/regrid.py.

Expected changes

Using file_regrid.py such to regrid lat-lon files to a different lat-lon grid, such as:

$ python -m gcpy.file_regrid                                 \
  --filein         GEOSChem.Restart.20190101_0000z.nc4     \
  --dim_format_in  classic                                 \
  --fileout        GEOSChem.Restart.20190101_0000z_2x25.nc \
  --ll_res_out     2x2.5                                   \
  --dim_format_out classic

will no longer result in the TypeError described by @nicodgomez in #361.

Related Github Issue

gcpy/regrid.py
- Added the "method" keyword argument in the routines listed below
  with default value = "conservative".  Pass the value from the method
  keyword argument to xe.Regridder instead of using the hardwired
  string "conservative"
  - make_regridder_L2L
  - make_regridder_C2L
  - make_regridder_S2S
  - make_regridder_L2S
- Apply fixes suggested by Pylint
- Trimmed trailing whitespace

gcpy/file_regrid.py
- Apply fixes suggested by Pylint
- Trimmed trailing whitespace

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
@yantosca yantosca added this to the 1.6.2 milestone May 23, 2025
@yantosca yantosca requested a review from lizziel May 23, 2025 20:26
@yantosca yantosca self-assigned this May 23, 2025
@yantosca yantosca added topic: Regridding Issues pertaining to horizontal & vertical regridding category: Bug Fix Fixes a bug that was previously reported labels May 23, 2025
@yantosca yantosca changed the base branch from main to dev May 23, 2025 20:31
# ==============================================================
for var in dset.data_vars.keys():
if var == "DELP_DRY" or var == "DELPDRY":
if var in ("DELP_DRY", "DELPDRY"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a fix suggested by Pylint

"currently not supported. Please use the offline regridding\n" + \
"method described in the Regridding section of gcpy.readthedocs.io."
raise RuntimeError(msg)
msg = "Regridding to or from cubed-sphere stretched grids is\n" + \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra indentation was suggested by Pylint

1, cmpminlon_ind:cmpmaxlon_ind + 1].squeeze()
return new_data
elif cmpgridtype == "cs":
if cmpgridtype == "cs":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing elif -> if after a return statement was suggested by Pylint.

# %%%% Renaming from the common format %%%%
# Reverse rename
ds = rename_existing(ds,
ds = rename_existing(ds,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed trailing whitespace here

1, cmpminlon_ind:cmpmaxlon_ind + 1].squeeze()
return new_data
elif cmpgridtype == "ll":
if cmpgridtype == "ll":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing elif -> if after a return statement was suggested by Pylint.

Copy link
Contributor

@lizziel lizziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks @yantosca!

@yantosca yantosca changed the title Add "method" keyword argument to make_regridder_L2L routines in gcpy/regrid.py Add "method" keyword argument to make_regridder_* routines in gcpy/regrid.py May 27, 2025
@yantosca yantosca merged commit 52677a3 into dev May 27, 2025
17 checks passed
@yantosca yantosca deleted the bugfix/method-keyword-in-regrid branch May 27, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Bug Fix Fixes a bug that was previously reported topic: Regridding Issues pertaining to horizontal & vertical regridding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError running Regridding, method keyword should not be passed to make_regridder_L2L
2 participants