Skip to content
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

Set gridline (if available) as the default grid registration for remote datasets #2266

Merged
merged 44 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
39203d5
update default registration for load_earth_relief
willschlitzer Dec 22, 2022
dd1b685
update default registration for load_earth_age
willschlitzer Dec 22, 2022
dcb09b5
Merge branch 'main' into load-remote-dataset/set-default-registration
seisman Dec 26, 2022
5d649e6
Update pygmt/datasets/load_remote_dataset.py
seisman Dec 26, 2022
ead76a0
Merge branch 'main' into load-remote-dataset/set-default-registration
willschlitzer Dec 27, 2022
24b8931
change if statement for default registration
willschlitzer Dec 27, 2022
bdfc550
add default registration testing for test_datasets_earth_age.py
willschlitzer Dec 27, 2022
7b0a219
update earth_age registration docstring
willschlitzer Dec 27, 2022
2fefe64
update earth_free_air_anomaly registration docstring
willschlitzer Dec 27, 2022
3442893
update test_datasets_earth_free_air_anomaly.py for default registration
willschlitzer Dec 27, 2022
d36f53d
update registration docstring in earth_geoid.py
willschlitzer Dec 27, 2022
24b3e73
add test to test_datasets_earth_geoid.py for default registration
willschlitzer Dec 27, 2022
2a64cf5
update registration docstring in earth_magnetic_anomaly.py
willschlitzer Dec 27, 2022
eaa57ae
add test to test_datasets_earth_magnetic_anomaly.py for default regis…
willschlitzer Dec 27, 2022
040883e
update registration docstring in earth_vertical_gravity_gradient.py
willschlitzer Dec 27, 2022
79ca10e
run make format
willschlitzer Dec 27, 2022
664d7da
add test for default registration to test_datasets_earth_vertical_gra…
willschlitzer Dec 27, 2022
c7fa8f5
update registration docstring to earth_relief.py
willschlitzer Dec 27, 2022
7ec384d
remove note in earth_relief.py
willschlitzer Dec 27, 2022
1fadc26
add tests for loading default registrations for 15s and 03s to test_d…
willschlitzer Dec 27, 2022
6f306fd
run make format
willschlitzer Dec 27, 2022
e24bcbc
Update pygmt/datasets/load_remote_dataset.py
willschlitzer Dec 27, 2022
087e6a9
remove test_earth_age_05m_with_region from test_datasets_earth_age.py
willschlitzer Dec 27, 2022
75519f7
remove test_earth_faa_05m_with_region from test_datasets_earth_free_a…
willschlitzer Dec 27, 2022
f668947
remove test_earth_geoid_05m_with_region from test_datasets_earth_geoi…
willschlitzer Dec 27, 2022
78fc8c1
remove test_earth_mag_05m_with_region from test_datasets_earth_magnet…
willschlitzer Dec 27, 2022
ae6176d
remove test_earth_vertical_gravity_gradient_05m_with_region from test…
willschlitzer Dec 27, 2022
3714ccc
remove test_earth_relief_05m_with_region from test_datasets_earth_rel…
willschlitzer Dec 27, 2022
9bfb317
uncomment pull_request for cache data
willschlitzer Dec 27, 2022
bea25d5
recomment pull_request for cache data
willschlitzer Dec 27, 2022
05f79a1
Apply suggestions from code review
willschlitzer Dec 28, 2022
8b09c33
Apply suggestions from code review
willschlitzer Dec 28, 2022
6a984e5
Merge branch 'main' into load-remote-dataset/set-default-registration
willschlitzer Dec 28, 2022
60c1eee
remove 05m mag4km test
willschlitzer Dec 28, 2022
224bbcf
change 05m to 01m resolution in test_datasets_earth_magnetic_anomaly.py
willschlitzer Dec 28, 2022
c624d43
change 05m to 01m resolution in test_datasets_earth_age.py
willschlitzer Dec 28, 2022
cad7796
change 05m to 01m resolution in test_datasets_earth_free_air_anomaly.py
willschlitzer Dec 28, 2022
706c5bc
change 05m to 01m resolution in test_datasets_earth_geoid.py
willschlitzer Dec 28, 2022
9cb34ec
change 05m to 01m resolution in test_datasets_earth_relief.py
willschlitzer Dec 28, 2022
6235bab
change 05m to 01m resolution in test_datasets_earth_vertical_gravity_…
willschlitzer Dec 28, 2022
f3fc043
Merge branch 'main' into load-remote-dataset/set-default-registration
willschlitzer Dec 28, 2022
f8553d5
Apply suggestions from code review
willschlitzer Dec 28, 2022
a2e508d
run make format
willschlitzer Dec 28, 2022
cedfa26
Always check if gridline is the default registration for 01d resolution
seisman Dec 28, 2022
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: 1 addition & 3 deletions pygmt/datasets/earth_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def load_earth_age(resolution="01d", region=None, registration=None):

