Skip to content

Commit

Permalink
add tests for from_raster
Browse files Browse the repository at this point in the history
  • Loading branch information
wrightky committed May 31, 2023
1 parent 0d7af3f commit dea43ec
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tests/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_area():
area_fraction_inside = np.sum(grid1.raster)/grid1.raster.size
assert area_fraction_inside == pytest.approx(0.528344, rel=0.01)

# Test domain B
# Test domain 2
cellsize2 = 1
boundary2 = [[0,0],[100,0],[100,100],[0,100],[0,52],[70,80],[70,20],[0,48]]
grid2 = ipdw.Gridded(cellsize2, boundary2)
Expand Down Expand Up @@ -58,4 +58,21 @@ def test_reinterpolate():
output_1 = grid2.interpolate(input_locations2, [7,3], n_nearest=2)
output_2 = grid2.reinterpolate([6,2])
diff = output_1 - output_2
assert np.nanmean(diff) == pytest.approx(1, rel=0.01)
assert np.nanmean(diff) == pytest.approx(1, rel=0.01)

# Test domain 3
extent = [0, 150, 0, 75]
raster = np.array([[0,0,0,0,0,0],
[0,1,1,0,1,0],
[0,1,1,1,1,0]]).astype(float)
grid3 = ipdw.Gridded(raster=raster, extent=extent)

def test_from_raster():
assert (grid3.raster == raster).all()

def test_cellsize():
assert grid3.cellsize == pytest.approx(25, rel=1e-6)

def test_bbox():
bbox = np.round(np.array(grid3.bbox),1)
assert (bbox == np.array([12.5, 137.5, 12.5, 62.5])).all()

0 comments on commit dea43ec

Please sign in to comment.