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

Python scripts: Require user to specify lon format when ambiguous #3024

Open
wants to merge 23 commits into
base: b4b-dev
Choose a base branch
from

Conversation

samsrabin
Copy link
Collaborator

@samsrabin samsrabin commented Mar 21, 2025

Description of changes

At the moment, our Python tools are dangerous in that they can allow the user to enter longitude in the [-180, 180] format when the tools actually assume the [0, 360] format. This PR fixes that by, in ambiguous cases, requiring the user to specify the format they're using with --lon-type either 180 or 360.

Specific notes

Contributors other than yourself, if any: None

CTSM Issues Fixed:

Are answers expected to change (and if so in what way)? No

Any User Interface Changes (namelist or namelist defaults changes)? No

Does this create a need to change or add documentation? Did you do so? Yes; see ESCOMP/ctsm-docs#9.

Testing performed, if any:

  • Python unit and system tests passed but should be rerun before merge.
  • Docs build OK (only pre-existing issues).

Remaining:

  • clm_pymods test suite

@samsrabin samsrabin changed the title [WIPFix python tools longitude format [WIP] Fix python tools longitude format Mar 21, 2025
@samsrabin samsrabin self-assigned this Mar 21, 2025
@samsrabin
Copy link
Collaborator Author

samsrabin commented Apr 1, 2025

  • Done with e5bbb14: If all longitudes are unambiguous, assume longitude format

* Require that user specify whether longitude is in [-180, 180] format (i.e., centered around Prime Meridian) or [0, 360] format (i.e., centered around International Date Line).
* Specified as --lon-type, either 180 or 360 (respectively)
* Resolves ESCOMP#2017
* Resolves ESCOMP#3001
@samsrabin samsrabin force-pushed the fix-python-tools-longitude-format branch from dd68889 to 6b29b53 Compare April 3, 2025 19:47
@samsrabin samsrabin changed the base branch from master to b4b-dev April 3, 2025 19:47
@samsrabin samsrabin added bug something is working incorrectly bfb bit-for-bit test: python Pass clm_pymods test suite plus Python sys/unit tests before merging labels Apr 3, 2025
@github-project-automation github-project-automation bot moved this to Ready to start (or start again) in CTSM: Upcoming tags Apr 3, 2025
@samsrabin samsrabin moved this from Ready to start (or start again) to In progress - master/b4b-dev in CTSM: Upcoming tags Apr 3, 2025
@samsrabin samsrabin linked an issue Apr 3, 2025 that may be closed by this pull request
@samsrabin samsrabin force-pushed the fix-python-tools-longitude-format branch from a777427 to 27d45c9 Compare April 4, 2025 22:37
@samsrabin samsrabin force-pushed the fix-python-tools-longitude-format branch from 879ddd8 to 7ca9ad0 Compare April 4, 2025 23:06
@samsrabin samsrabin requested a review from Copilot April 4, 2025 23:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 20 out of 25 changed files in this pull request and generated 1 comment.

Files not reviewed (5)
  • .git-blame-ignore-revs: Language not supported
  • python/ctsm/test/testinputs/modify_fsurdat_1x1mexicocity.cfg: Language not supported
  • python/ctsm/test/testinputs/modify_fsurdat_opt_sections.cfg: Language not supported
  • python/ctsm/test/testinputs/modify_fsurdat_short.cfg: Language not supported
  • python/ctsm/test/testinputs/modify_fsurdat_short_nofiles.cfg: Language not supported
Comments suppressed due to low confidence (2)

python/ctsm/test/test_sys_mesh_modifier.py:60

  • The variable _lon_type is set to None in the test setup but never given a proper default value. Consider initializing it with an appropriate default (e.g., 360) to ensure consistent behavior in tests.
self._lon_type = None

python/ctsm/subset_data.py:440

  • The condition intended to check for the existence of the config file uses surf_year as a proxy, leading to a misleading error message (“Entered default config file does not exist”). Clarify the condition by directly checking the existence of the config file and update the corresponding error message accordingly.
if args.surf_year != 1850 and args.surf_year != 2000:

@samsrabin samsrabin marked this pull request as ready for review April 4, 2025 23:36
@samsrabin samsrabin changed the title [WIP] Fix python tools longitude format Fix python tools longitude format Apr 4, 2025
@samsrabin samsrabin added PR status: awaiting review Work on this PR is paused while waiting for review. next this should get some attention in the next week or two. Normally each Thursday SE meeting. labels Apr 4, 2025
@samsrabin samsrabin changed the title Fix python tools longitude format Python scripts: Require user to specify lon format when ambiguous Apr 4, 2025
@samsrabin samsrabin added documentation additions or edits to user-facing documentation test: docs Test documentation build before merging labels Apr 4, 2025
@@ -119,6 +137,7 @@ def get_parser():
type=plon_type,
default=287.8,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • Add "must be unambiguous" note here.

@samsrabin samsrabin requested a review from ekluzek April 8, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bfb bit-for-bit bug something is working incorrectly documentation additions or edits to user-facing documentation next this should get some attention in the next week or two. Normally each Thursday SE meeting. PR status: awaiting review Work on this PR is paused while waiting for review. test: docs Test documentation build before merging test: python Pass clm_pymods test suite plus Python sys/unit tests before merging
Projects
Status: In progress - master/b4b-dev
Development

Successfully merging this pull request may close these issues.

Make Python scripts smarter about lons [-180, 180) vs. [0, 360)
1 participant