registration : str
Grid registration type. Either ``"pixel"`` for pixel registration or
``"gridline"`` for gridline registration. Default is ``None``, where
a pixel-registered grid is returned unless only the
gridline-registered grid is available.
``"gridline"`` for gridline registration. Default is ``"gridline"``.

Returns
-------
Expand Down
5 changes: 2 additions & 3 deletions pygmt/datasets/earth_free_air_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ def load_earth_free_air_anomaly(resolution="01d", region=None, registration=None

registration : str
Grid registration type. Either ``"pixel"`` for pixel registration or
``"gridline"`` for gridline registration. Default is ``None``, where
a pixel-registered grid is returned unless only the
gridline-registered grid is available.
``"gridline"`` for gridline registration. Default is ``"gridline"``
for all resolutions except ``"01m"`` which is ``"pixel"`` only.

Returns
-------
Expand Down
4 changes: 1 addition & 3 deletions pygmt/datasets/earth_geoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def load_earth_geoid(resolution="01d", region=None, registration=None):

registration : str
Grid registration type. Either ``"pixel"`` for pixel registration or
``"gridline"`` for gridline registration. Default is ``None``, where
a pixel-registered grid is returned unless only the
gridline-registered grid is available.
``"gridline"`` for gridline registration. Default is ``"gridline"``.

Returns
-------
Expand Down
5 changes: 2 additions & 3 deletions pygmt/datasets/earth_magnetic_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def load_earth_magnetic_anomaly(

registration : str
Grid registration type. Either ``"pixel"`` for pixel registration or
``"gridline"`` for gridline registration. Default is ``None``, where
a pixel-registered grid is returned unless only the
gridline-registered grid is available.
``"gridline"`` for gridline registration. Default is ``"gridline"``
for all resolutions except ``"02m"`` which is ``"pixel"`` only.

mag4km : bool
Choose the data version to use. The default is ``False``, which is
Expand Down
8 changes: 2 additions & 6 deletions pygmt/datasets/earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ def load_earth_relief(

registration : str
Grid registration type. Either ``"pixel"`` for pixel registration or
``"gridline"`` for gridline registration. Default is ``None``, where
a gridline-registered grid is returned unless only the pixel-registered
grid is available.

**Note**: For GMT 6.3, ``registration=None`` returns a pixel-registered
grid by default unless only the gridline-registered grid is available.
``"gridline"`` for gridline registration. Default is ``"gridline"``
for all resolutions except ``"15s"`` which is ``"pixel"`` only.

data_source : str
Select the source for the Earth relief data.
Expand Down
5 changes: 2 additions & 3 deletions pygmt/datasets/earth_vertical_gravity_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ def load_earth_vertical_gravity_gradient(

registration : str
Grid registration type. Either ``"pixel"`` for pixel registration or
``"gridline"`` for gridline registration. Default is ``None``, where
a pixel-registered grid is returned unless only the
gridline-registered grid is available.
``"gridline"`` for gridline registration. Default is ``"gridline"``
for all resolutions except ``"01m"`` which is ``"pixel"`` only.

Returns
-------
Expand Down
24 changes: 15 additions & 9 deletions pygmt/datasets/load_remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,26 @@ def _load_remote_dataset(
The returned :class:`xarray.DataArray` doesn't support slice operation for
tiled grids.
"""

if registration in ("pixel", "gridline", None):
# If None, let GMT decide on Pixel/Gridline type
reg = f"_{registration[0]}" if registration else ""
dataset = datasets[dataset_name]
if resolution not in dataset.resolutions.keys():
raise GMTInvalidInput(f"Invalid resolution '{resolution}'.")
if registration is None:
# Check if "gridline" is an available registration for the resolution
if "gridline" in dataset.resolutions[resolution].registrations:
# Use default of gridline registration if available
registration = "gridline"
else:
registration = "pixel"
if registration in ("pixel", "gridline"):
reg = f"_{registration[0]}"
else:
raise GMTInvalidInput(
f"Invalid grid registration: '{registration}', should be either "
"'pixel', 'gridline' or None. Default is None, where a "
"pixel-registered grid is returned unless only the "
"gridline-registered grid is available."
"gridline-registered grid is returned unless only the "
"pixel-registered grid is available."
)
dataset = datasets[dataset_name]
if resolution not in dataset.resolutions.keys():
raise GMTInvalidInput(f"Invalid resolution '{resolution}'.")

if registration and (
registration not in dataset.resolutions[resolution].registrations
):
Expand Down
13 changes: 7 additions & 6 deletions pygmt/helpers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,26 @@ def download_test_data():
"@N37W120.earth_relief_03s_g.nc",
"@N00W090.earth_relief_03m_p.nc",
"@N00E135.earth_relief_30s_g.nc",
"@N00W010.earth_relief_15s_p.nc", # Specific grid for 15s test
"@N04W010.earth_relief_03s_g.nc", # Specific grid for 03s test
# Earth synbath relief grids
"@S15W105.earth_synbath_30s_p.nc",
# Earth seafloor age grids
"@earth_age_01d_g",
"@S90W180.earth_age_05m_g.nc", # Specific grid for 05m test
"@N00W030.earth_age_01m_g.nc", # Specific grid for 01m test
# Earth geoid grids
"@earth_geoid_01d_g",
"@S90W180.earth_geoid_05m_g.nc", # Specific grid for 05m test
"@N00W030.earth_geoid_01m_g.nc", # Specific grid for 01m test
# Earth magnetic anomaly grids
"@earth_mag_01d_g",
"@S90W180.earth_mag_05m_g.nc", # Specific grid for 05m test
"@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test
"@earth_mag4km_01d_g",
"@S90W180.earth_mag4km_05m_g.nc", # Specific grid for 05m test
# Earth free-air anomaly grids
"@earth_faa_01d_g",
"@S90W180.earth_faa_05m_g.nc", # Specific grid for 05m test
"@N00W030.earth_faa_01m_p.nc", # Specific grid for 01m test
# Earth vertical gravity gradient grids
"@earth_vgg_01d_g",
"@S90W180.earth_vgg_05m_g.nc", # Specific grid for 05m test
"@N00W030.earth_vgg_01m_p.nc", # Specific grid for 01m test
# Other cache files
"@capitals.gmt",
"@earth_relief_20m_holes.grd",
Expand Down
45 changes: 22 additions & 23 deletions pygmt/tests/test_datasets_earth_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ def test_earth_age_01d():
"""
Test some properties of the earth age 01d data.
"""
data = load_earth_age(resolution="01d", registration="gridline")
data = load_earth_age(resolution="01d")
assert data.name == "seafloor_age"
assert data.attrs["units"] == "Myr"
assert data.attrs["long_name"] == "age of seafloor crust"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == 0
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.167381, rtol=1e-5)
Expand All @@ -47,39 +48,21 @@ def test_earth_age_01d_with_region():
"""
Test loading low-resolution earth age with 'region'.
"""
data = load_earth_age(
resolution="01d", region=[-10, 10, -5, 5], registration="gridline"
)
data = load_earth_age(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == 0
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.293945)
npt.assert_allclose(data.max(), 125.1189)


def test_earth_age_05m_with_region():
"""
Test loading a subregion of high-resolution earth age.
"""
data = load_earth_age(
resolution="05m", region=[-50, -40, 20, 30], registration="gridline"
)
assert data.coords["lat"].data.min() == 20.0
assert data.coords["lat"].data.max() == 30.0
assert data.coords["lon"].data.min() == -50.0
assert data.coords["lon"].data.max() == -40.0
npt.assert_allclose(data.data.min(), 0.040000916)
npt.assert_allclose(data.data.max(), 46.530003)
assert data.sizes["lat"] == 121
assert data.sizes["lon"] == 121


def test_earth_age_05m_without_region():
def test_earth_age_01m_without_region():
"""
Test loading high-resolution earth age without passing 'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_age("05m")
load_earth_age("01m")


def test_earth_age_incorrect_resolution_registration():
Expand All @@ -89,3 +72,19 @@ def test_earth_age_incorrect_resolution_registration():
"""
with pytest.raises(GMTInvalidInput):
load_earth_age(resolution="01m", region=[0, 1, 3, 5], registration="pixel")


def test_earth_age_01m_default_registration():
"""
Test that the grid returned by default for the 1 arc-minute resolution has
a "gridline" registration.
"""
data = load_earth_age(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (121, 61)
assert data.gmt.registration == 0
assert data.coords["lat"].data.min() == 3.0
assert data.coords["lat"].data.max() == 5.0
assert data.coords["lon"].data.min() == -10.0
assert data.coords["lon"].data.max() == -9.0
npt.assert_allclose(data.min(), 88.63)
npt.assert_allclose(data.max(), 125.25)
42 changes: 21 additions & 21 deletions pygmt/tests/test_datasets_earth_free_air_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ def test_earth_faa_01d():
"""
Test some properties of the free air anomaly 01d data.
"""
data = load_earth_free_air_anomaly(resolution="01d", registration="gridline")
data = load_earth_free_air_anomaly(resolution="01d")
assert data.name == "free_air_anomaly"
assert data.attrs["long_name"] == "IGPP Global Earth Free-Air Anomaly"
assert data.attrs["units"] == "mGal"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == 0
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(), -275.75)
Expand All @@ -47,36 +48,35 @@ def test_earth_faa_01d_with_region():
"""
Test loading low-resolution earth free air anomaly with 'region'.
"""
data = load_earth_free_air_anomaly(
resolution="01d", region=[-10, 10, -5, 5], registration="gridline"
)
data = load_earth_free_air_anomaly(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == 0
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(), -58.75)
npt.assert_allclose(data.max(), 69.524994)


def test_earth_faa_05m_with_region():
def test_earth_faa_01m_without_region():
"""
Test loading a subregion of high-resolution earth free air anomaly data.
Test loading high-resolution earth free air anomaly without passing
'region'.
"""
data = load_earth_free_air_anomaly(
resolution="05m", region=[-115, -112, 4, 6], registration="gridline"
)
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(), -20.5)
npt.assert_allclose(data.max(), -3.9500122)
with pytest.raises(GMTInvalidInput):
load_earth_free_air_anomaly("01m")


def test_earth_faa_05m_without_region():
def test_earth_faa_01m_default_registration():
"""
Test loading high-resolution earth free air anomaly without passing
'region'.
Test that the grid returned by default for the 1 arc-minute resolution has
a "pixel" registration.
"""
with pytest.raises(GMTInvalidInput):
load_earth_free_air_anomaly("05m")
data = load_earth_free_air_anomaly(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (120, 60)
assert data.gmt.registration == 1
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)
npt.assert_allclose(data.coords["lon"].data.max(), -9.00833333)
npt.assert_allclose(data.min(), -51)
npt.assert_allclose(data.max(), 113.675)
45 changes: 22 additions & 23 deletions pygmt/tests/test_datasets_earth_geoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ def test_earth_geoid_01d():
"""
Test some properties of the earth geoid 01d data.
"""
data = load_earth_geoid(resolution="01d", registration="gridline")
data = load_earth_geoid(resolution="01d")
assert data.name == "earth_geoid"
assert data.attrs["units"] == "m"
assert data.attrs["long_name"] == "EGM2008 Global Earth Geoid"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == 0
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.45)
Expand All @@ -47,39 +48,21 @@ def test_earth_geoid_01d_with_region():
"""
Test loading low-resolution earth geoid with 'region'.
"""
data = load_earth_geoid(
resolution="01d", region=[-10, 10, -5, 5], registration="gridline"
)
data = load_earth_geoid(resolution="01d", region=[-10, 10, -5, 5])
assert data.shape == (11, 21)
assert data.gmt.registration == 0
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(), 4.87)
npt.assert_allclose(data.max(), 29.89)


def test_earth_geoid_05m_with_region():
"""
Test loading a subregion of high-resolution earth geoid.
"""
data = load_earth_geoid(
resolution="05m", region=[-50, -40, 20, 30], registration="gridline"
)
assert data.coords["lat"].data.min() == 20.0
assert data.coords["lat"].data.max() == 30.0
assert data.coords["lon"].data.min() == -50.0
assert data.coords["lon"].data.max() == -40.0
npt.assert_allclose(data.min(), -32.79)
npt.assert_allclose(data.max(), 16.57)
assert data.sizes["lat"] == 121
assert data.sizes["lon"] == 121


def test_earth_geoid_05m_without_region():
def test_earth_geoid_01m_without_region():
"""
Test loading high-resolution earth geoid without passing 'region'.
"""
with pytest.raises(GMTInvalidInput):
load_earth_geoid("05m")
load_earth_geoid("01m")


def test_earth_geoid_incorrect_resolution_registration():
Expand All @@ -89,3 +72,19 @@ def test_earth_geoid_incorrect_resolution_registration():
"""
with pytest.raises(GMTInvalidInput):
load_earth_geoid(resolution="01m", region=[0, 1, 3, 5], registration="pixel")


def test_earth_geoid_01m_default_registration():
"""
Test that the grid returned by default for the 1 arc-minute resolution has
a "gridline" registration.
"""
data = load_earth_geoid(resolution="01m", region=[-10, -9, 3, 5])
assert data.shape == (121, 61)
assert data.gmt.registration == 0
assert data.coords["lat"].data.min() == 3.0
assert data.coords["lat"].data.max() == 5.0
assert data.coords["lon"].data.min() == -10.0
assert data.coords["lon"].data.max() == -9.0
npt.assert_allclose(data.min(), 20.34)
npt.assert_allclose(data.max(), 30.039999)
Loading