Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when querying unknown axis #164

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/ndstorage/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_info = (0, 1, 6)
version_info = (0, 1, 7)
__version__ = ".".join(map(str, version_info))
15 changes: 7 additions & 8 deletions python/ndstorage/ndstorage_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -329,7 +330,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.

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -651,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
3 changes: 2 additions & 1 deletion python/ndstorage/ndtiff_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions python/ndstorage/ndtiff_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading