-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix matrix order * Add test files * Temporary CI branch rename * Change order to 'F' in GridObject * Add seed parameter to gen_random * Add fillsinks tests * Revise testing setup * Add multiple python versions to test * Fix python-version in matrix * Add pytest import * Change required python version * Add first identifyflats test * Change actions version to v3 * Add order='F' to read_tif * Revert branch name to main
- Loading branch information
Showing
8 changed files
with
141 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,7 @@ docs/_build/* | |
docs/_autosummary/* | ||
|
||
# ignore _temp | ||
docs/_temp | ||
docs/_temp | ||
|
||
# ignore pytest_cache | ||
.pytest_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
import topotoolbox as topo | ||
|
||
|
||
@pytest.fixture | ||
def square_dem(): | ||
return topo.gen_random(rows=128, columns=128, seed=12) | ||
|
||
|
||
@pytest.fixture | ||
def wide_dem(): | ||
return topo.gen_random(rows=64, columns=128, seed=12) | ||
|
||
|
||
@pytest.fixture | ||
def tall_dem(): | ||
return topo.gen_random(rows=128, columns=64, seed=12) | ||
|
||
|
||
def test_fillsinks(square_dem, wide_dem, tall_dem): | ||
for grid in [square_dem, wide_dem, tall_dem]: | ||
# since grid is a fixture, it has to be assigned/called first | ||
dem = grid | ||
filled_dem = dem.fillsinks() | ||
|
||
# Loop over all cells of the DEM | ||
for i in range(dem.shape[0]): | ||
for j in range(dem.shape[1]): | ||
|
||
# Test: no filled cell lower than before calling fillsinks | ||
assert dem[i, j] <= filled_dem[i, j] | ||
|
||
# Test: cell isn't a sink | ||
sink = 0 | ||
for i_offset, j_offset in [ | ||
(-1, -1), | ||
(-1, 0), | ||
(-1, 1), | ||
(0, -1), | ||
(0, 1), | ||
(1, -1), | ||
(1, 0), | ||
(1, 1)]: | ||
|
||
i_neighbor = i + i_offset | ||
j_neighbor = j + j_offset | ||
|
||
if (i_neighbor < 0 or i_neighbor >= dem.z.shape[0] | ||
or j_neighbor < 0 or j_neighbor >= dem.z.shape[1]): | ||
continue | ||
|
||
if filled_dem[i_neighbor, j_neighbor] > filled_dem[i, j]: | ||
sink += 1 | ||
|
||
assert sink < 8 | ||
|
||
|
||
def test_identifyflats(square_dem, wide_dem, tall_dem): | ||
for dem in [square_dem, wide_dem, tall_dem]: | ||
sills, flats = dem.identifyflats() | ||
|
||
for i in range(dem.shape[0]): | ||
for j in range(dem.shape[1]): | ||
|
||
for i_offset, j_offset in [ | ||
(-1, -1), | ||
(-1, 0), | ||
(-1, 1), | ||
(0, -1), | ||
(0, 1), | ||
(1, -1), | ||
(1, 0), | ||
(1, 1)]: | ||
|
||
i_neighbor = i + i_offset | ||
j_neighbor = j + j_offset | ||
|
||
if (i_neighbor < 0 or i_neighbor >= dem.z.shape[0] | ||
or j_neighbor < 0 or j_neighbor >= dem.z.shape[1]): | ||
continue | ||
|
||
if flats[i_neighbor, j_neighbor] < flats[i, j]: | ||
assert flats[i, j] == 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import pytest | ||
import topotoolbox.utils |