Uh oh!
There was an error while loading. Please reload this page.
GMTDataArrayAccessor: Fallback to default grid registration and gtype if the grid source file doesn't exist - #2009
Conversation
seisman
commented
Jul 25, 2022
Ping @maxrjones and @weiji14 for reviewing. |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
seisman
commented
Jul 26, 2022
I've added a unit test in 37869d4, and the test helps find a new bug. At the end of the test, I manually set the registration and gtype information and expect the two |
seisman
commented
Jul 27, 2022
The documentation of xarray accessor explains why they don't work as expected:
So every time |
c769028 to
7b0520aCompareweiji14
commented
Jul 27, 2022
The accessor |
seisman
commented
Feb 16, 2023
OK. I've removed this test and added a simpler test instead. The old complicated test was moved to #1984 so that we can work on this later. |
| try: | ||
| self._source = self._obj.encoding["source"] # filepath to NetCDF source | ||
| if not Path(self._source).exists(): | ||
| raise FileNotFoundError( | ||
| f"Grid source file {self._source} doesn't exist." | ||
| ) | ||
| # Get grid registration and grid type from the last two columns of | ||
| # the shortened summary information of `grdinfo`. | ||
| self._registration, self._gtype = map( | ||
| int, grdinfo(self._source, per_column="n").split()[-2:] | ||
| ) | ||
| except (KeyError, ValueError): | ||
| except (KeyError, ValueError, FileNotFoundError): | ||
| self._registration = 0 # Default to Gridline registration | ||
| self._gtype = 0 # Default to Cartesian grid type |
There was a problem hiding this comment.
I wonder if we should change these lines to the following codes, which I think are more readable:
self._source = self._obj.encoding.get("source")
if self._source is not None and Path(self._source).exists():
try:
# Get grid registration and grid type from the last two columns of
# the shortened summary information of `grdinfo`.
self._registration, self._gtype = map(
int, grdinfo(self._source, per_column="n").split()[-2:]
)
except ValueError:
self._registration = 0
self._gtype = 0
else:
self._registration = 0
self._gtype = 0
There was a problem hiding this comment.
So we will silently fallback to registration=0 and gtype=0 if grdinfo cannot determine the grid registration and type? Ok I guess, but please add the code comments back 🙂
seisman
commented
Feb 20, 2023
Ping @GenericMappingTools/pygmt-maintainers for review. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
weiji14
left a comment
There was a problem hiding this comment.
Sorry, 2 more typos, otherwise ok.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com>
michaelgrund
left a comment
There was a problem hiding this comment.
Only minor consistency changes, otherwise looks good!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com>
Description of proposed changes
If the netCDF source file doesn't exist, running
grdinfoon the netCDF source file gives the following error:The error is unfriendly and confusing. Actually, it makes no sense if the grid source file doesn't exist. In this case, it should fallback to registration=0 and gtype=0 unless we implement the idea in #2194 (comment).
Partially address #1984 and #524 (comment)
Please note that this PR doesn't solve the problems in #1984 and #524, because the registration and gtype information are incorrect, but at least it doesn't report confusing errors.