Skip to content
Snippets Groups Projects
Commit a39414d2 authored by Arin Wongprommoon's avatar Arin Wongprommoon
Browse files

test(aliby): ImageDummy.pad_array() method

EVIDENCE THAT COMMIT WORKS:
- issue #53

REFERENCES:
parent 8c8a8123
No related branches found
No related tags found
No related merge requests found
......@@ -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(
......
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment