Skip to content

Commit 8dd3d5f

Browse files
committed
Use enums GridType and GridReg in tests
1 parent 94086f7 commit 8dd3d5f

37 files changed

+153
-116
lines changed

pygmt/datatypes/grid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def to_dataarray(self) -> xr.DataArray:
165165
axis: Y
166166
actual_range: [-24. -10.]
167167
>>> da.gmt.registration, da.gmt.gtype
168-
(1, 1)
168+
(<GridReg.PIXEL: 1>, <GridType.GEOGRAPHIC: 1>)
169169
"""
170170
# The grid header
171171
header = self.header.contents

pygmt/datatypes/image.py

+1-1
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, 1)
169+
(<GridReg.PIXEL: 1>, <GridType.GEOGRAPHIC: 1>)
170170
"""
171171
# The image header
172172
header = self.header.contents

pygmt/src/tilemap.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from pygmt.clib import Session
88
from pygmt.datasets.tile_map import load_tile_map
9+
from pygmt.enums import GridType
910
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
1011

1112
try:
@@ -121,7 +122,7 @@ def tilemap(
121122
zoom_adjust=zoom_adjust,
122123
)
123124
if lonlat:
124-
raster.gmt.gtype = 1 # Set to geographic type
125+
raster.gmt.gtype = GridType.GEOGRAPHIC
125126

126127
# Only set region if no_clip is None or False, so that plot is clipped to exact
127128
# bounding box region

pygmt/tests/test_binstats.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy.testing as npt
88
import pytest
99
from pygmt import binstats
10+
from pygmt.enums import GridReg, GridType
1011
from pygmt.helpers import GMTTempFile
1112

1213

@@ -42,8 +43,8 @@ def test_binstats_no_outgrid():
4243
region="g",
4344
)
4445
assert temp_grid.dims == ("y", "x")
45-
assert temp_grid.gmt.gtype == 0 # Cartesian grid
46-
assert temp_grid.gmt.registration == 0 # Gridline registration
46+
assert temp_grid.gmt.gtype == GridType.CARTESIAN
47+
assert temp_grid.gmt.registration == GridReg.GRIDLINE
4748
npt.assert_allclose(temp_grid.max(), 35971536)
4849
npt.assert_allclose(temp_grid.min(), 53)
4950
npt.assert_allclose(temp_grid.median(), 1232714.5)

pygmt/tests/test_datasets_earth_age.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import numpy.testing as npt
77
from pygmt.datasets import load_earth_age
8+
from pygmt.enums import GridReg
89

910

1011
def test_earth_age_01d():
@@ -18,7 +19,7 @@ def test_earth_age_01d():
1819
assert data.attrs["units"] == "Myr"
1920
assert data.attrs["horizontal_datum"] == "WGS84"
2021
assert data.shape == (181, 361)
21-
assert data.gmt.registration == 0
22+
assert data.gmt.registration == GridReg.GRIDLINE
2223
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
2324
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
2425
npt.assert_allclose(data.min(), 0.37, atol=0.01)
@@ -31,7 +32,7 @@ def test_earth_age_01d_with_region():
3132
"""
3233
data = load_earth_age(resolution="01d", region=[-10, 10, -5, 5])
3334
assert data.shape == (11, 21)
34-
assert data.gmt.registration == 0
35+
assert data.gmt.registration == GridReg.GRIDLINE
3536
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
3637
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
3738
npt.assert_allclose(data.min(), 11.13, atol=0.01)
@@ -45,7 +46,7 @@ def test_earth_age_01m_default_registration():
4546
"""
4647
data = load_earth_age(resolution="01m", region=[-10, -9, 3, 5])
4748
assert data.shape == (121, 61)
48-
assert data.gmt.registration == 0
49+
assert data.gmt.registration == GridReg.GRIDLINE
4950
assert data.coords["lat"].data.min() == 3.0
5051
assert data.coords["lat"].data.max() == 5.0
5152
assert data.coords["lon"].data.min() == -10.0

