-
Notifications
You must be signed in to change notification settings - Fork 224
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
Allow GMTDataArrayAccessor to work on sliced datacubes #1581
Conversation
If `grdinfo` can't read the source NetCDF file as it is an n-dimensional datacube (instead of a 2D grid), we fallback to setting the default gridline registration and Cartesian grid type.
684315d
to
95f28fc
Compare
So that the file can be deleted on Windows.
@@ -34,7 +34,7 @@ def __init__(self, xarray_obj): | |||
self._registration, self._gtype = map( | |||
int, grdinfo(self._source, per_column="n", o="10,11").split() | |||
) | |||
except KeyError: | |||
except (KeyError, ValueError): |
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.
As I understand it, previous imports of sliced datacubes would result in a ValueError
, so this makes an exception for it and sets the grid registration and type to a default?
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.
Correct. Sliced datacubes will fallback to using the default grid registration and type instead of raising a ValueError.
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.
I don't know when a sliced datacube would be used or what type of error it would cause (I'm assuming a ValueError
based upon the changes to accessors.py
), but on the grounds that that this adds a passing test, so I assume it works as intended.
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.
The PR looks good to me, but do we want to cache the data file?
fname = which( | ||
"https://github.com/pydata/xarray-data/raw/master/eraint_uvz.nc", | ||
download="u", | ||
) |
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 we want to cache this file in CI?
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.
Probably don't need to, since this file is on GitHub, and our CI is on GitHub too, so if GitHub is down, nothing will work 😆
…gTools#1581) If `grdinfo` can't read the source NetCDF file as it is an n-dimensional datacube (instead of a 2D grid), we fallback to setting the default gridline registration and Cartesian grid type. * Use with statement to ensure the grid is properly closed So that the file can be deleted on Windows. Co-authored-by: Will Schlitzer <[email protected]>
Description of proposed changes
If
grdinfo
can't read the source NetCDF file as it is an n-dimensional datacube (instead of a 2D grid), we fallback to setting the default gridline registration and Cartesian grid type.Note that a warning like
grdinfo [WARNING]: Detected a data cube (eraint_uvz.nc) but -Q not set - skipping
will still be emitted, but runninggrid.gmt.registration
should still work. Perhaps a better way would be to try to usegrdinfo -Q
, but then we would somehow need to know which variable within the datacube people have sliced.Fixes #1578, Addresses #524 (comment)
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version