Skip to content

Commit f715aee

Browse files
committed
Improve the logic for determine grid/image gtype based on upstream GMT codes
1 parent 62f0ce0 commit f715aee

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pygmt/datatypes/header.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@ def gtype(self) -> int:
250250
"lon"/"lat" or have units "degrees_east"/"degrees_north", then the grid is
251251
assumed to be geographic.
252252
"""
253+
gtype = 0 # Cartesian by default
254+
253255
dims = self.dims
254-
gtype = 1 if dims[0] == "lat" and dims[1] == "lon" else 0
256+
if dims[0] == "lat" and dims[1] == "lon":
257+
# Check dimensions for grids that following CF-conventions
258+
gtype = 1
259+
elif self.ProjRefPROJ4 is not None:
260+
# Check ProjRefPROJ4 for images imported via GDAL.
261+
# The logic comes from GMT's `gmtlib_read_image_info` function.
262+
projref = self.ProjRefPROJ4.decode()
263+
if "longlat" in projref or "latlong" in projref:
264+
gtype = 1
255265
return gtype

pygmt/datatypes/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def to_dataarray(self) -> xr.DataArray:
166166
axis: Y
167167
actual_range: [-90. 90.]
168168
>>> da.gmt.registration, da.gmt.gtype
169-
(1, 0)
169+
(1, 1)
170170
"""
171171
# The image header
172172
header = self.header.contents

0 commit comments

Comments
 (0)