-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement simple test for downsampling
- Loading branch information
1 parent
7292a74
commit 707ced0
Showing
1 changed file
with
35 additions
and
0 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
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" |