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

Keep metadata of sample datasets in the xarray objects #184

Merged
merged 5 commits into from Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions harmonica/datasets/sample_data.py
Expand Up @@ -64,7 +64,10 @@ def fetch_geoid_earth():

"""
fname = REGISTRY.fetch("geoid-earth-0.5deg.nc.xz", processor=pooch.Decompress())
data = xr.open_dataset(fname, engine="scipy").astype("float64")
data = xr.open_dataset(fname, engine="scipy")
attrs = data.attrs.copy()
data = data.astype("float64")
data.attrs = attrs
return data


Expand Down Expand Up @@ -94,7 +97,10 @@ def fetch_gravity_earth():
fname = REGISTRY.fetch("gravity-earth-0.5deg.nc.xz", processor=pooch.Decompress())
# The heights are stored as ints and data as float32 to save space on the
# data file. Cast them to float64 to avoid integer division errors.
data = xr.open_dataset(fname, engine="scipy").astype("float64")
data = xr.open_dataset(fname, engine="scipy")
attrs = data.attrs.copy()
data = data.astype("float64")
data.attrs = attrs
return data


Expand Down Expand Up @@ -125,7 +131,10 @@ def fetch_topography_earth():
fname = REGISTRY.fetch("etopo1-0.5deg.nc.xz", processor=pooch.Decompress())
# The data are stored as int16 to save disk space. Cast them to floats to
# avoid integer division problems when processing.
data = xr.open_dataset(fname, engine="scipy").astype("float64")
data = xr.open_dataset(fname, engine="scipy")
attrs = data.attrs.copy()
data = data.astype("float64")
data.attrs = attrs
return data


Expand Down
14 changes: 14 additions & 0 deletions harmonica/tests/test_sample_data.py
Expand Up @@ -30,6 +30,11 @@ def test_geoid_earth():
assert grid.geoid.shape == (361, 721)
npt.assert_allclose(grid.geoid.min(), -106.257344)
npt.assert_allclose(grid.geoid.max(), 84.722744)
assert grid.attrs
assert grid.attrs.get("refsysname") == "WGS84"
assert grid.attrs.get("max_used_degree") == "1277"
assert grid.attrs.get("tide_system") == "tide_free"
assert grid.attrs.get("modelname") == "EIGEN-6C4"


def test_gravity_earth():
Expand All @@ -40,6 +45,11 @@ def test_gravity_earth():
npt.assert_allclose(grid.gravity.min(), 9.7476403e05)
assert grid.height_over_ell.shape == (361, 721)
npt.assert_allclose(grid.height_over_ell, 10000)
assert grid.attrs
assert grid.attrs.get("refsysname") == "WGS84"
assert grid.attrs.get("max_used_degree") == "1277"
assert grid.attrs.get("tide_system") == "tide_free"
assert grid.attrs.get("modelname") == "EIGEN-6C4"


def test_topography_earth():
Expand All @@ -48,6 +58,10 @@ def test_topography_earth():
assert grid.topography.shape == (361, 721)
npt.assert_allclose(grid.topography.max(), 5651, atol=1)
npt.assert_allclose(grid.topography.min(), -8409, atol=1)
assert grid.attrs
assert grid.attrs.get("refsysname") == "WGS84"
assert grid.attrs.get("max_used_degree") == "1277"
assert grid.attrs.get("modelname") == "etopo1-2250"


def test_britain_magnetic():
Expand Down