Skip to content

Change load_earth_relief()'s default resolution to 01d #488

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 3 commits into from
Jun 23, 2020
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 .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
- bash: |
set -x -e
source activate testing
gmt which -Gu @earth_relief_10m @earth_relief_60m @ridge.txt @Table_5_11.txt @tut_bathy.nc @tut_quakes.ngdc @tut_ship.xyz
gmt which -Gu @earth_relief_10m @earth_relief_01d @ridge.txt @Table_5_11.txt @tut_bathy.nc @tut_quakes.ngdc @tut_ship.xyz
displayName: Download remote data
condition: ne(variables['CACHE_CACHEDATA_RESTORED'], true)

Expand Down Expand Up @@ -224,7 +224,7 @@ jobs:
- bash: |
set -x -e
source activate testing
gmt which -Gu @earth_relief_10m @earth_relief_60m @ridge.txt @Table_5_11.txt @tut_bathy.nc @tut_quakes.ngdc @tut_ship.xyz
gmt which -Gu @earth_relief_10m @earth_relief_01d @ridge.txt @Table_5_11.txt @tut_bathy.nc @tut_quakes.ngdc @tut_ship.xyz
displayName: Download remote data
condition: ne(variables['CACHE_CACHEDATA_RESTORED'], true)

Expand Down
4 changes: 2 additions & 2 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def dataarray_to_matrix(grid):
--------

>>> from pygmt.datasets import load_earth_relief
>>> # Use the global Earth relief grid with 1 degree spacing (60')
>>> grid = load_earth_relief(resolution='60m')
>>> # Use the global Earth relief grid with 1 degree spacing
>>> grid = load_earth_relief(resolution='01d')
>>> matrix, region, inc = dataarray_to_matrix(grid)
>>> print(region)
[-180.0, 180.0, -90.0, 90.0]
Expand Down
2 changes: 1 addition & 1 deletion pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ def virtualfile_from_grid(self, grid):

>>> from pygmt.datasets import load_earth_relief
>>> from pygmt.helpers import GMTTempFile
>>> data = load_earth_relief(resolution='60m')
>>> data = load_earth_relief(resolution='01d')
>>> print(data.shape)
(181, 361)
>>> print(data.lon.values.min(), data.lon.values.max())
Expand Down
21 changes: 14 additions & 7 deletions pygmt/datasets/earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..exceptions import GMTInvalidInput


def load_earth_relief(resolution="60m"):
def load_earth_relief(resolution="01d"):
"""
Load Earth relief grids (topography and bathymetry) in various resolutions.

Expand All @@ -23,9 +23,10 @@ def load_earth_relief(resolution="60m"):
Parameters
----------
resolution : str
The grid resolution. The suffix ``m`` and ``s`` stand for arc-minute
and arc-second. It can be ``'60m'``, ``'30m'``, ``'10m'``, ``'05m'``,
``'02m'``, ``'01m'``, ``'30s'`` or ``'15s'``.
The grid resolution. The suffix ``d``, ``m`` and ``s`` stand for
arc-degree, arc-minute and arc-second. It can be ``'01d'``, ``'30m'``,
``'20m'``, ``'15m'``, ``'10m'``, ``'06m'``, ``'05m'``, ``'04m'``,
``'03m'``, ``'02m'``, ``'01m'``, ``'30s'`` or ``'15s'``.

Returns
-------
Expand Down Expand Up @@ -69,6 +70,7 @@ def _is_valid_resolution(resolution):
Examples
--------

>>> _is_valid_resolution("01d")
>>> _is_valid_resolution("60m")
>>> _is_valid_resolution("5m")
Traceback (most recent call last):
Expand All @@ -81,8 +83,11 @@ def _is_valid_resolution(resolution):
pygmt.exceptions.GMTInvalidInput: Invalid Earth relief resolution '01s'.

"""
valid_resolutions = ["{:02d}m".format(res) for res in [60, 30, 10, 5, 2, 1]]
valid_resolutions.extend(["{:02d}s".format(res) for res in [30, 15]])
valid_resolutions = ["01d"]
valid_resolutions.extend(
[f"{res:02d}m" for res in [60, 30, 20, 15, 10, 6, 5, 4, 3, 2, 1]]
)
valid_resolutions.extend([f"{res:02d}s" for res in [30, 15]])
if resolution not in valid_resolutions:
raise GMTInvalidInput(
"Invalid Earth relief resolution '{}'.".format(resolution)
Expand Down Expand Up @@ -120,7 +125,9 @@ def _shape_from_resolution(resolution):
"""
_is_valid_resolution(resolution)
unit = resolution[2]
if unit == "m":
if unit == "d":
seconds = int(resolution[:2]) * 60 * 60
elif unit == "m":
seconds = int(resolution[:2]) * 60
elif unit == "s":
seconds = int(resolution[:2])
Expand Down
10 changes: 5 additions & 5 deletions pygmt/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ def test_earth_relief_fails():
load_earth_relief(resolution=resolution)


# Only test 60m and 30m to avoid downloading large datasets in CI
def test_earth_relief_60():
"Test some properties of the earth relief 60m data"
data = load_earth_relief(resolution="60m")
# Only test 01d and 30m to avoid downloading large datasets in CI
def test_earth_relief_01d():
"Test some properties of the earth relief 01d data"
data = load_earth_relief(resolution="01d")
assert data.shape == (181, 361)
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(), -8592.144531)
npt.assert_allclose(data.max(), 5558.79248)


def test_earth_relief_30():
def test_earth_relief_30m():
"Test some properties of the earth relief 30m data"
data = load_earth_relief(resolution="30m")
assert data.shape == (361, 721)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_grdcontour_file():
"Plot a contour image using grid file input"
fig = Figure()
fig.grdcontour(
"@earth_relief_60m",
"@earth_relief_01d",
interval="1000",
limit="0",
pen="0.5p,black",
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_grdimage_file():
"Plot an image using file input"
fig = Figure()
fig.grdimage(
"@earth_relief_60m",
"@earth_relief_01d",
cmap="ocean",
region=[-180, 180, -70, 70],
projection="W0/10i",
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_grdinfo():

def test_grdinfo_file():
"Test grdinfo with file input"
result = grdinfo("@earth_relief_60m", L=0, C="n")
result = grdinfo("@earth_relief_01d", L=0, C="n")
assert result.strip() == "-180 180 -90 90 -8592.14465255 5558.79248047 1 1 361 181"


Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_grdtrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_grdtrack_input_dataframe_and_ncfile():
Run grdtrack by passing in a pandas.DataFrame and netcdf file as inputs
"""
dataframe = load_ocean_ridge_points()
ncfile = which("@earth_relief_60m", download="c")
ncfile = which("@earth_relief_01d", download="c")

output = grdtrack(points=dataframe, grid=ncfile, newcolname="bathymetry")
assert isinstance(output, pd.DataFrame)
Expand All @@ -73,7 +73,7 @@ def test_grdtrack_input_csvfile_and_ncfile():
Run grdtrack by passing in a csvfile and netcdf file as inputs
"""
csvfile = which("@ridge.txt", download="c")
ncfile = which("@earth_relief_60m", download="c")
ncfile = which("@earth_relief_01d", download="c")

try:
output = grdtrack(points=csvfile, grid=ncfile, outfile=TEMP_TRACK)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_grdview_grid_file_with_region_subset():
"""
Run grdview by passing in a grid filename, and cropping it to a region.
"""
gridfile = which("@earth_relief_60m", download="c")
gridfile = which("@earth_relief_01d", download="c")

fig = Figure()
fig.grdview(grid=gridfile, region=[-116, -109, -47, -44])
Expand Down