Skip to content

Commit

Permalink
simplify/expand padding test
Browse files Browse the repository at this point in the history
test padding on both sides
  • Loading branch information
pattonw committed Jan 2, 2024
1 parent 3782525 commit c6928bd
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions tests/cases/pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@


@pytest.mark.parametrize("mode", ["constant", "reflect"])
def test_output(mode):
def test_padding(mode):
array_key = ArrayKey("TEST_ARRAY")
graph_key = GraphKey("TEST_GRAPH")

array_spec = ArraySpec(
roi=Roi((200, 20, 20), (1800, 180, 180)), voxel_size=(20, 2, 2)
)
array_spec = ArraySpec(roi=Roi((200, 20, 20), (600, 60, 60)), voxel_size=(20, 2, 2))
roi_voxel = array_spec.roi / array_spec.voxel_size
data = np.zeros(roi_voxel.shape, dtype=np.uint32)
data[:, ::2] = 100
array = Array(data, spec=array_spec)

graph_spec = GraphSpec(roi=Roi((200, 20, 20), (1800, 180, 180)))
graph_spec = GraphSpec(roi=Roi((200, 20, 20), (600, 60, 60)))
graph = Graph([], [], graph_spec)

source = (
Expand All @@ -43,13 +41,13 @@ def test_output(mode):

pipeline = (
source
+ Pad(array_key, Coordinate((20, 20, 20)), value=1, mode=mode)
+ Pad(graph_key, Coordinate((10, 10, 10)), mode=mode)
+ Pad(array_key, Coordinate((200, 20, 20)), value=1, mode=mode)
+ Pad(graph_key, Coordinate((100, 10, 10)), mode=mode)
)

with build(pipeline):
assert pipeline.spec[array_key].roi == Roi((180, 0, 0), (1840, 220, 220))
assert pipeline.spec[graph_key].roi == Roi((190, 10, 10), (1820, 200, 200))
assert pipeline.spec[array_key].roi == Roi((0, 0, 0), (1000, 100, 100))
assert pipeline.spec[graph_key].roi == Roi((100, 10, 10), (800, 80, 80))

batch = pipeline.request_batch(
BatchRequest({array_key: ArraySpec(Roi((180, 0, 0), (40, 40, 40)))})
Expand All @@ -73,3 +71,26 @@ def test_output(mode):
np.sum(octants),
data,
)

# 1 x 10 x (10,30,10)
batch = pipeline.request_batch(
BatchRequest({array_key: ArraySpec(Roi((200, 20, 0), (20, 20, 100)))})
)
data = batch.arrays[array_key].data

if mode == "constant":
lower_pad = 1 * 10 * 10
upper_pad = 1 * 10 * 10
center = 100 * 1 * 5 * 30
assert np.sum(data) == np.sum((lower_pad, upper_pad, center)), (
np.sum(data),
np.sum((lower_pad, upper_pad, center)),
)
elif mode == "reflect":
lower_pad = 100 * 1 * 5 * 10
upper_pad = 100 * 1 * 5 * 10
center = 100 * 1 * 5 * 30
assert np.sum(data) == np.sum((lower_pad, upper_pad, center)), (
np.sum(data),
np.sum((lower_pad, upper_pad, center)),
)

0 comments on commit c6928bd

Please sign in to comment.