pygmt/tests/test_datasets_earth_day.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import numpy.testing as npt
77
from pygmt.datasets import load_blue_marble
8+
from pygmt.enums import GridReg, GridType
89

910

1011
def test_blue_marble_01d():
@@ -18,8 +19,8 @@ def test_blue_marble_01d():
1819
assert data.attrs["description"] == "NASA Day Images"
1920
assert data.shape == (3, 180, 360)
2021
assert data.dtype == "uint8"
21-
assert data.gmt.registration == 1
22-
assert data.gmt.gtype == 1
22+
assert data.gmt.registration == GridReg.PIXEL
23+
assert data.gmt.gtype == GridType.GEOGRAPHIC
2324
npt.assert_allclose(data.y, np.arange(89.5, -90.5, -1))
2425
npt.assert_allclose(data.x, np.arange(-179.5, 180.5, 1))
2526
npt.assert_allclose(data.min(), 10, atol=1)
@@ -33,8 +34,8 @@ def test_blue_marble_01d_with_region():
3334
data = load_blue_marble(resolution="01d", region=[-10, 10, -5, 5])
3435
assert data.shape == (3, 10, 20)
3536
assert data.dtype == "uint8"
36-
assert data.gmt.registration == 1
37-
assert data.gmt.gtype == 1
37+
assert data.gmt.registration == GridReg.PIXEL
38+
assert data.gmt.gtype == GridType.GEOGRAPHIC
3839
npt.assert_allclose(data.y, np.arange(4.5, -5.5, -1))
3940
npt.assert_allclose(data.x, np.arange(-9.5, 10.5, 1))
4041
npt.assert_allclose(data.min(), 10, atol=1)

pygmt/tests/test_datasets_earth_free_air_anomaly.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import numpy.testing as npt
77
from pygmt.datasets import load_earth_free_air_anomaly
8+
from pygmt.enums import GridReg
89

910

1011
def test_earth_faa_01d():
@@ -18,7 +19,7 @@ def test_earth_faa_01d():
1819
assert data.attrs["units"] == "mGal"
1920
assert data.attrs["horizontal_datum"] == "WGS84"
2021
assert data.shape == (181, 361)
21-
assert data.gmt.registration == 0
22+
assert data.gmt.registration == GridReg.GRIDLINE
2223
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
2324
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
2425
npt.assert_allclose(data.min(), -188.85, atol=0.025)
@@ -31,7 +32,7 @@ def test_earth_faa_01d_with_region():
3132
"""
3233
data = load_earth_free_air_anomaly(resolution="01d", region=[-10, 10, -5, 5])
3334
assert data.shape == (11, 21)
34-
assert data.gmt.registration == 0
35+
assert data.gmt.registration == GridReg.GRIDLINE
3536
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
3637
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
3738
npt.assert_allclose(data.min(), -36.125, atol=0.025)
@@ -45,7 +46,7 @@ def test_earth_faa_01m_default_registration():
4546
"""
4647
data = load_earth_free_air_anomaly(resolution="01m", region=[-10, -9, 3, 5])
4748
assert data.shape == (120, 60)
48-
assert data.gmt.registration == 1
49+
assert data.gmt.registration == GridReg.PIXEL
4950
npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333)
5051
npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666)
5152
npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666)

pygmt/tests/test_datasets_earth_geoid.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import numpy.testing as npt
77
from pygmt.datasets import load_earth_geoid
8+
from pygmt.enums import GridReg
89

910

