-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_grd2xyz.py
42 lines (34 loc) · 1.11 KB
/
test_grd2xyz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Test pygmt.grd2xyz.
"""
import numpy as np
import pandas as pd
import pytest
from pygmt import grd2xyz
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers.testing import load_static_earth_relief
@pytest.fixture(scope="module", name="grid")
def fixture_grid():
"""
Load the grid data from the static_earth_relief file.
"""
return load_static_earth_relief()
@pytest.mark.benchmark
def test_grd2xyz(grid):
"""
Test the basic functionality of grd2xyz.
"""
xyz_df = grd2xyz(grid=grid)
assert isinstance(xyz_df, pd.DataFrame)
assert list(xyz_df.columns) == ["lon", "lat", "z"]
assert xyz_df.shape == (112, 3)
lon, lat = -50.5, -18.5
orig_val = grid.sel(lon=lon, lat=lat).to_numpy()
xyz_val = xyz_df[(xyz_df["lon"] == lon) & (xyz_df["lat"] == lat)]["z"].to_numpy()
np.testing.assert_allclose(orig_val, xyz_val)
def test_grd2xyz_pandas_output_with_o(grid):
"""
Test that grd2xyz fails when outcols is set and output_type is set to 'pandas'.
"""
with pytest.raises(GMTInvalidInput):
grd2xyz(grid=grid, output_type="pandas", outcols="2")