tiamat-python 0.1.10__tar.gz → 0.1.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/PKG-INFO +2 -2
  2. tiamat_python-0.1.12/README.rst +206 -0
  3. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/pyproject.toml +1 -1
  4. tiamat_python-0.1.12/tiamat/metadata/metadata.py +206 -0
  5. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/stack.py +24 -17
  6. tiamat_python-0.1.12/tiamat/readers/zarr.py +441 -0
  7. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat_python.egg-info/PKG-INFO +2 -2
  8. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat_python.egg-info/SOURCES.txt +1 -0
  9. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat_python.egg-info/requires.txt +3 -1
  10. tiamat_python-0.1.10/tiamat/metadata/metadata.py +0 -118
  11. tiamat_python-0.1.10/tiamat/readers/zarr.py +0 -353
  12. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/LICENSE +0 -0
  13. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/README.md +0 -0
  14. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/setup.cfg +0 -0
  15. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/setup.py +0 -0
  16. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tests/test_metadata.py +0 -0
  17. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tests/test_package.py +0 -0
  18. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/__init__.py +0 -0
  19. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/array.py +0 -0
  20. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/cache.py +0 -0
  21. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/cli.py +0 -0
  22. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/constants.py +0 -0
  23. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/errors.py +0 -0
  24. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/io.py +0 -0
  25. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/metadata/__init__.py +0 -0
  26. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/metadata/dimensions.py +0 -0
  27. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/pipeline.py +0 -0
  28. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/__init__.py +0 -0
  29. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/factory.py +0 -0
  30. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/generic.py +0 -0
  31. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/memory.py +0 -0
  32. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/nifti.py +0 -0
  33. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/pipeline.py +0 -0
  34. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/processing.py +0 -0
  35. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/readers/protocol.py +0 -0
  36. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/serialization.py +0 -0
  37. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/__init__.py +0 -0
  38. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/access.py +0 -0
  39. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/affine.py +0 -0
  40. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/axes.py +0 -0
  41. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/color.py +0 -0
  42. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/coordinates.py +0 -0
  43. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/dfield.py +0 -0
  44. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/metadata.py +0 -0
  45. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/normalization.py +0 -0
  46. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/protocol.py +0 -0
  47. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat/transformers/view.py +0 -0
  48. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat_python.egg-info/dependency_links.txt +0 -0
  49. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat_python.egg-info/entry_points.txt +0 -0
  50. {tiamat_python-0.1.10 → tiamat_python-0.1.12}/tiamat_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tiamat-python
3
- Version: 0.1.10
3
+ Version: 0.1.12
4
4
  Summary: Tiled Image Access, Manipulation, and Analysis Toolkit
5
5
  Author-email: "Big Data Analytics Group, Forschungszentrum Juelich, Institute of Neuroscience and Medicine (INM-1)" <inm1-bda@fz-juelich.de>
6
6
  License:
@@ -233,7 +233,7 @@ Requires-Dist: flake8; extra == "dev"
233
233
  Requires-Dist: pre-commit; extra == "dev"
234
234
  Requires-Dist: pytest; extra == "dev"
235
235
  Provides-Extra: zarr
236
- Requires-Dist: zarr; extra == "zarr"
236
+ Requires-Dist: tensorstore; python_version >= "3.11" and extra == "zarr"
237
237
  Dynamic: license-file
238
238
 
239
239
  <p align="center">
@@ -0,0 +1,206 @@
1
+ .. image:: https://jugit.fz-juelich.de/inm-1/bda/software/data_access/tiamat/tiamat/-/raw/develop/assets/logo512.png
2
+ :height: 128px
3
+ :align: center
4
+
5
+ ========
6
+ tiamat
7
+ ========
8
+
9
+ ----
10
+
11
+ ````````````````````````````````````````````````````````````````
12
+ Tiled Image Access, Manipulation, and Analysis Toolkit
13
+ ````````````````````````````````````````````````````````````````
14
+
15
+ ----
16
+
17
+ **tiamat** is a modular Python toolkit for accessing, transforming, and exposing large scientific image datasets.
18
+ It provides a flexible, pluggable pipeline model that separates data access (*readers*), transformation (*transformers*), and delivery (*interfaces*) — allowing on-the-fly, tool-agnostic image workflows without data duplication or format conversion.
19
+
20
+ Supported outputs include NumPy arrays, Napari, Neuroglancer, OpenSeadragon, and FUSE-mounted virtual filesystems.
21
+
22
+ ----
23
+
24
+ ========================
25
+ 📑 Table of Contents
26
+ ========================
27
+
28
+ 1. `Quick Start <#quick-start>`_
29
+ 2. `Installation <#installation>`_
30
+ 3. `Core Concepts <#core-concepts>`_
31
+ 4. `Examples <#examples>`_
32
+ 5. `Development Guidelines <#development-guidelines>`_
33
+ 6. `Contributing <#contributing>`_
34
+ 7. `Data <#data>`_
35
+ 8. `Acknowledgements <#acknowledgements>`_
36
+ 9. `Contributors <#contributors>`_
37
+ 10. `License <#license>`_
38
+
39
+ ----
40
+
41
+ ==================
42
+ 🚀 Quick Start
43
+ ==================
44
+
45
+ .. quickstart-start
46
+
47
+ .. code-block:: python
48
+
49
+ from tiamat.pipeline import Pipeline
50
+ from tiamat.io import ImageAccessor
51
+ from tiamat.transformers.color import LUTTransformer
52
+
53
+ # Create a pipeline with fractional coordinate access and a rainbow colormap
54
+ pipeline = Pipeline(
55
+ image_transformers=[LUTTransformer(colormap="rainbow")]
56
+ )
57
+
58
+ # Request the central 50% of the image
59
+ accessor = ImageAccessor(x=(0.25, 0.75), y=(0.25, 0.75))
60
+ result = pipeline("example_image.tif", accessor=accessor)
61
+
62
+ # Get the transformed NumPy image and metadata
63
+ image = result.image
64
+ metadata = result.metadata
65
+
66
+ .. quickstart-end
67
+
68
+ ----
69
+
70
+ ==================
71
+ 📦 Installation
72
+ ==================
73
+
74
+ .. installation-start
75
+
76
+ Install the latest development version directly from GitLab:
77
+
78
+ .. code-block:: bash
79
+
80
+ pip install git+https://jugit.fz-juelich.de/inm-1/bda/software/data_access/tiamat/tiamat
81
+
82
+ .. installation-end
83
+
84
+ ----
85
+
86
+ ==================
87
+ 🧠 Core Concepts
88
+ ==================
89
+
90
+ .. coreconcepts-start
91
+
92
+ Tiamat defines a modular pipeline composed of:
93
+
94
+ - **Readers** – Load image data from formats like TIFF, NIfTI, HDF5, or memory arrays.
95
+ - **Transformers** – Apply dynamic, on-the-fly transformations (e.g., colormaps, axis reordering, tiling).
96
+ - **Interfaces** – Serve data to tools like Napari, Neuroglancer, OpenSeadragon, or directly as arrays.
97
+
98
+ This decoupled architecture allows you to:
99
+
100
+ - Build pipelines from reusable components
101
+ - Extend with custom readers or transformers
102
+ - Avoid costly format conversions
103
+
104
+ .. coreconcepts-end
105
+
106
+ ----
107
+
108
+ ============
109
+ 📁 Examples
110
+ ============
111
+
112
+ .. examples-start
113
+
114
+ See the ``examples/`` directory for usage demonstrations and pipeline configurations.
115
+
116
+ .. examples-end
117
+
118
+ ----
119
+
120
+ ==============================
121
+ 🛠️ Development Guidelines
122
+ ==============================
123
+
124
+ .. development-start
125
+
126
+ - Follow `PEP 561 <https://peps.python.org/pep-0561/>`_ type hinting
127
+ - Use `Google-style docstrings <https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings>`_
128
+ - Formatting: ``flake8`` with line length 120
129
+ - Tests: ``pytest`` unit tests
130
+ - Feature development follows ``git-flow``
131
+
132
+ .. development-end
133
+
134
+ ----
135
+
136
+ ==================
137
+ 🤝 Contributing
138
+ ==================
139
+
140
+ **We welcome contributions!**
141
+
142
+ .. contributing-start
143
+
144
+ - Fork the repository and work on a feature branch
145
+ - Submit a Merge Request (MR) into ``develop``
146
+ - All contributions are reviewed and tested before merging
147
+
148
+ .. contributing-end
149
+
150
+ This project follows the `git-flow workflow <https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow>`_.
151
+ Releases are merged into ``master`` from ``develop`` on a regular basis.
152
+
153
+ ----
154
+
155
+ ============
156
+ 📂 Data
157
+ ============
158
+
159
+ .. data-start
160
+
161
+ Some test and example datasets require ``git-lfs`` for download.
162
+
163
+ .. data-end
164
+
165
+ ----
166
+
167
+ ==================
168
+ 👥 Contributors
169
+ ==================
170
+
171
+ .. contributors-start
172
+
173
+ - Forschungszentrum Jülich, Institute of Neuroscience and Medicine (INM-1)
174
+ - Community contributors via GitLab merge requests
175
+
176
+ .. contributors-end
177
+
178
+ ----
179
+
180
+ ============
181
+ 📄 License
182
+ ============
183
+
184
+ .. license-start
185
+
186
+ Apache 2.0 – see `LICENSE <./LICENSE>`_ for details.
187
+
188
+ .. license-end
189
+
190
+ ----
191
+
192
+ ========================
193
+ 🙏 Acknowledgements
194
+ ========================
195
+
196
+ .. acknowledgements-start
197
+
198
+ This project received funding from the European Union's Horizon 2020 Research and Innovation Programme, grant agreement
199
+ 101147319 (EBRAINS 2.0 Project), the Helmholtz Association port-folio theme "Supercomputing and Modeling for the Human
200
+ Brain", the Helmholtz Association's Initiative and Networking Fund through the Helmholtz International BigBrain
201
+ Analytics and Learning Laboratory (HIBALL) under the Helmholtz International Lab grant agreement InterLabs-0015,
202
+ from HELMHOLTZ IMAGING, a platform of the Helmholtz Information & Data Science Incubator [X-BRAIN, grant number:
203
+ ZT-I-PF-4-061], and from the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under the National
204
+ Research Data Infrastructure – NFDI 46/1 – 501864659.
205
+
206
+ .. acknowledgements-end
@@ -48,7 +48,7 @@ tiamat = "tiamat.cli:cli"
48
48
 
49
49
  [project.optional-dependencies]
50
50
  dev = ["autopep8", "flake8", "pre-commit", "pytest"]
51
- zarr = ["zarr"]
51
+ zarr = ["tensorstore; python_version >= '3.11'"]
52
52
 
53
53
  [project.urls]
54
54
  homepage = "https://www.fz-juelich.de/de/inm/inm-1"
@@ -0,0 +1,206 @@
1
+ """
2
+ Metadata on images.
3
+ """
4
+
5
+ from collections.abc import Iterable
6
+ from dataclasses import dataclass, field
7
+ from itertools import product, repeat
8
+
9
+ import numpy as np
10
+
11
+ import tiamat.metadata.dimensions as dimensions
12
+
13
+ # Image types
14
+ IMAGE_TYPE_SEGMENTATION = "segmentation" # an image with discrete values, e.g., a mask or a segmentation.
15
+ IMAGE_TYPE_IMAGE = "image" # an image with continuous values (e.g., a microscopy image).
16
+ IMAGE_TYPE_VECTOR = "vector" # an image with continuous vector values (e.g., a deformation field).
17
+
18
+
19
+ def get_dtype_limits(dtype):
20
+ """Returns the min and max values for a given dtype.
21
+
22
+ Supports numpy dtypes (integer or float)
23
+
24
+ Args:
25
+ dtype: numpy dtype
26
+
27
+ Returns:
28
+ tuple: min and max value of the dtype.
29
+ """
30
+
31
+ dtype = np.dtype(dtype)
32
+
33
+ if issubclass(dtype.type, np.integer):
34
+ info = np.iinfo(dtype)
35
+ elif issubclass(dtype.type, np.floating):
36
+ info = np.finfo(dtype)
37
+ else:
38
+ raise RuntimeError(f"{dtype} is not a valid dtype")
39
+ return info.min, info.max
40
+
41
+
42
+ @dataclass
43
+ class ImageMetadata:
44
+ """
45
+ Metadata describing an image result and its storage properties.
46
+
47
+ Attributes
48
+ ----------
49
+ image_type:
50
+ Logical type of the image defining how its data should be interpreted.
51
+ Typical examples include raw intensity images, segmentation masks,
52
+ or vector fields.
53
+
54
+ Must be one of:
55
+
56
+ - ``tiamat.metadata.IMAGE_TYPE_SEGMENTATION``
57
+ - ``tiamat.metadata.IMAGE_TYPE_IMAGE``
58
+ - ``tiamat.metadata.IMAGE_TYPE_VECTOR``
59
+
60
+ shape:
61
+ Shape of the image array at full resolution, expressed as a tuple
62
+ of integers describing the number of pixels or voxels along each
63
+ dimension.
64
+
65
+ The default dimension order is ``(z, y, x)``. This order matches the
66
+ typical indexing order used in NumPy arrays and ensures efficient
67
+ memory access.
68
+
69
+ value_range:
70
+ Expected minimum and maximum values of the image data, given as
71
+ ``(min, max)``.
72
+
73
+ The range is typically derived from the limits of ``dtype``,
74
+ but can also refer to the expected modality-specific limits.
75
+
76
+ This information may be used for normalization, data type conversion,
77
+ or visualization.
78
+
79
+ dtype:
80
+ NumPy data type used to store the image values.
81
+
82
+ dimensions:
83
+ Ordered names of the dimensions corresponding to ``shape``.
84
+ Valid dimension names are defined in ``tiamat.metadata.dimensions``.
85
+
86
+ The default order is ``(y, x, c)``, with the channel dimension
87
+ placed last.
88
+
89
+ file_path:
90
+ Path or collection of paths pointing to the file(s) storing the
91
+ image data.
92
+
93
+ Multiple paths typically indicate that the image data is read from
94
+ multiple files (for example an image stack). May be ``None`` if
95
+ the image is not associated with files on disk.
96
+
97
+ spacing:
98
+ Physical spacing between pixels or voxels at full resolution,
99
+ expressed in micrometers.
100
+
101
+ The value may be a single scalar (uniform spacing) or a tuple
102
+ specifying spacing per spatial dimension. Spacing is defined only
103
+ for spatial dimensions and does not apply to channel dimensions.
104
+
105
+ The dimension order follows ``(x, y)`` or ``(x, y, z)``.
106
+
107
+ additional_metadata:
108
+ Dictionary containing arbitrary additional metadata that is not
109
+ covered by the standard attributes.
110
+
111
+ This dictionary may contain reader-specific metadata or metadata
112
+ generated by the transform_metadata functions.
113
+
114
+ scales:
115
+ Scaling factors describing the available resolution levels of the
116
+ image (for example in a multi-resolution pyramid).
117
+
118
+ The value may be a single scale or an iterable of scales if multiple
119
+ resolutions are available.
120
+
121
+ Each scale may be either:
122
+
123
+ - a single numeric value for isotropic scaling, or
124
+ - a tuple specifying one scale value per spatial dimension.
125
+
126
+ A scale of ``1.0`` refers to the image at full resolution. Smaller
127
+ values indicate downsampled versions relative to the original size
128
+ (e.g. ``0.5`` corresponds to a downsampling factor of two).
129
+
130
+ The dimension order follows ``(x, y)`` or ``(x, y, z)``.
131
+ """
132
+
133
+ image_type: str
134
+ shape: tuple
135
+ value_range: tuple
136
+ dtype: np.dtype
137
+ dimensions: list[str, ...] | tuple[str, ...] = (dimensions.Y, dimensions.X, dimensions.C)
138
+ file_path: Iterable[str] | str | None = None
139
+ spacing: float | tuple[float, ...] | None = None
140
+ additional_metadata: dict = field(default_factory=dict)
141
+ scales: float | int | Iterable[float | int] | None = None
142
+
143
+ @property
144
+ def spatial_dimensions(self):
145
+ """
146
+ Returns indices of spatial dimensions, excluding channels
147
+ """
148
+ return tuple(
149
+ self.dimensions.index(dimension)
150
+ for dimension in dimensions.SPATIAL_DIMENSIONS
151
+ if dimension in self.dimensions
152
+ )
153
+
154
+ @property
155
+ def channel_dimensions(self):
156
+ """
157
+ Returns indices of channels, excluding spatial dimensions
158
+ """
159
+ return tuple(index for index, _ in enumerate(self.shape) if index not in self.spatial_dimensions)
160
+
161
+ @property
162
+ def spatial_shape(self):
163
+ """
164
+ Spatial shape of the image array, ignoring channel dimensions
165
+ """
166
+ return tuple(self.shape[i] for i in self.spatial_dimensions)
167
+
168
+ @spatial_shape.setter
169
+ def spatial_shape(self, shape):
170
+ shape_list = list(self.shape)
171
+ for i, ix in enumerate(self.spatial_dimensions):
172
+ shape_list[ix] = shape[i]
173
+ self.shape = tuple(shape_list)
174
+
175
+ @property
176
+ def extents(self):
177
+ """
178
+ Extents of the image. Provided as a list of tuple of coordinates.
179
+ Extrapolated by shape. Can be set, and will then return the set value.
180
+ Delete the property to revert to the default behavior.
181
+ """
182
+ if hasattr(self, "_extents"):
183
+ return self._extents
184
+ extents = list(zip(repeat(0), self.shape))
185
+ return list(product(*extents))
186
+
187
+ @extents.deleter
188
+ def extents(self):
189
+ delattr(self, "_extents")
190
+
191
+ def __repr__(self):
192
+ return (
193
+ f"ImageMetadata(\n"
194
+ f" image_type={self.image_type},\n"
195
+ f" shape={self.shape},\n"
196
+ f" value_range={self.value_range},\n"
197
+ f" dtype={self.dtype},\n"
198
+ f" spacing={self.spacing},\n"
199
+ f" dimensions=({','.join(self.dimensions)}),\n"
200
+ f" additional_metadata={self.additional_metadata},\n"
201
+ f" scales={self.scales}\n"
202
+ f")"
203
+ )
204
+
205
+ def __str__(self):
206
+ return self.__repr__()
@@ -757,34 +757,41 @@ class VolumeStackReader(ImageReader):
757
757
 
