Skip to content

Fix the test for the default registration of earth_mag4km_02m dataset (#2341 #2341

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
Feb 3, 2023
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
1 change: 1 addition & 0 deletions pygmt/helpers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def download_test_data():
"@earth_mag_01d_g",
"@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test
"@earth_mag4km_01d_g",
"@S30W120.earth_mag4km_02m_p.nc", # Specific grid for 02m test
# Earth mask grid
"@earth_mask_01d_g",
# Earth free-air anomaly grids
Expand Down
50 changes: 28 additions & 22 deletions pygmt/tests/test_datasets_earth_magnetic_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ def test_earth_mag_incorrect_resolution_registration():
)


def test_earth_mag_02m_default_registration():
"""
Test that the grid returned by default for the 2 arc-minute resolution has
a "pixel" registration.
"""
data = load_earth_magnetic_anomaly(resolution="02m", region=[-10, -9, 3, 5])
assert data.shape == (60, 30)
assert data.gmt.registration == 1
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)
npt.assert_allclose(data.coords["lon"].data.max(), -9.01666667)
npt.assert_allclose(data.min(), -231)
npt.assert_allclose(data.max(), 131.79999)


def test_earth_mag4km_01d():
"""
Test some properties of the magnetic anomaly 4km 01d data.
Expand Down Expand Up @@ -114,34 +130,24 @@ def test_earth_mag4km_01d_with_region():
npt.assert_allclose(data.max(), 113.59985)


def test_earth_mag_02m_default_registration():
def test_earth_mag4km_02m_default_registration():
"""
Test that the grid returned by default for the 2 arc-minute resolution has
a "pixel" registration.
"""
data = load_earth_magnetic_anomaly(resolution="02m", region=[-10, -9, 3, 5])
assert data.shape == (60, 30)
assert data.gmt.registration == 1
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)
npt.assert_allclose(data.coords["lon"].data.max(), -9.01666667)
npt.assert_allclose(data.min(), -231)
npt.assert_allclose(data.max(), 131.79999)

data = load_earth_magnetic_anomaly(
resolution="05m",
resolution="02m",
region=[-115, -112, 4, 6],
registration="gridline",
data_source="emag2_4km",
)
assert data.shape == (25, 37)
assert data.lat.min() == 4
assert data.lat.max() == 6
assert data.lon.min() == -115
assert data.lon.max() == -112
npt.assert_allclose(data.min(), -128.40015)
npt.assert_allclose(data.max(), 76.80005)
assert data.shape == (60, 90)
assert data.gmt.registration == 1
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)
npt.assert_allclose(data.coords["lon"].data.max(), -112.01666667)
npt.assert_allclose(data.min(), -132.80005)
npt.assert_allclose(data.max(), 79.59985)


def test_earth_mag_01d_wdmam():
Expand Down Expand Up @@ -196,13 +202,13 @@ def test_earth_mag_03m_wdmam_with_region():
npt.assert_allclose(data.max(), 629.6)


def test_earth_mag_05m_wdmam_without_region():
def test_earth_mag_03m_wdmam_without_region():
"""
Test loading a high-resolution WDMAM grid without passing 'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_magnetic_anomaly(
resolution="05m", registration="gridline", data_source="wdmam"
resolution="03m", registration="gridline", data_source="wdmam"
)


Expand Down