@@ -132,10 +132,13 @@ def test_xarray_accessor_sliced_datacube():
132
132
Path (fname ).unlink ()
133
133
134
134
135
- def test_xarray_accessor_grid_source_file_not_exist ():
135
+ def test_xarray_accessor_tiled_grid_slice_and_add ():
136
136
"""
137
- Check that the accessor fallbacks to the default registration and gtype when the
138
- grid source file (i.e., grid.encoding["source"]) doesn't exist.
137
+ Check that the accessor works to get the registration and gtype when the grid source
138
+ file is from a tiled grid, that slicing doesn't affect registration/gtype, but math
139
+ operations do return the default registration/gtype as a fallback.
140
+
141
+ Unit test to track https://github.com/GenericMappingTools/pygmt/issues/524
139
142
"""
140
143
# Load the 05m earth relief grid, which is stored as tiles.
141
144
grid = load_earth_relief (
@@ -144,17 +147,25 @@ def test_xarray_accessor_grid_source_file_not_exist():
144
147
# Registration and gtype are correct.
145
148
assert grid .gmt .registration is GridRegistration .PIXEL
146
149
assert grid .gmt .gtype is GridType .GEOGRAPHIC
147
- # The source grid file is undefined.
148
- assert grid .encoding . get ( "source" ) is None
150
+ # The source grid file for tiled grids is the first tile
151
+ assert grid .encoding [ "source" ]. endswith ( "S90E000.earth_relief_05m_p.nc" )
149
152
150
- # For a sliced grid, fallback to default registration and gtype, because the source
151
- # grid file doesn't exist.
153
+ # For a sliced grid, ensure we don't fallback to the default registration (gridline)
154
+ # and gtype (cartesian), because the source grid file should still exist.
152
155
sliced_grid = grid [1 :3 , 1 :3 ]
153
- assert sliced_grid .gmt .registration is GridRegistration .GRIDLINE
154
- assert sliced_grid .gmt .gtype is GridType .CARTESIAN
155
-
156
- # Still possible to manually set registration and gtype.
157
- sliced_grid .gmt .registration = GridRegistration .PIXEL
158
- sliced_grid .gmt .gtype = GridType .GEOGRAPHIC
156
+ assert sliced_grid .encoding ["source" ].endswith ("S90E000.earth_relief_05m_p.nc" )
159
157
assert sliced_grid .gmt .registration is GridRegistration .PIXEL
160
158
assert sliced_grid .gmt .gtype is GridType .GEOGRAPHIC
159
+
160
+ # For a grid that underwent mathematical operations, fallback to default
161
+ # registration and gtype, because the source grid file doesn't exist.
162
+ added_grid = sliced_grid + 9
163
+ assert added_grid .encoding == {}
164
+ assert added_grid .gmt .registration is GridRegistration .GRIDLINE
165
+ assert added_grid .gmt .gtype is GridType .CARTESIAN
166
+
167
+ # Still possible to manually set registration and gtype.
168
+ added_grid .gmt .registration = GridRegistration .PIXEL
169
+ added_grid .gmt .gtype = GridType .GEOGRAPHIC
170
+ assert added_grid .gmt .registration is GridRegistration .PIXEL
171
+ assert added_grid .gmt .gtype is GridType .GEOGRAPHIC
0 commit comments