Skip to content

Commit

Permalink
implement simple test for downsampling
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrofelder committed Aug 15, 2024
1 parent 7292a74 commit 707ced0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_unit/test_transform_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import dask.array as da
import numpy as np
import pytest
from skimage import transform

from brainglobe_template_builder.preproc.transform_utils import (
downsample_anisotropic_image_stack,
)


@pytest.fixture()
def stack():
"""Create a dask array representing an image stack"""
data = np.random.rand(10, 100, 100) # Random image stack
return da.from_array(data, chunks=(1, 100, 100))


def test_downsample_anisotropic_image_stack(stack):
"""Test that downsampling with dask gives same as without."""
xy_downsampling = 20
z_downsampling = 2

downsampled_stack = downsample_anisotropic_image_stack(
stack, xy_downsampling, z_downsampling
)

assert downsampled_stack.shape == (5, 5, 5)

expected = transform.downscale_local_mean(
stack.compute(), (1, xy_downsampling, xy_downsampling)
)
expected = transform.downscale_local_mean(expected, (z_downsampling, 1, 1))
assert np.all(
downsampled_stack == expected
), "dask downsampling does not match expected skimage result"

0 comments on commit 707ced0

Please sign in to comment.