Skip to content

Add static_earth_relief to grd2xyz tests #1737

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 2 commits into from
Feb 11, 2022
Merged
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
16 changes: 8 additions & 8 deletions pygmt/tests/test_grd2xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@
import pandas as pd
import pytest
from pygmt import grd2xyz
from pygmt.datasets import load_earth_relief
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile
from pygmt.helpers.testing import load_static_earth_relief


@pytest.fixture(scope="module", name="grid")
def fixture_grid():
"""
Load the grid data from the sample earth_relief file.
Load the grid data from the static_earth_relief file.
"""
return load_earth_relief(resolution="01d", region=[-1, 1, 3, 5])
return load_static_earth_relief()


def test_grd2xyz(grid):
"""
Make sure grd2xyz works as expected.
"""
xyz_data = grd2xyz(grid=grid, output_type="numpy")
assert xyz_data.shape == (4, 3)
assert xyz_data.shape == (112, 3)


def test_grd2xyz_format(grid):
"""
Test that correct formats are returned.
"""
lon = -0.5
lat = 3.5
lon = -50.5
lat = -18.5
orig_val = grid.sel(lon=lon, lat=lat).to_numpy()
xyz_default = grd2xyz(grid=grid)
xyz_val = xyz_default[(xyz_default["lon"] == lon) & (xyz_default["lat"] == lat)][
"elevation"
"z"
].to_numpy()
assert isinstance(xyz_default, pd.DataFrame)
assert orig_val.size == 1
Expand All @@ -47,7 +47,7 @@ def test_grd2xyz_format(grid):
assert isinstance(xyz_array, np.ndarray)
xyz_df = grd2xyz(grid=grid, output_type="pandas")
assert isinstance(xyz_df, pd.DataFrame)
assert list(xyz_df.columns) == ["lon", "lat", "elevation"]
assert list(xyz_df.columns) == ["lon", "lat", "z"]


def test_grd2xyz_file_output(grid):
Expand Down