Skip to content

Set registration and gtype properly as enums on gmt accessor init #3942

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

Merged
merged 4 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pygmt/tests/test_binstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def test_binstats_no_outgrid():
region="g",
)
assert temp_grid.dims == ("y", "x")
assert temp_grid.gmt.gtype == GridType.CARTESIAN
assert temp_grid.gmt.registration == GridRegistration.GRIDLINE
assert temp_grid.gmt.gtype is GridType.CARTESIAN
assert temp_grid.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(temp_grid.max(), 35971536)
npt.assert_allclose(temp_grid.min(), 53)
npt.assert_allclose(temp_grid.median(), 1232714.5)
Expand Down
6 changes: 3 additions & 3 deletions pygmt/tests/test_datasets_earth_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_earth_age_01d():
assert data.attrs["units"] == "Myr"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), 0.37, atol=0.01)
Expand All @@ -32,7 +32,7 @@ def test_earth_age_01d_with_region():
"""
data = load_earth_age(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), 11.13, atol=0.01)
Expand All @@ -46,7 +46,7 @@ def test_earth_age_01m_default_registration():
"""
data = load_earth_age(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (121, 61)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
assert data.coords["lat"].data.min() == 3.0
assert data.coords["lat"].data.max() == 5.0
assert data.coords["lon"].data.min() == -10.0
Expand Down
8 changes: 4 additions & 4 deletions pygmt/tests/test_datasets_earth_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def test_blue_marble_01d():
assert data.attrs["description"] == "NASA Day Images"
assert data.shape == (3, 180, 360)
assert data.dtype == "uint8"
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.gtype == GridType.GEOGRAPHIC
assert data.gmt.registration is GridRegistration.PIXEL
assert data.gmt.gtype is GridType.GEOGRAPHIC
npt.assert_allclose(data.y, np.arange(89.5, -90.5, -1))
npt.assert_allclose(data.x, np.arange(-179.5, 180.5, 1))
npt.assert_allclose(data.min(), 10, atol=1)
Expand All @@ -34,8 +34,8 @@ def test_blue_marble_01d_with_region():
data = load_blue_marble(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (3, 10, 20)
assert data.dtype == "uint8"
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.gtype == GridType.GEOGRAPHIC
assert data.gmt.registration is GridRegistration.PIXEL
assert data.gmt.gtype is GridType.GEOGRAPHIC
npt.assert_allclose(data.y, np.arange(4.5, -5.5, -1))
npt.assert_allclose(data.x, np.arange(-9.5, 10.5, 1))
npt.assert_allclose(data.min(), 10, atol=1)
Expand Down
12 changes: 6 additions & 6 deletions pygmt/tests/test_datasets_earth_deflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_earth_edefl_01d():
assert data.attrs["units"] == "micro-radians"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), -142.64, atol=0.04)
Expand All @@ -33,7 +33,7 @@ def test_earth_edefl_01d_with_region():
"""
data = load_earth_deflection(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), -28.92, atol=0.04)
Expand All @@ -47,7 +47,7 @@ def test_earth_edefl_01m_default_registration():
"""
data = load_earth_deflection(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (120, 60)
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.registration is GridRegistration.PIXEL
npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333)
npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666)
npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666)
Expand All @@ -67,7 +67,7 @@ def test_earth_ndefl_01d():
assert data.attrs["units"] == "micro-radians"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), -214.8, atol=0.04)
Expand All @@ -82,7 +82,7 @@ def test_earth_ndefl_01d_with_region():
resolution="01d", region=[-10, 10, -5, 5], component="north"
)
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), -48.08, atol=0.04)
Expand All @@ -98,7 +98,7 @@ def test_earth_ndefl_01m_default_registration():
resolution="01m", region=[-10, -9, 3, 5], component="north"
)
assert data.shape == (120, 60)
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.registration is GridRegistration.PIXEL
npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333)
npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666)
npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666)
Expand Down
6 changes: 3 additions & 3 deletions pygmt/tests/test_datasets_earth_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_earth_dist_01d():
assert data.attrs["units"] == "kilometers"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), -2655.7, atol=0.01)
Expand All @@ -31,7 +31,7 @@ def test_earth_dist_01d_with_region():
"""
data = load_earth_dist(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), -1081.94, atol=0.01)
Expand All @@ -45,7 +45,7 @@ def test_earth_dist_01m_default_registration():
"""
data = load_earth_dist(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (121, 61)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
assert data.coords["lat"].data.min() == 3.0
assert data.coords["lat"].data.max() == 5.0
assert data.coords["lon"].data.min() == -10.0
Expand Down
12 changes: 6 additions & 6 deletions pygmt/tests/test_datasets_earth_free_air_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_earth_faa_01d():
assert data.attrs["units"] == "mGal"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), -188.85, atol=0.025)
Expand All @@ -32,7 +32,7 @@ def test_earth_faa_01d_with_region():
"""
data = load_earth_free_air_anomaly(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), -36.125, atol=0.025)
Expand All @@ -46,7 +46,7 @@ def test_earth_faa_01m_default_registration():
"""
data = load_earth_free_air_anomaly(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (120, 60)
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.registration is GridRegistration.PIXEL
npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333)
npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666)
npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666)
Expand All @@ -66,7 +66,7 @@ def test_earth_faaerror_01d():
assert data.attrs["units"] == "mGal"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), 0.0, atol=0.04)
Expand All @@ -81,7 +81,7 @@ def test_earth_faaerror_01d_with_region():
resolution="01d", region=[-10, 10, -5, 5], uncertainty=True
)
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), 0.72, atol=0.04)
Expand All @@ -97,7 +97,7 @@ def test_earth_faaerror_01m_default_registration():
resolution="01m", region=[-10, -9, 3, 5], uncertainty=True
)
assert data.shape == (120, 60)
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.registration is GridRegistration.PIXEL
npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333)
npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666)
npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666)
Expand Down
6 changes: 3 additions & 3 deletions pygmt/tests/test_datasets_earth_geoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_earth_geoid_01d():
assert data.attrs["units"] == "meters"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), -106.06, atol=0.01)
Expand All @@ -32,7 +32,7 @@ def test_earth_geoid_01d_with_region():
"""
data = load_earth_geoid(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), 5.57, atol=0.01)
Expand All @@ -46,7 +46,7 @@ def test_earth_geoid_01m_default_registration():
"""
data = load_earth_geoid(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (121, 61)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
assert data.coords["lat"].data.min() == 3.0
assert data.coords["lat"].data.max() == 5.0
assert data.coords["lon"].data.min() == -10.0
Expand Down
12 changes: 6 additions & 6 deletions pygmt/tests/test_datasets_earth_magnetic_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_earth_mag_01d():
assert data.attrs["units"] == "nT"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), -336.2, atol=0.2)
Expand All @@ -34,7 +34,7 @@ def test_earth_mag_01d_with_region():
"""
data = load_earth_magnetic_anomaly(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), -54.4, atol=0.2)
Expand All @@ -48,7 +48,7 @@ def test_earth_mag_02m_default_registration():
"""
data = load_earth_magnetic_anomaly(resolution="02m", region=[-10, -9, 3, 5])
assert data.shape == (60, 30)
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.registration is GridRegistration.PIXEL
npt.assert_allclose(data.coords["lat"].data.min(), 3.016666667)
npt.assert_allclose(data.coords["lat"].data.max(), 4.983333333)
npt.assert_allclose(data.coords["lon"].data.min(), -9.98333333)
Expand All @@ -68,7 +68,7 @@ def test_earth_mag4km_01d():
assert data.attrs["units"] == "nT"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), -436.8, atol=0.2)
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_earth_mag4km_02m_default_registration():
data_source="emag2_4km",
)
assert data.shape == (60, 90)
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.registration is GridRegistration.PIXEL
npt.assert_allclose(data.coords["lat"].data.min(), 4.01666667)
npt.assert_allclose(data.coords["lat"].data.max(), 5.98333333)
npt.assert_allclose(data.coords["lon"].data.min(), -114.98333333)
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_earth_mag_03m_wdmam_with_region():
data = load_earth_magnetic_anomaly(
resolution="03m", region=[10, 13, -60, -58], data_source="wdmam"
)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
assert data.shape == (41, 61)
assert data.lat.min() == -60
assert data.lat.max() == -58
Expand Down
8 changes: 4 additions & 4 deletions pygmt/tests/test_datasets_earth_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_earth_mask_01d():
assert data.attrs["description"] == "GSHHG Earth mask"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.gtype == GridType.GEOGRAPHIC
assert data.gmt.registration is GridRegistration.GRIDLINE
assert data.gmt.gtype is GridType.GEOGRAPHIC
assert data.dtype == "int8"
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
Expand All @@ -33,8 +33,8 @@ def test_earth_mask_01d_with_region():
"""
data = load_earth_mask(resolution="01d", region=[-7, 4, 13, 19])
assert data.shape == (7, 12)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.gtype == GridType.GEOGRAPHIC
assert data.gmt.registration is GridRegistration.GRIDLINE
assert data.gmt.gtype is GridType.GEOGRAPHIC
assert data.dtype == "int8"
npt.assert_allclose(data.lat, np.arange(13, 20, 1))
npt.assert_allclose(data.lon, np.arange(-7, 5, 1))
Expand Down
6 changes: 3 additions & 3 deletions pygmt/tests/test_datasets_earth_mean_sea_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_earth_mss_01d():
assert data.attrs["units"] == "meters"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
npt.assert_allclose(data.min(), -104.71, atol=0.01)
Expand All @@ -31,7 +31,7 @@ def test_earth_mss_01d_with_region():
"""
data = load_earth_mean_sea_surface(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
npt.assert_allclose(data.min(), 6.53, atol=0.01)
Expand All @@ -45,7 +45,7 @@ def test_earth_mss_01m_default_registration():
"""
data = load_earth_mean_sea_surface(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (121, 61)
assert data.gmt.registration == GridRegistration.GRIDLINE
assert data.gmt.registration is GridRegistration.GRIDLINE
assert data.coords["lat"].data.min() == 3.0
assert data.coords["lat"].data.max() == 5.0
assert data.coords["lon"].data.min() == -10.0
Expand Down
8 changes: 4 additions & 4 deletions pygmt/tests/test_datasets_earth_night.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def test_black_marble_01d():
assert data.attrs["description"] == "NASA Night Images"
assert data.shape == (3, 180, 360)
assert data.dtype == "uint8"
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.gtype == GridType.GEOGRAPHIC
assert data.gmt.registration is GridRegistration.PIXEL
assert data.gmt.gtype is GridType.GEOGRAPHIC
npt.assert_allclose(data.y, np.arange(89.5, -90.5, -1))
npt.assert_allclose(data.x, np.arange(-179.5, 180.5, 1))
npt.assert_allclose(data.min(), 3, atol=1)
Expand All @@ -34,8 +34,8 @@ def test_black_marble_01d_with_region():
data = load_black_marble(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (3, 10, 20)
assert data.dtype == "uint8"
assert data.gmt.registration == GridRegistration.PIXEL
assert data.gmt.gtype == GridType.GEOGRAPHIC
assert data.gmt.registration is GridRegistration.PIXEL
assert data.gmt.gtype is GridType.GEOGRAPHIC
npt.assert_allclose(data.y, np.arange(4.5, -5.5, -1))
npt.assert_allclose(data.x, np.arange(-9.5, 10.5, 1))
npt.assert_allclose(data.min(), 3, atol=1)
Expand Down
Loading