Skip to content

Commit

Permalink
add basic tests, and test of preprocessing. Testing the other options…
Browse files Browse the repository at this point in the history
…/functionality will be more difficult.
  • Loading branch information
Andrew Moodie committed Jun 25, 2024
1 parent d185aa6 commit 12f1af1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
9 changes: 6 additions & 3 deletions deltametrics/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ def shaw_opening_angle_method(
Binary image that has been thresholded to split water/land. At
minimum, this should be a thresholded elevation matrix, or some
classification of land/water based on pixel color or reflectance
intensity. This is the startin point (i.e., guess) for the opening
intensity. This is the starting point for the opening
angle method.
numviews : int, optional
Expand Down Expand Up @@ -1748,12 +1748,15 @@ def shaw_opening_angle_method(
# set refers to the points which bound the angle calculations.

## Preprocess
# Preprocess in orginal paper: "we pre-process by filling lakes
# (contiguous sets of water pixels surrounded by land)"
if preprocess:
# Preprocess in orginal paper: "we pre-process by filling lakes
# (contiguous sets of water pixels surrounded by land)"
below_mask = np.logical_not(
binary_fill_holes(np.logical_not(below_mask))
).astype(int)
else:
# Ensure array is integer binary
below_mask = below_mask.astype(int)

## Find land-water interface (`edges`)
# find the edges of the below_mask by a gradient approach in x and y
Expand Down
28 changes: 23 additions & 5 deletions tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,30 @@ def test_bad_type(self):


class TestShawOpeningAngleMethod:
simple_ocean = 1 - simple_land

# NEED TESTS
simple_ocean = 1 - simple_land # ocean is at bottom of image

def test_null(self):
pass
def test_allblack(self):
with pytest.raises(ValueError, match=r"No pixels identified in below_mask.*"):
_ = plan.shaw_opening_angle_method(np.zeros((10, 10), dtype=int))

def test_simple_case_defaults(self):
oam = plan.shaw_opening_angle_method(self.simple_ocean)
assert np.all(oam <= 180)
assert np.all(oam >= 0)
assert np.all(oam[-1, :] == 180)

def test_simple_case_preprocess(self):
# make a custom mask with a lake
_custom_ocean = np.copy(self.simple_ocean)
_custom_ocean[1:3, 1:3] = 1 # add a lake

# the lake should be removed (default)
oam1 = plan.shaw_opening_angle_method(_custom_ocean, preprocess=True)
assert np.all(oam1[1:3, 1:3] == 0)

# the lake should persist
oam2 = plan.shaw_opening_angle_method(_custom_ocean, preprocess=False)
assert np.all(oam2[1:3, 1:3] != 0)


class TestDeltaArea:
Expand Down

0 comments on commit 12f1af1

Please sign in to comment.