Skip to content

Add constants for stretched-grid and lat-lon parameters; Modify code according to suggestions from Pylint#374

Merged
yantosca merged 18 commits intodevfrom
feature/update-constants
Nov 4, 2025
Merged

Add constants for stretched-grid and lat-lon parameters; Modify code according to suggestions from Pylint#374
yantosca merged 18 commits intodevfrom
feature/update-constants

Conversation

@yantosca
Copy link
Contributor

@yantosca yantosca commented Aug 13, 2025

Name and Institution (Required)

Name: Bob Yantosca
Institution: Harvard + GCST

Describe the update

This PR does the following:

  1. Renames the constant skip_these_vars to SKIP_THESE_VARS (as constants in Python should be upper case), and replaced them in various routines.

  2. Adds GLOBAL_LL_EXTENT, DEFAULT_SG_STRETCH_FACTOR, DEFAULT_SG_TARGET_LAT, DEFAULT_SG_TARGET_LON, and NO_STRETCH_SG_PARAMS to gcpy/constants.py.

    • Replaced [-180, 180, -90, 90] with GLOBAL_LL_EXTENT in various routines
    • Replaced [1, 170, -90] with NO_STRETCH_SG_PARAMS in various routines
  3. Add modifications suggested by Pylint to gcpy/grid.py:

    • Added a shebang line at top of the module
    • Imported GLOBAL_LL_EXTENT and NO_STRETCH_SG_PARAMS from constants.py
    • Edited lines to not be longer than 100 chars where expedient
    • Removed "else" statements after a "return", they're redundant, and re-indented code accordingly
    • Removed lists as default values for keywords; Use None instead, then if the keyword is None, set to its appropriate default value
    • Added PyDoc headers that were missing
    • Renamed routines to conform to Python snake-case name convention:
      • make_grid_LL -> make_grid_ll
      • make_grid_CS -> make_grid_cs
      • make_grid_SG -> make_grid_sg
      • csgrid_GMAO -> csgrid_gmao
      • rotate_sphere_3D -> rotate_sphere_3d
    • Renamed several variables to conform to Python snake-case name convention
    • Removed parentheses after equal signs as directed by Pylint
    • Added cosmetic changes (comments, line breaks, indentations)
    • Added an else block in routine rotate_sphere_3d to raise a ValueError if the rot_axis is not either "x", "y", or "z"
  4. Add modifications suggested by Pylint to gcpy/regrid.py

    • Added the shebang line at the top of the module
    • Adjusted import statements to import renamed functions in grid.py
    • Renamed the following functions to better conform to Python snake-case naming convention:
      • make_regridder_l2l --> make_regridder_ll2ll
      • make_regridder_C2L --> make_regridder_cs2ll
      • make_regridder_S2S --> make_regridder_sg2sg
      • make_regridder_l2S --> make_regridder_ll2sg
    • Renamed loop variable regridder to the_regridder to avoid having a name clash with an argument named "regridder"
    • Edited code to make sure lines of code are less than 100 chars.
    • Converted strings using .format() to f-strings
    • Modified code to no longer trap for BaseException
    • Modified code so that lists are not used as default values for keyword arguments. Use None instead and then if the keyword is None, then set it to default values within the program.
    • Renamed local variables to conform to snake-case convention
    • Cosmetic changes (comments, indentation, trimmed whitespace)
  5. Add modifications suggested by Pylint to gcpy/cstools.py

    • Updated code to import and use the renamed csgrid_gmao function from gcpy/grid.py
    • Modified the assigment statement for x_lat to use i_vert in (0, 3)
    • Fixed incorrect indentation at line 753
  6. Updated gcpy/file_regrid.py to import the renamed make_regridder_* functions from gcpy/grid.py

  7. Update gcpy/append_grid_corners.py as follows:

    • Import NO_STRETCH_SG_PARAMS from constants.py and use that instead of hardwired [1, 170, -90]
    • Updated code to use renamed "make_grid_sg" instead of the older "make_grid_SG" function (from grid.py)
  8. Update gcpy/raveller_1D.py as follows

    • Now import the renamed make_grid_cs from gcpy/grid.py
    • Added missing PyDoc headers
    • Break lines up so they do no excceed 80 chars
    • Cosmetic changes for readability

Expected changes

This should be a zero-diff change.

Related Github Issue

N/A

@yantosca yantosca requested review from lizziel and msulprizio August 13, 2025 15:07
@yantosca yantosca self-assigned this Aug 13, 2025
@yantosca yantosca added topic: Cubed-Sphere Grid Pertains to cubed-sphere grids and/or regridding category: Feature Request New feature or request topic: Structural Modifications Related to GCPy structural modifications (as opposed to scientific updates) topic: Stretched Grid Pertaining to the cubed-sphere stretched-grid labels Aug 13, 2025
@lizziel
Copy link
Contributor

lizziel commented Aug 13, 2025

An initial comment I have on this update is to make the default param names more descriptive. Specifically, change DEFAULT_LL_EXTENT to GLOBAL_LL_EXTENT, and DEFAULT_SG_PARAMS to NO_STRETCH_SG_PARAMS. This will make the code more understandable when reading it.

