-
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
Changes from 4 commits
95f28fc
1f96d15
81145db
ef95f2e
f5b5a78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
""" | ||
Test the behaviour of the GMTDataArrayAccessor class. | ||
""" | ||
import os | ||
|
||
import pytest | ||
import xarray as xr | ||
from pygmt import which | ||
|
@@ -66,3 +68,25 @@ def test_accessor_set_non_boolean(): | |
|
||
with pytest.raises(GMTInvalidInput): | ||
grid.gmt.gtype = 2 | ||
|
||
|
||
def test_accessor_sliced_datacube(): | ||
""" | ||
Check that a 2D grid which is sliced from an n-dimensional datacube works | ||
with accessor methods. | ||
|
||
This is a regression test for | ||
https://github.com/GenericMappingTools/pygmt/issues/1578. | ||
""" | ||
try: | ||
fname = which( | ||
"https://github.com/pydata/xarray-data/raw/master/eraint_uvz.nc", | ||
download="u", | ||
) | ||
Comment on lines
+82
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 😆 |
||
with xr.open_dataset(fname) as dataset: | ||
grid = dataset.sel(level=500, month=1, drop=True).z | ||
|
||
assert grid.gmt.registration == 0 # gridline registration | ||
assert grid.gmt.gtype == 0 # cartesian coordinate type | ||
finally: | ||
os.remove(fname) |
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.