Skip to content

Commit

Permalink
Improve the logic for determine grid/image gtype based on upstream GM…
Browse files Browse the repository at this point in the history
…T codes
  • Loading branch information
seisman committed Sep 29, 2024
1 parent 62f0ce0 commit f715aee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pygmt/datatypes/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ def gtype(self) -> int:
"lon"/"lat" or have units "degrees_east"/"degrees_north", then the grid is
assumed to be geographic.
"""
gtype = 0 # Cartesian by default

dims = self.dims
gtype = 1 if dims[0] == "lat" and dims[1] == "lon" else 0
if dims[0] == "lat" and dims[1] == "lon":
# Check dimensions for grids that following CF-conventions
gtype = 1
elif self.ProjRefPROJ4 is not None:
# Check ProjRefPROJ4 for images imported via GDAL.
# The logic comes from GMT's `gmtlib_read_image_info` function.
projref = self.ProjRefPROJ4.decode()
if "longlat" in projref or "latlong" in projref:
gtype = 1
return gtype
2 changes: 1 addition & 1 deletion pygmt/datatypes/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def to_dataarray(self) -> xr.DataArray:
axis: Y
actual_range: [-90. 90.]
>>> da.gmt.registration, da.gmt.gtype
(1, 0)
(1, 1)
"""
# The image header
header = self.header.contents
Expand Down

0 comments on commit f715aee

Please sign in to comment.