@yantosca
Copy link
Contributor Author

An initial comment I have on this update is to make the default param names more descriptive. Specifically, change DEFAULT_LL_EXTENT to GLOBAL_LL_EXTENT, and DEFAULT_SG_PARAMS to NO_STRETCH_SG_PARAMS. This will make the code more understandable when reading it.

Thanks @lizziel, I can do this.

@yantosca yantosca added this to the 1.7.0 milestone Aug 13, 2025
@yantosca
Copy link
Contributor Author

@lizziel @msulprizio: I changed the names of the constants and pushed a couple more fixes.

@yantosca yantosca force-pushed the feature/update-constants branch from 3837265 to c99ef74 Compare August 14, 2025 17:37
@yantosca
Copy link
Contributor Author

@msulprizio @lizziel: This PR has been rebased atop PR #377 (stretched-grid fixes) and #375, and #376 (pypdf==6.0.0)

In gcpy/constants.py
- Renamed "skip_these_vars" to "SKIP_THESE_VARS", as constants should
  use all caps
- Added DEFAULT_LL_EXTENT = [-180, 180, -90, 90]
- Added DEFAULT_SG_PARAMS = [1, 170, -90]

In various routines
- Replaced "skip_these_vars" with "SKIP_THESE_VARS"
- Replaced "[-180, 180, -90, 90]" with DEFAULT_LL_EXTENT
- Replaced "[-180, 180, -90, 90]" with DEFAULT_SG_PARAMS

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/constants.py
- Added DEFAULT_SG_STRETCH_FACTOR, DEFAULT_SG_TARGET_LON,
  and DEFAULT_SG_TARGET_LAT
- Now define DEFAULT_SG_PARAMS with the other DEFAULT_SG_* constants
- Updated comments

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/grid.py
- Added a shebang line at top of the module
- Imported DEFAULT_LL_EXTENT and DEFAULT_SG_PARAMS from constants.py
- Edited lines to not be longer than 100 chars where expedient
- Removed "else" statements after a "return", they're redundant,
  and re-indented code accordingly
- Removed lists as default values for keywords; Use None instead, then
  if the keyword is None, set to its appropriate default value
- Added PyDoc headers that were missing
- Renamed routines to conform to Python snake-case name convention:
  - make_grid_LL     -> make_grid_ll
  - make_grid_CS     -> make_grid_cs
  - make_grid_SG     -> make_grid_sg
  - csgrid_GMAO      -> csgrid_gmao
  - rotate_sphere_3D -> rotate_sphere_3d
- Renamed several variables to conform to Python snake-case name convention
- Removed parentheses after equal signs as directed by Pylint
- Added cosmetic changes (comments, line breaks, indentations)
- Added an else block in routine rotate_sphere_3d to raise a ValueError
  if the rot_axis is not either "x", "y", or "z"

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/regrid.py
- Added the shebang line at the top of the module
- Adjusted import statements to import renamed functions in grid.py
- Renamed the following functions to better conform to Python snake-case
  naming convention:
  - make_regridder_l2l --> make_regridder_ll2ll
  - make_regridder_C2L --> make_regridder_cs2ll
  - make_regridder_S2S --> make_regridder_sg2sg
  - make_regridder_l2S --> make_regridder_ll2sg
- Renamed loop variable "regridder" to "the_regridder" to avoid having
  a name clash with an argument named "regridder"
- Edited code to make sure lines of code are less than 100 chars.
- Converted strings using ".format()" to f-strings
- Modified code to no longer trap for BaseException
- Modified code so that lists are not used as default values for keyword
  arguments.  Use None instead and then if the keyword is None, then
  set it to default values within the program.
- Renamed local variables to conform to snake-case convention
- Cosmetic changes (comments, indentation, trimmed whitespace)

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/cstools.py
- Updated code to import and use the renamed "csgrid_gmao" function
  from "gcpy/grid.py"
- Modified the assigment statement for x_lat to use "i_vert in (0, 3)"
- Fixed incorrect indentation at line 753

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/file_regrid.py
- Now imports and uses the make_regridder_ll2ll, make_regrider_cs2ll,
  make_regridder_sg2sg, and make_regridder_ll2sg functions that
  have been renamed in gcpy/grid.py.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/append_grid_corners.py
- Import DEFAULT_SG_PARAMS from constants.py and use that instead
  of hardwired [1, 170, -90]
- Updated code to use renamed "make_grid_sg" instead of the older
  "make_grid_SG" function (from grid.py)

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/raveller_1D.py
- Now import the renamed make_grid_cs from gcpy/grid.py
- Added missing PyDoc headers
- Break lines up so they do no excceed 80 chars
- Cosmetic changes for readability

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/constants.py
- Renamed DEFAULT_LL_EXTENT -> GLOBAL_LL_EXTENT
- Renamed DEFAULT_SG_*      -> NO_STRETCH_SG_*

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/grid.py
- Now import newly-renamed GLOBAL_LL_EXTENT constant
- Now import newly-renamed NO_STRETCH_SG_* constants
- Renamed vert_grid class to VertGrid, as Python classes should use
  PascalCase naming convention
gcpy/append_grid_corners.py
gcpy/regrid.py
- Now import newly-renamed GLOBAL_LL_EXTENT constant
- Now import newly-renamed NO_STRETCH_SG_* constants

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/cstools.py
- Now call gcpy.make_grid_sg instead of gcpy.make_grid_SG.
  This should have been changed in a prior commit but wasn't.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/regrid.py
- The CodeQL GitHub Action flagged the use of hashlib.sha1 as being
  cryptographically weak.  We have adopted the recommendation of using
  hashlib.sha256 instead.

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
grid.py
regrid.py
- Renamed the last remaining instances of vert_grid to VertGrid.
  These were missed in the previous commit.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/plot/compare_single_level.py
- Replaced 2 additional instances of [1,170,-90] with the
  constant NO_STRETCH_SG_PARAMS from gcpy/constants.py.

gcpy/plot/compare_zonal_mean.py
- Replaced 2 additional instances of [1,170,-90] with the
  constant NO_STRETCH_SG_PARAMS from gcpy/constants.py.

The instances of [1,170,-90] were introduced from a rebase.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
@yantosca yantosca force-pushed the feature/update-constants branch from 9ced073 to 9654a75 Compare September 8, 2025 14:23
gcpy/grid.py
- Import GLOBAL_LL_EXTENT, NO_STRETCH_SG_PARAMS, and R_EARTH_m
  from gcpy.constants, not gcpy.vgrid_defs
- Change calls to "vert_grid" to "VertGrid", to conform to PascalCase
  naming convention for Python classes

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
This merge brings updates from the "dev" branch (as of PR #381)
back into the "feature/update-constants" branch.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
@yantosca
Copy link
Contributor Author

yantosca commented Oct 6, 2025

I have merged the dev branch as of PR #381 back into feature/update-constants.

@lizziel
Copy link
Contributor

lizziel commented Oct 6, 2025

Thanks @yantosca, I will do a re-review this week.

CHANGELOG.md Outdated
- Renamed `skip_these_vars` to `SKIP_THESE_VARS` to conform to Python style for constants
- Modified code in `grid.py`, `regrid.py`, `file_regrid.py`, and `cstools.py`, and `raveller_1D.py` as directed by Pylint to better conform to the Python style guide
- Renamed the following routines in `gcpy/grid.py` to conform to snake-case naming convention
- `csgrid_GMAO --> csgrid_gmao`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this level of detail in the changelog is a bit too much. Best keep it simple, e.g. "Renamed grid routines to use all lower-case to conform to snake-case naming convention". Same comment for other sections of changelog that have bulleted lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @lizziel, now updated

Replaced explicit changes with more general descriptions

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
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.

Good to merge!

@yantosca yantosca merged commit 411dcb6 into dev Nov 4, 2025
@yantosca yantosca deleted the feature/update-constants branch November 4, 2025 19:12
yantosca added a commit that referenced this pull request Nov 4, 2025
gcpy/plot/compare_single_level.py
gcpy/plot/compare_zonal_mean.py
- Import NO_STRETCH_SG_PARAMS from gcpy.constants.  This had
  been omitted in PR #374.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
yantosca added a commit that referenced this pull request Nov 4, 2025
gcpy/examples/grids/display_gcclassic_grid_info.py
- Rebased atop PR #374; use consistent snake_case format
- Added the type of grid ("global", "nested NA", etc") as the
  4th element in the grid_parameters tuple
- Now display metadata (Name, Resolution, Longitude range,
  Latitude Range) before displaying the lon & lat centers & edges
- Add "res_display" variable to contain a "pretty" version of the
  resolution string (with degree symbols)

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
yantosca added a commit that referenced this pull request Nov 4, 2025
gcpy/examples/grids/display_gcclassic_grid_info.py
- Rebased atop PR #374; use consistent snake_case format
- Added the type of grid ("global", "nested NA", etc") as the
  4th element in the grid_parameters tuple
- Now display metadata (Name, Resolution, Longitude range,
  Latitude Range) before displaying the lon & lat centers & edges
- Add "res_display" variable to contain a "pretty" version of the
  resolution string (with degree symbols)

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
yantosca added a commit that referenced this pull request Jan 20, 2026
This merge brings PR #396 (Allow args to create_regridders to be
xr.Dataset or xr.DataArray, by @yantosca) into the GCPy 1.7.0
development stream.

PR #396 fixes a bug introduced in PR #374, where an error was thrown
if arguments to the "create_regridders" function were not of type
xarray.Dataset.  We now also allow arguments of type xarray.DataArray.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: Feature Request New feature or request topic: Cubed-Sphere Grid Pertains to cubed-sphere grids and/or regridding topic: Stretched Grid Pertaining to the cubed-sphere stretched-grid topic: Structural Modifications Related to GCPy structural modifications (as opposed to scientific updates)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants