diff --git a/CHANGELOG.md b/CHANGELOG.md index 57980bc..1f619dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Version 0.6.7 +- Fixed bugs in asdask() and GeneratorSource +- Pinned some versions in pip requirements + #### Version 0.6.6 - Rewritten TiffSource using dask/zarr functionality - Added high level Dask function diff --git a/OmeSliCC/GeneratorSource.py b/OmeSliCC/GeneratorSource.py index 6ccb81c..d0ed06e 100644 --- a/OmeSliCC/GeneratorSource.py +++ b/OmeSliCC/GeneratorSource.py @@ -58,11 +58,11 @@ def calc_color(self, *args, **kwargs): return np.stack(channels, axis=-1) def get_tile(self, indices, tile_size=None): - # tile in (z,),y,x,c + # indices / tile size in x,y(,z,...) if not tile_size: tile_size = np.flip(self.tile_shape) - range0 = np.flip(indices) - range1 = np.min([range0 + tile_size, self.size], 0) + range0 = indices + range1 = np.min([np.array(indices) + np.array(tile_size), self.size], 0) shape = list(reversed(range1 - range0)) tile = np.fromfunction(self.calc_color, shape, dtype=int, range0=range0) # apply noise to each channel separately @@ -77,14 +77,14 @@ def get_tile(self, indices, tile_size=None): def _asarray_level(self, level: int, x0: float = 0, y0: float = 0, x1: float = -1, y1: float = -1, c: int = None, z: int = None, t: int = None) -> np.ndarray: # ignore c - indices = [y0, x0] - tile_size = [y1 - y0, x1 - x0] + indices = [x0, y0] + tile_size = [x1 - x0, y1 - y0] if z: - indices = [0] + indices - tile_size = [1] + tile_size + indices += [0] + tile_size += [1] if t: - indices = [0] + indices - tile_size = [1] + tile_size + indices += [0] + tile_size += [1] data = self.get_tile(indices, tile_size) if not z: data = np.expand_dims(data, 0) @@ -95,7 +95,7 @@ def _asarray_level(self, level: int, x0: float = 0, y0: float = 0, x1: float = - if __name__ == '__main__': - # (tile) size in x,y(,z) + # (tile) size in x,y(,z,...) size = 256, 256, 256 tile_size = 256, 256, 1 dtype = np.uint8 diff --git a/OmeSliCC/OmeSource.py b/OmeSliCC/OmeSource.py index 9abd5e1..6e75ec8 100644 --- a/OmeSliCC/OmeSource.py +++ b/OmeSliCC/OmeSource.py @@ -353,6 +353,7 @@ def asdask(self, chunk_size: tuple) -> da.Array: while len(chunk_shape) < 5: chunk_shape = [1] + chunk_shape chunks = np.ceil(np.flip(self.get_size_xyzct()) / chunk_shape).astype(int) + w, h = self.get_size() delayed_reader = dask.delayed(self.asarray) dtype = self.get_pixel_type() @@ -365,18 +366,24 @@ def asdask(self, chunk_size: tuple) -> da.Array: for yi in range(chunks[3]): dask_tiles = [] for xi in range(chunks[4]): - x0, x1 = xi * chunk_shape[4], (xi + 1) * chunk_shape[4] - y0, y1 = yi * chunk_shape[3], (yi + 1) * chunk_shape[3] - z = zi * chunk_shape[2] - t = ti * chunk_shape[0] - dask_tile = da.from_delayed(delayed_reader(x0, y0, x1, y1, z=z, t=t), shape=chunk_shape, + shape = list(chunk_shape).copy() + x0, x1 = xi * shape[4], (xi + 1) * shape[4] + y0, y1 = yi * shape[3], (yi + 1) * shape[3] + if x1 > w: + x1 = w + shape[4] = w - x0 + if y1 > h: + y1 = h + shape[3] = h - y0 + z = zi * shape[2] + t = ti * shape[0] + dask_tile = da.from_delayed(delayed_reader(x0, y0, x1, y1, z=z, t=t), shape=shape, dtype=dtype) dask_tiles.append(dask_tile) dask_rows.append(da.concatenate(dask_tiles, axis=4)) dask_planes.append(da.concatenate(dask_rows, axis=3)) dask_times.append(da.concatenate(dask_planes, axis=1)) dask_data = da.concatenate(dask_times, axis=0) - return dask_data def clone_empty(self) -> np.ndarray: diff --git a/pyproject.toml b/pyproject.toml index a9fd476..6d5ab3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "OmeSliCC" -version = "0.6.6" +version = "0.6.7" description = "Ome(ro) Slide Image Conversion and Compression pipeline" readme = "README.md" license = {file = "LICENSE.md"} diff --git a/requirements.txt b/requirements.txt index 0bbeb15..e9e5e29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,9 +3,9 @@ pandas scikit-image scikit-learn opencv-python -imagecodecs +imagecodecs>=2023.3.16 numcodecs -tifffile +tifffile>=2023.9.26 zarr aiohttp omero-py diff --git a/tests/conversion_test.py b/tests/conversion_test.py index 4567a21..371d65e 100644 --- a/tests/conversion_test.py +++ b/tests/conversion_test.py @@ -22,8 +22,8 @@ def load_as_zarr(path, x_um, y_um, w_um, h_um): def save_source_as_ome_tiff(output, source, output_params): - data = source.asarray() - #data = source.asdask(output_params['tile_size']) + #data = source.asarray() + data = source.asdask(output_params['tile_size']) save_image_as_tiff(source, data, output, output_params, ome=True) @@ -50,9 +50,10 @@ def conversion_test(): path2 = 'test1.ome.zarr' path3 = 'test2.ome.tiff' size = [1024, 1024] - output_params = {'tile_size': [256, 256], 'npyramid_add': 3, 'pyramid_downsample': 2} + tile_size = [256, 256] + output_params = {'tile_size': tile_size, 'npyramid_add': 3, 'pyramid_downsample': 2} - source = create_source(size, [256, 256], np.uint8, [(1, 'um')]) + source = create_source(size, tile_size, np.uint8, [(1, 'um')]) nchannels = source.get_nchannels() save_source_as_ome_tiff(path1, source, output_params)