Skip to content

Commit e3a4f7a

Browse files
committed
Add test_dimfilter.py
1 parent 3373066 commit e3a4f7a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

pygmt/tests/test_dimfilter.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Tests for dimfilter.
3+
"""
4+
import os
5+
6+
import numpy.testing as npt
7+
import pytest
8+
from pygmt import dimfilter
9+
from pygmt.datasets import load_earth_relief
10+
from pygmt.exceptions import GMTInvalidInput
11+
from pygmt.helpers import GMTTempFile
12+
13+
14+
@pytest.fixture(scope="module", name="grid")
15+
def fixture_grid():
16+
"""
17+
Load the grid data from the sample earth_relief file.
18+
"""
19+
return load_earth_relief(resolution="30m", region=[-5, 5, -5, 5])
20+
21+
22+
def test_dimfilter_outgrid(grid):
23+
"""
24+
Test the required parameters for dimfilter with a set outgrid.
25+
"""
26+
with GMTTempFile(suffix=".nc") as tmpfile:
27+
result = dimfilter(grid=grid, outgrid=tmpfile.name, filter="m600", distance=4, sectors="l6")
28+
assert result is None # return value is None
29+
assert os.path.exists(path=tmpfile.name) # check that outgrid exists
30+
31+
32+
def test_grdgradient_no_outgrid(grid):
33+
"""
34+
Test the required parameters for dimfilter with no set outgrid.
35+
"""
36+
temp_grid = dimfilter(grid=grid, filter="m600", distance=4, sectors="l6")
37+
assert temp_grid.dims == ("lat", "lon")
38+
assert temp_grid.gmt.gtype == 1 # Geographic grid
39+
assert temp_grid.gmt.registration == 1 # Pixel registration
40+
npt.assert_allclose(temp_grid.min(), -5125)
41+
npt.assert_allclose(temp_grid.max(), -3750.5)
42+
npt.assert_allclose(temp_grid.median(), -4826.5)
43+
npt.assert_allclose(temp_grid.mean(), -4789.791)
44+
45+
def test_dimfilter_fails(grid):
46+
"""
47+
Check that dimfilter fails correctly when sector,
48+
filters, and distance are not specified..
49+
"""
50+
with pytest.raises(GMTInvalidInput):
51+
dimfilter(grid=grid)

0 commit comments

Comments
 (0)