diff --git a/src/aliby/io/image.py b/src/aliby/io/image.py index c0b9ea734b31c9ac6da2651d6e3086f514a37dd0..81a6c04fe61beab51314627f2bd2c68954ac3654 100644 --- a/src/aliby/io/image.py +++ b/src/aliby/io/image.py @@ -164,10 +164,6 @@ class ImageDummy(BaseLocalImage): extended_array = pad_array(my_da_array, dim = 2, n_empty_slices = 4) The additional 4 slices will be filled with zeros. """ - # (If done correctly, these should be true) - # tmp[n_empty_slices] == image_array - # result.shape[dim] == i+1 - # Concats zero arrays with same dimensions as image_array, and puts # image_array as last element in list of arrays to be concatenated return da.concatenate( diff --git a/tests/aliby/pipeline/test_image.py b/tests/aliby/pipeline/test_image.py new file mode 100644 index 0000000000000000000000000000000000000000..22e5af650436a9fd7e65cd426e73ad123700b735 --- /dev/null +++ b/tests/aliby/pipeline/test_image.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import numpy as np +import dask.array as da +import pytest + +from aliby.io.image import ImageDummy + +tiler_parameters = {"tile_size": 117, "ref_channel": "Brightfield", "ref_z": 0} + +sample_da = da.from_array(np.array([[1, 2], [3, 4]])) +# Make it 5-dimensional +sample_da = da.reshape( + sample_da, (1, 1, sample_da.shape[-2], sample_da.shape[-1]) +) + + +@pytest.mark.parametrize("sample_da", sample_da) +@pytest.mark.parametrize("dim", 2) +@pytest.mark.parametrize("n_empty_slices", 4) +def test_pad_array(sample_da, dim, n_empty_slices): + """Test ImageDummy.pad_array() method""" + # create object + imgdmy = ImageDummy(tiler_parameters) + # pads array + padded_da = imgdmy.pad_array( + sample_da, dim=dim, n_empty_slices=n_empty_slices + ) + + # select which dimension to index the multidimensional array + indices = {dim: n_empty_slices} + ix = [ + indices.get(dim, slice(None)) + for dim in range(padded_da.compute().ndim) + ] + + # Checks that original image array is there and is at the last index + assert padded_da.compute(ix) == sample_da + # Checks that the additional axis is extended correctly + assert padded_da.compute.shape[dim] == n_empty_slices + 1