1011
def test_earth_geoid_01d():
@@ -18,7 +19,7 @@ def test_earth_geoid_01d():
1819
assert data.attrs["units"] == "m"
1920
assert data.attrs["horizontal_datum"] == "WGS84"
2021
assert data.shape == (181, 361)
21-
assert data.gmt.registration == 0
22+
assert data.gmt.registration == GridReg.GRIDLINE
2223
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
2324
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
2425
npt.assert_allclose(data.min(), -106.06, atol=0.01)
@@ -31,7 +32,7 @@ def test_earth_geoid_01d_with_region():
3132
"""
3233
data = load_earth_geoid(resolution="01d", region=[-10, 10, -5, 5])
3334
assert data.shape == (11, 21)
34-
assert data.gmt.registration == 0
35+
assert data.gmt.registration == GridReg.GRIDLINE
3536
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
3637
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
3738
npt.assert_allclose(data.min(), 5.57, atol=0.01)
@@ -45,7 +46,7 @@ def test_earth_geoid_01m_default_registration():
4546
"""
4647
data = load_earth_geoid(resolution="01m", region=[-10, -9, 3, 5])
4748
assert data.shape == (121, 61)
48-
assert data.gmt.registration == 0
49+
assert data.gmt.registration == GridReg.GRIDLINE
4950
assert data.coords["lat"].data.min() == 3.0
5051
assert data.coords["lat"].data.max() == 5.0
5152
assert data.coords["lon"].data.min() == -10.0

pygmt/tests/test_datasets_earth_magnetic_anomaly.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy.testing as npt
77
import pytest
88
from pygmt.datasets import load_earth_magnetic_anomaly
9+
from pygmt.enums import GridReg
910
from pygmt.exceptions import GMTInvalidInput
1011

1112

@@ -20,7 +21,7 @@ def test_earth_mag_01d():
2021
assert data.attrs["units"] == "nT"
2122
assert data.attrs["horizontal_datum"] == "WGS84"
2223
assert data.shape == (181, 361)
23-
assert data.gmt.registration == 0
24+
assert data.gmt.registration == GridReg.GRIDLINE
2425
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
2526
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
2627
npt.assert_allclose(data.min(), -336.2, atol=0.2)
@@ -33,7 +34,7 @@ def test_earth_mag_01d_with_region():
3334
"""
3435
data = load_earth_magnetic_anomaly(resolution="01d", region=[-10, 10, -5, 5])
3536
assert data.shape == (11, 21)
36-
assert data.gmt.registration == 0
37+
assert data.gmt.registration == GridReg.GRIDLINE
3738
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
3839
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
3940
npt.assert_allclose(data.min(), -54.4, atol=0.2)
@@ -47,7 +48,7 @@ def test_earth_mag_02m_default_registration():
4748
"""
4849
data = load_earth_magnetic_anomaly(resolution="02m", region=[-10, -9, 3, 5])
4950
assert data.shape == (60, 30)
50-
assert data.gmt.registration == 1
51+
assert data.gmt.registration == GridReg.PIXEL
5152
npt.assert_allclose(data.coords["lat"].data.min(), 3.016666667)
5253
npt.assert_allclose(data.coords["lat"].data.max(), 4.983333333)
5354
npt.assert_allclose(data.coords["lon"].data.min(), -9.98333333)
@@ -67,7 +68,7 @@ def test_earth_mag4km_01d():
6768
assert data.attrs["units"] == "nT"
6869
assert data.attrs["horizontal_datum"] == "WGS84"
6970
assert data.shape == (181, 361)
70-
assert data.gmt.registration == 0
71+
assert data.gmt.registration == GridReg.GRIDLINE
7172
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
7273
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
7374
npt.assert_allclose(data.min(), -436.8, atol=0.2)
@@ -102,7 +103,7 @@ def test_earth_mag4km_02m_default_registration():
102103
data_source="emag2_4km",
103104
)
104105
assert data.shape == (60, 90)
105-
assert data.gmt.registration == 1
106+
assert data.gmt.registration == GridReg.PIXEL
106107
npt.assert_allclose(data.coords["lat"].data.min(), 4.01666667)
107108
npt.assert_allclose(data.coords["lat"].data.max(), 5.98333333)
108109
npt.assert_allclose(data.coords["lon"].data.min(), -114.98333333)
@@ -154,7 +155,7 @@ def test_earth_mag_03m_wdmam_with_region():
154155
data = load_earth_magnetic_anomaly(
155156
resolution="03m", region=[10, 13, -60, -58], data_source="wdmam"
156157
)
157-
assert data.gmt.registration == 0
158+
assert data.gmt.registration == GridReg.GRIDLINE
158159
assert data.shape == (41, 61)
159160
assert data.lat.min() == -60
160161
assert data.lat.max() == -58

pygmt/tests/test_datasets_earth_mask.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import numpy.testing as npt
77
from pygmt.datasets import load_earth_mask
8+
from pygmt.enums import GridReg, GridType
89

910

1011
def test_earth_mask_01d():
@@ -16,8 +17,8 @@ def test_earth_mask_01d():
1617
assert data.attrs["description"] == "GSHHG Earth mask"
1718
assert data.attrs["horizontal_datum"] == "WGS84"
1819
assert data.shape == (181, 361)
19-
assert data.gmt.registration == 0
20-
assert data.gmt.gtype == 1
20+
assert data.gmt.registration == GridReg.GRIDLINE
21+
assert data.gmt.gtype == GridType.GEOGRAPHIC
2122
assert data.dtype == "int8"
2223
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
2324
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
@@ -32,8 +33,8 @@ def test_earth_mask_01d_with_region():
3233
"""
3334
data = load_earth_mask(resolution="01d", region=[-7, 4, 13, 19])
3435
assert data.shape == (7, 12)
35-
assert data.gmt.registration == 0
36-
assert data.gmt.gtype == 1
36+
assert data.gmt.registration == GridReg.GRIDLINE
37+
assert data.gmt.gtype == GridType.GEOGRAPHIC
3738
assert data.dtype == "int8"
3839
npt.assert_allclose(data.lat, np.arange(13, 20, 1))
3940
npt.assert_allclose(data.lon, np.arange(-7, 5, 1))

pygmt/tests/test_datasets_earth_night.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import numpy.testing as npt
77
from pygmt.datasets import load_black_marble
8+
from pygmt.enums import GridReg, GridType
89

910

1011
def test_black_marble_01d():
@@ -18,8 +19,8 @@ def test_black_marble_01d():
1819
assert data.attrs["description"] == "NASA Night Images"
1920
assert data.shape == (3, 180, 360)
2021
assert data.dtype == "uint8"
21-
assert data.gmt.registration == 1
22-
assert data.gmt.gtype == 1
22+
assert data.gmt.registration == GridReg.PIXEL
23+
assert data.gmt.gtype == GridType.GEOGRAPHIC
2324
npt.assert_allclose(data.y, np.arange(89.5, -90.5, -1))
2425
npt.assert_allclose(data.x, np.arange(-179.5, 180.5, 1))
2526
npt.assert_allclose(data.min(), 3, atol=1)
@@ -33,8 +34,8 @@ def test_black_marble_01d_with_region():
3334
data = load_black_marble(resolution="01d", region=[-10, 10, -5, 5])
3435
assert data.shape == (3, 10, 20)
3536
assert data.dtype == "uint8"
36-
assert data.gmt.registration == 1
37-
assert data.gmt.gtype == 1
37+
assert data.gmt.registration == GridReg.PIXEL
38+
assert data.gmt.gtype == GridType.GEOGRAPHIC
3839
npt.assert_allclose(data.y, np.arange(4.5, -5.5, -1))
3940
npt.assert_allclose(data.x, np.arange(-9.5, 10.5, 1))
4041
npt.assert_allclose(data.min(), 3, atol=1)

pygmt/tests/test_datasets_earth_relief.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from packaging.version import Version
99
from pygmt.clib import __gmt_version__
1010
from pygmt.datasets import load_earth_relief
11+
from pygmt.enums import GridReg
1112
from pygmt.exceptions import GMTInvalidInput
1213

1314

@@ -25,7 +26,7 @@ def test_earth_relief_01d_igpp_synbath(data_source):
2526
assert data.attrs["vertical_datum"] == "EGM96"
2627
assert data.attrs["horizontal_datum"] == "WGS84"
2728
assert data.shape == (181, 361)
28-
assert data.gmt.registration == 0
29+
assert data.gmt.registration == GridReg.GRIDLINE
2930
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
3031
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
3132
npt.assert_allclose(data.min(), -7174.0, atol=0.5)
@@ -45,7 +46,7 @@ def test_earth_relief_01d_gebco(data_source):
4546
assert data.attrs["vertical_datum"] == "EGM96"
4647
assert data.attrs["horizontal_datum"] == "WGS84"
4748
assert data.shape == (181, 361)
48-
assert data.gmt.registration == 0
49+
assert data.gmt.registration == GridReg.GRIDLINE
4950
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
5051
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
5152
npt.assert_allclose(data.min(), -7169.0, atol=1.0)
@@ -62,7 +63,7 @@ def test_earth_relief_01d_with_region_srtm():
6263
data_source="igpp",
6364
)
6465
assert data.shape == (11, 21)
65-
assert data.gmt.registration == 0
66+
assert data.gmt.registration == GridReg.GRIDLINE
6667
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
6768
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
6869
npt.assert_allclose(data.min(), -5118.0, atol=0.5)
@@ -79,7 +80,7 @@ def test_earth_relief_01d_with_region_gebco():
7980
data_source="gebco",
8081
)
8182
assert data.shape == (11, 21)
82-
assert data.gmt.registration == 0
83+
assert data.gmt.registration == GridReg.GRIDLINE
8384
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
8485
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
8586
npt.assert_allclose(data.min(), -5118.0, atol=1.0)
@@ -92,7 +93,7 @@ def test_earth_relief_30m():
9293
"""
9394
data = load_earth_relief(resolution="30m")
9495
assert data.shape == (361, 721)
95-
assert data.gmt.registration == 0
96+
assert data.gmt.registration == GridReg.GRIDLINE
9697
npt.assert_allclose(data.lat, np.arange(-90, 90.5, 0.5))
9798
npt.assert_allclose(data.lon, np.arange(-180, 180.5, 0.5))
9899
npt.assert_allclose(data.min(), -8279.5, atol=0.5)
@@ -110,7 +111,7 @@ def test_earth_gebcosi_15m_with_region():
110111
data_source="gebcosi",
111112
)
112113
assert data.shape == (16, 8)
113-
assert data.gmt.registration == 1
114+
assert data.gmt.registration == GridReg.PIXEL
114115
npt.assert_allclose(data.lat, np.arange(-87.875, -84, 0.25))
115116
npt.assert_allclose(data.lon, np.arange(85.125, 87, 0.25))
116117
npt.assert_allclose(data.min(), -492, atol=1.0)
@@ -183,7 +184,7 @@ def test_earth_relief_15s_default_registration():
183184
"""
184185
data = load_earth_relief(resolution="15s", region=[-10, -9.5, 4, 5])
185186
assert data.shape == (240, 120)
186-
assert data.gmt.registration == 1
187+
assert data.gmt.registration == GridReg.PIXEL
187188
npt.assert_allclose(data.coords["lat"].data.min(), 4.002083)
188189
npt.assert_allclose(data.coords["lat"].data.max(), 4.997917)
189190
npt.assert_allclose(data.coords["lon"].data.min(), -9.997917)
@@ -203,7 +204,7 @@ def test_earth_relief_03s_default_registration():
203204
"""
204205
data = load_earth_relief(resolution="03s", region=[-10, -9.8, 4.9, 5])
205206
assert data.shape == (121, 241)
206-
assert data.gmt.registration == 0
207+
assert data.gmt.registration == GridReg.GRIDLINE
207208
npt.assert_allclose(data.coords["lat"].data.min(), 4.9)
208209
npt.assert_allclose(data.coords["lat"].data.max(), 5)
209210
npt.assert_allclose(data.coords["lon"].data.min(), -10)

0 commit comments

Comments
 (0)