-
Notifications
You must be signed in to change notification settings - Fork 225
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
Conversation
170a15d
to
fd099b0
Compare
pygmt/accessors.py
Outdated
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." |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😆!
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:
GridReg
/GridType
.GMTDataArrayAccessor
to support passing enum values (e.g.,grid.gmt.registration=GridReg.PIXEL
, notgrid.gmt.registration=1
).assert grid.gmt.registration==GridReg.PIXEL
, notassert grid.gmt.registration==1
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:
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:
GridReg
/GridType
to API docs [in Add enums GridRegistration and GridType for grid registration and type #3693]Preview: https://pygmt-dev--3696.org.readthedocs.build/en/3696/api/generated/pygmt.GMTDataArrayAccessor.html
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.