From b8d090729830f978c0a706ab96fde968a5585978 Mon Sep 17 00:00:00 2001 From: Henry Pinkard <7969470+henrypinkard@users.noreply.github.com> Date: Tue, 25 Jun 2024 22:26:01 +0200 Subject: [PATCH 1/4] fix incorrect signature --- python/ndstorage/ndstorage_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ndstorage/ndstorage_base.py b/python/ndstorage/ndstorage_base.py index a8b0a0d..9e67559 100644 --- a/python/ndstorage/ndstorage_base.py +++ b/python/ndstorage/ndstorage_base.py @@ -329,7 +329,7 @@ def has_image(self, channel: Union[int, str] = None, z: int = None, time: int = @abstractmethod def read_image(self, channel: Union[int, str] = None, z: int = None, time: int = None, position: int = None, row: int = None, column: int = None, - **kwargs: Union[int, str]) -> Union[np.ndarray, Tuple[np.ndarray, Dict[str, Any]]]: + **kwargs: Union[int, str]) -> np.ndarray: """ Read image data as numpy array. From 8fd90e41bb80528750db2dae40287eb792061237 Mon Sep 17 00:00:00 2001 From: Henry Pinkard <7969470+henrypinkard@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:45:51 +0200 Subject: [PATCH 2/4] duck typing check instead of explicit inheritance --- python/ndstorage/ndstorage_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/ndstorage/ndstorage_base.py b/python/ndstorage/ndstorage_base.py index 9e67559..847da43 100644 --- a/python/ndstorage/ndstorage_base.py +++ b/python/ndstorage/ndstorage_base.py @@ -9,6 +9,7 @@ - image_keys: a list of image_keys, e.g. [frozenset({'channel': 0, 'z': 1, 'time': 2}), frozenset({'channel': 0, 'z': 1, 'time': 3})] """ from abc import ABC, abstractmethod +from collections.abc import Mapping from typing import Any, Dict, List, Union, Tuple import numpy as np import dask @@ -622,7 +623,7 @@ def _parse_string_axes_values(self, image_coordinates): self._string_axes_values[string_axis_name] = [] # if its called on just one image, make it a list of one image - if isinstance(image_coordinates, dict): + if isinstance(image_coordinates, Mapping): image_coordinates = [image_coordinates.items()] for single_image_coordinates in image_coordinates: From 069a7e89fa256d70fd4f6d0701491c84045c84a7 Mon Sep 17 00:00:00 2001 From: Henry Pinkard <7969470+henrypinkard@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:31:10 +0200 Subject: [PATCH 3/4] avoid inconsistencies by flushing to disk after write --- python/ndstorage/ndtiff_dataset.py | 3 ++- python/ndstorage/ndtiff_file.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/python/ndstorage/ndtiff_dataset.py b/python/ndstorage/ndtiff_dataset.py index 2f0ec64..c25f45f 100644 --- a/python/ndstorage/ndtiff_dataset.py +++ b/python/ndstorage/ndtiff_dataset.py @@ -33,7 +33,8 @@ def __init__(self, dataset_path=None, file_io: NDTiffFileIO = BUILTIN_FILE_IO, s file_io: ndtiff.file_io.NDTiffFileIO A container containing various methods for interacting with files. summary_metadata : dict - Summary metadata for a dataset that is currently being written by another process + Summary metadata for a dataset that is currently being written by another process. If writable is True, + this should instead be provided by the initialize() method. name : str Name of the dataset if writing a new dataset writable : bool diff --git a/python/ndstorage/ndtiff_file.py b/python/ndstorage/ndtiff_file.py index 08c0242..5b30247 100644 --- a/python/ndstorage/ndtiff_file.py +++ b/python/ndstorage/ndtiff_file.py @@ -162,6 +162,8 @@ def write_image(self, index_key, pixels, metadata, bit_depth='auto'): ied = self._write_ifd(index_key, pixels, metadata, rgb, image_height, image_width, bit_depth) while self.buffers: self.file.write(self.buffers.popleft()) + # make sure the file is flushed to disk + self.file.flush() self.index_map[index_key] = ied return ied From abc0c938c944351885fd82aa7730d8b573344728 Mon Sep 17 00:00:00 2001 From: Henry Pinkard <7969470+henrypinkard@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:33:11 +0200 Subject: [PATCH 4/4] fix error when queryin unknown axis --- python/ndstorage/_version.py | 2 +- python/ndstorage/ndstorage_base.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/python/ndstorage/_version.py b/python/ndstorage/_version.py index 78f8d1b..8ead122 100644 --- a/python/ndstorage/_version.py +++ b/python/ndstorage/_version.py @@ -1,2 +1,2 @@ -version_info = (0, 1, 6) +version_info = (0, 1, 7) __version__ = ".".join(map(str, version_info)) diff --git a/python/ndstorage/ndstorage_base.py b/python/ndstorage/ndstorage_base.py index 847da43..50a5e88 100644 --- a/python/ndstorage/ndstorage_base.py +++ b/python/ndstorage/ndstorage_base.py @@ -652,18 +652,16 @@ def _consolidate_axes(self, channel: int or str, z: int, position: int, Combine all the axes with standard names and custom names into a single dictionary, eliminating any None values. Also, convert any string-valued axes passed as ints into strings """ - if ('channel_name' in kwargs): - warnings.warn('channel_name is deprecated, use "channel" instead') - channel = kwargs['channel_name'] - del kwargs['channel_name'] - axis_positions = {'channel': channel, 'z': z, 'position': position, 'time': time, 'row': row, 'column': column, **kwargs} # ignore ones that are None axis_positions = {n: axis_positions[n] for n in axis_positions.keys() if axis_positions[n] is not None} for axis_name in axis_positions.keys(): # convert any string-valued axes passed as ints into strings - if self.axes_types[axis_name] == str and type(axis_positions[axis_name]) == int: + if axis_name not in self.axes_types.keys(): + # can't convert to string if the axis is not known + pass + elif self.axes_types[axis_name] == str and type(axis_positions[axis_name]) == int: axis_positions[axis_name] = self._string_axes_values[axis_name][axis_positions[axis_name]] return axis_positions