-
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
Infer grid registration (gridline vs pixel) and grid type (geographic or Cartesian) for xarray.DataArray input #2194
Comments
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct. |
@PaulWessel I remember that GMT has a function or lines of code that checks if a grid is geographic or Cartesian, but I can't find where it is. Could you please point me to the function if you remember? |
In usual situations (a grid has ben read or -R -J processed) then we use the macro gmt_M_is_geographic (GMT, GMT_IN) which returns true of we have a geographic situation. There is also gmt_M_is_cartesian (GMT, GMT_IN) as well. |
Hmm, depending on how that geographic/cartesian logic works, we could probably add it to the logic around here: Lines 28 to 39 in d8c816a
Currently we do try to use If I'm hearing correctly, resolving this issue would require
|
I just found this function
I also found the It seems that we can apply the same logic to xarray.DataArray data. |
Yes, I would think that is reasonable |
Currently, grdimage in pygmt can accept a NetCDF file name or an xarray structure as input for the grid to be plotted. When providing a NetCDF file, the code apparently checks whether the grid is geographic (has latitude/longitude dimensions), and behaves accordingly, by closing the grid at 0/360 deg longitude. When providing an xarray structure, however, such a check is not performed, and the user has to set the .gmt.gtype property on the xarray data to 1 to make pygmt plot the data as a geographic grid.
The topic was discussed on the forum, where a code example is provided:
https://forum.generic-mapping-tools.org/t/pygmt-gap-in-grdimage-of-xarray-data-at-zero-longitude/3431/9
I've also just found this closely related (closed) issue: #375
A temporary solution might be to improve the documentation on how the user should set the xarray .gmt.gtype property in the documentation, perhaps by including an example in the Tuturial related to grdimage (https://www.pygmt.org/latest/tutorials/advanced/earth_relief.html#sphx-glr-tutorials-advanced-earth-relief-py), or by adding a separate tutorial on how NetCDF files and xarray structures can be created from Python and are handled together with PyGMT.
Are you willing to help implement and maintain this feature? No, I'm not at the moment able to invest the necessary time in working out the inner workings of the code, especially since this seems related to a complex long-running series of issue. I could help with the documentation, though.
The text was updated successfully, but these errors were encountered: