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

GMTDataArrayAccessor: Support passing values using enums GridRegistration and GridType for grid registration and type #3696

Merged
merged 32 commits into from
Feb 10, 2025

Conversation

seisman
Copy link
Member

@seisman seisman commented Dec 18, 2024

Description of proposed changes

This PR improves the GMTDataArrayAccessor by allowing setting grid registration and gtype using more readable enums, rather than numeric values.

Refer to #499 (comment) for the initial thoughts but implemented using enums as proposed in #499 (comment).

This PR does a few things:

  1. 8c7f8f6: Add enums GridReg/GridType.
  2. 94086f7: Update GMTDataArrayAccessor to support passing enum values (e.g., grid.gmt.registration=GridReg.PIXEL, not grid.gmt.registration=1).
  3. 8dd3d5f: Update the existing tests to check grid registration and gtype using enums (e.g., assert grid.gmt.registration==GridReg.PIXEL, not assert grid.gmt.registration==1
  4. fd099b0, f0b30ab: Update the tests in test_accessor.py

The plan is to cherry-pick the commit 8c7f8f6 into a separate PR and keep the other commits in this PR, so that we can have two separate entries in the release changelog. [Done in #3693]

Please note that:

  1. Changes in this PR are backward-compatible.
  2. String-type values (e.g., grid.gmt.registration = "gridline") initially proposed in Make a gmt xarray accessor to store metadata from grdinfo #499 (comment) are not supported in this PR. It's simple to support string-type values, but I feel it's not necessary (see the reverted changes in 259771a).

TODO:

Preview: https://pygmt-dev--3696.org.readthedocs.build/en/3696/api/generated/pygmt.GMTDataArrayAccessor.html

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

@seisman seisman force-pushed the enums/grid-reg-type branch from 170a15d to fd099b0 Compare December 18, 2024 14:34
@seisman seisman added the enhancement Improving an existing feature label Dec 18, 2024
@seisman seisman marked this pull request as ready for review December 18, 2024 15:49
@seisman seisman added the needs review This PR has higher priority and needs review. label Dec 18, 2024
@seisman seisman added this to the 0.14.0 milestone Dec 18, 2024
@seisman seisman mentioned this pull request Dec 19, 2024
49 tasks
@seisman seisman removed the needs review This PR has higher priority and needs review. label Dec 27, 2024
@seisman seisman modified the milestones: 0.14.0, 0.15.0 Dec 27, 2024
@seisman seisman changed the title GMTDataArrayAccessor: Support passing values using enums GridReg and GridType for grid registration and type GMTDataArrayAccessor: Support passing values using enums GridRegistration and GridType for grid registration and type Jan 5, 2025
@seisman seisman added this to the 0.15.0 milestone Jan 5, 2025
@seisman seisman added the needs review This PR has higher priority and needs review. label Jan 5, 2025
f"Invalid grid registration value: {value}, should be either "
"0 for Gridline registration or 1 for Pixel registration."
f"Invalid grid registration: '{value}'. "
"Should be either GridRegistration.GRIDLINE or GridRegistration.PIXEL."
Copy link
Member

Choose a reason for hiding this comment

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

Should we still mention the integer value of the enum? E.g. have the error message be:

                "Should be either GridRegistration.GRIDLINE (0) or GridRegistration.PIXEL (1)."

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. Applied in d9bfa33 and 3c0d77b.

@@ -105,24 +135,24 @@ def test_accessor_grid_source_file_not_exist():
Check that the accessor fallbacks to the default registration and gtype when the
grid source file (i.e., grid.encoding["source"]) doesn't exist.
"""
# Load the 05m earth relief grid, which is stored as tiles
# Load the 05m earth relief grid, which is stored as tiles.
Copy link
Member

Choose a reason for hiding this comment

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

Do comments need to end with a full stop now?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's just my preference, since it's a complete sentence.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, I was afraid that you were using some experimental ruff linter 😆!

@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. final review call This PR requires final review and approval from a second reviewer labels Feb 10, 2025
@seisman seisman merged commit 6f1f5d7 into main Feb 10, 2025
25 checks passed
@seisman seisman deleted the enums/grid-reg-type branch February 10, 2025 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants