Skip to content

More informative metadata when loading earth_relief grids #494

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

Closed
wants to merge 3 commits into from
Closed
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: 3 additions & 1 deletion pygmt/datasets/earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def load_earth_relief(resolution="01d"):
"""
_is_valid_resolution(resolution)
fname = which("@earth_relief_{}".format(resolution), download="u")
grid = xr.open_dataarray(fname)
_dataset = xr.open_dataset(fname)
grid = _dataset.z
grid.attrs.update(_dataset.attrs) # add dataset atttributes to dataarray
# Add some metadata to the grid
grid.name = "elevation"
grid.attrs["long_name"] = "elevation relative to the geoid"
Expand Down
7 changes: 7 additions & 0 deletions pygmt/tests/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test basic functionality for loading datasets.
"""
import os
import numpy as np
import numpy.testing as npt
import pytest
Expand Down Expand Up @@ -71,6 +72,9 @@ def test_earth_relief_fails():
def test_earth_relief_01d():
"Test some properties of the earth relief 01d data"
data = load_earth_relief(resolution="01d")
# assert data.attrs["node_offset"] == 1 # pixel registration
assert data.attrs["Conventions"] == "CF-1.7"
assert os.path.basename(data.encoding["source"]) == "earth_relief_01d.grd"
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))
Expand All @@ -81,6 +85,9 @@ def test_earth_relief_01d():
def test_earth_relief_30m():
"Test some properties of the earth relief 30m data"
data = load_earth_relief(resolution="30m")
# assert data.attrs["node_offset"] == 1 # pixel registration
assert data.attrs["Conventions"] == "CF-1.7"
assert os.path.basename(data.encoding["source"]) == "earth_relief_30m.grd"
assert data.shape == (361, 721)
npt.assert_allclose(data.lat, np.arange(-90, 90.5, 0.5))
npt.assert_allclose(data.lon, np.arange(-180, 180.5, 0.5))
Expand Down