758
758
  out_image[tuple(index_to)] = array[tuple(index_from)]
759
759
 
760
- # Build volume stack
761
- cur_z_offset = 0
760
+ # Current offset each subvolume
761
+ volume_z_offset = 0
762
+
763
+ # Current coverage of read image data
764
+ coverage_offset = z_from
765
+
766
+ # Iterate all subvolumes
762
767
  for handle, shape in zip(self.ordered_subvolume_handles, self.subvolume_shapes):
768
+ # Size of the current subvolume
763
769
  z_size = shape[z_dim]
764
770
 
765
- # Use only slice handles with z slice overlap
766
- if cur_z_offset + z_size > z_from and cur_z_offset < z_to:
771
+ # Access only required subvolumes that lay in the accessor range and are not covered yet
772
+ if volume_z_offset + z_size > coverage_offset and volume_z_offset < z_to:
767
773
 
768
- # From, to slice for image access
769
- from_ix = max(z_from - cur_z_offset, 0)
770
- to_ix = min(z_to - cur_z_offset, z_size)
774
+ # Define access slice for the subvolume
775
+ from_ix = coverage_offset - volume_z_offset
776
+ to_ix = min(z_to - volume_z_offset, z_size)
771
777
 
772
778
  # Access subvolume and read from it
773
779
  tmp_accessor = replace(accessor, z=(from_ix, to_ix))
774
-
775
- # print("VolumeStackReader", accessor)
776
780
  tmp_image = handle.read_image(accessor=tmp_accessor)
777
781
 
778
- # Position in the output array to place the image
779
- scaled_z_offset = math.floor(max(cur_z_offset - z_from, 0) * image_scales[-1])
780
-
781
- # Insert the result in the array at specific offfset
782
+ # Position result in the output array
783
+ scaled_z_offset = math.floor(max(coverage_offset - z_from, 0) * image_scales[-1])
782
784
  insert_array(tmp_image, scaled_z_offset)
783
785
 
784
- # Output image might cover more than z_size
785
- cur_z_offset += z_size # tmp_image.shape[z_dim] / image_scales[-1]
786
- else:
787
- cur_z_offset += z_size
786
+ # Actual coverage of the newly read image data
787
+ tmp_coverage = tmp_image.shape[z_dim]
788
+ scaled_coverage = math.floor(tmp_coverage / image_scales[-1])
789
+
790
+ # Update total coverage of read image data
791
+ coverage_offset = coverage_offset + scaled_coverage
792
+
793
+ # Prepare offset for the next subvolume
794
+ volume_z_offset += z_size
788
795
 
789
796
  return out_image
790
797