-
Notifications
You must be signed in to change notification settings - Fork 229
GMT_GRID_HEADER: Parse grid header and add grid properties #3134
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
Conversation
… and units from x/y/z_units
Co-authored-by: Michael Grund <[email protected]>
Co-authored-by: Yvonne Fröhlich <[email protected]>
# Name of data set | ||
("title", ctp.c_char * GMT_GRID_TITLE_LEN80), | ||
# Name of generating command | ||
("command", ctp.c_char * GMT_GRID_COMMAND_LEN320), | ||
# Comments for this data set | ||
("remark", ctp.c_char * GMT_GRID_REMARK_LEN160), |
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.
Store these metadata in the attrs
dict too?
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.
Done in dfbc2e5.
Co-authored-by: Wei Ji <[email protected]>
I'm wondering if we should move the |
That's not a bad idea. But maybe split the implementation of |
Sounds good, but the |
Done in 2bd353a. |
pygmt/datatypes/header.py
Outdated
def get_registration(self) -> int: | ||
""" | ||
Get the grid registration from the grid header. | ||
|
||
Returns | ||
------- | ||
registration | ||
The grid registration. 0 for gridline and 1 for pixel. | ||
""" | ||
return self.registration |
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.
We could just remove this and call self.registration
no?
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.
Removed in 79f4c87.
pygmt/datatypes/header.py
Outdated
def get_name(self) -> str: | ||
""" | ||
Get the name of the grid from the grid header. | ||
|
||
Returns | ||
------- | ||
name | ||
The name of the grid. | ||
""" | ||
return "z" |
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.
Can probably remove this if it is only returning the letter z
?
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 name defaults to z
for 2-D grids and cube
for 3-D cubes, but it can be overridden by the varname
variable stored in the hidden GMT_GRID_HEADER_HIDDEN
data structure. I guess we won't wrap the GMT_GRID_HEADER_HIDDEN
data structure now because it is designed to be hidden and may change anytime, but maybe we have to wrap it in the future?
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.
Right, I see that varname
is marked as private at https://github.com/GenericMappingTools/gmt/blob/9b93e07982233a31e97b3f8a4ed8df3a3dfa56f9/src/gmt_hidden.h#L161, but it is supposedly holding the name of a NetCDF variable? Maybe we should try to parse it instead of always returning z
(or cube
)?
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, varname
is only assigned when a netCDF name like input.nc?varname
is specified. I guess it's just rare cases.
As mentioned above, to parse varname
, we have to wrap the GMT_GRID_HEADER_HIDDEN
data structure, which contains more than 50 fields, and the last time it was changed is just a few months ago (GenericMappingTools/gmt@b9d3f2b).
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.
Got it. Let's just leave it unwrapped for now then.
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.
Description of proposed changes
Part of PR #2398.
This PR add codes to parse the grid header and get the dimension names, attributes, gtype and more. They're stored as properties of the header.
The codes can be reused in wrapping GMT_GRID/GMT_IMAGE/GMT_CUBE data structures.
Tests are added to the
_parse_nameunits
function but not for other functions. The function will be tested in theGMT_GRID.to_dataarray
method.