micro-reader 0.4.4__tar.gz → 0.5.0__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 (78) hide show
  1. {micro_reader-0.4.4 → micro_reader-0.5.0}/.gitignore +1 -0
  2. micro_reader-0.5.0/PKG-INFO +314 -0
  3. micro_reader-0.5.0/README.md +259 -0
  4. {micro_reader-0.4.4 → micro_reader-0.5.0}/pyproject.toml +3 -2
  5. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/__init__.py +2 -1
  6. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_axes.py +52 -0
  7. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_base.py +17 -0
  8. micro_reader-0.5.0/src/micro_reader/_engine.py +255 -0
  9. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_fileset.py +43 -26
  10. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_io.py +73 -7
  11. micro_reader-0.5.0/src/micro_reader/_many.py +92 -0
  12. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_version.py +1 -1
  13. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/czi.py +102 -1
  14. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/metamorph.py +39 -24
  15. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/oif.py +2 -1
  16. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/tiff.py +101 -10
  17. micro_reader-0.4.4/PKG-INFO +0 -989
  18. micro_reader-0.4.4/README.md +0 -935
  19. {micro_reader-0.4.4 → micro_reader-0.5.0}/LICENSE +0 -0
  20. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_cfb.py +0 -0
  21. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_codecs.py +0 -0
  22. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_errors.py +0 -0
  23. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_eubi_guard.py +0 -0
  24. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_groups.py +0 -0
  25. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_index.py +0 -0
  26. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_jpeg_restarts.py +0 -0
  27. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_lambda.py +0 -0
  28. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_memory.py +0 -0
  29. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_metadata.py +0 -0
  30. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_mosaic.py +0 -0
  31. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_naming.py +0 -0
  32. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_outline.py +0 -0
  33. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_parts.py +0 -0
  34. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_plate.py +0 -0
  35. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_pool.py +0 -0
  36. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_registry.py +0 -0
  37. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_spatial.py +0 -0
  38. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_stack.py +0 -0
  39. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/_stream.py +0 -0
  40. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/__init__.py +0 -0
  41. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_czi_metadata.py +0 -0
  42. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_ets.py +0 -0
  43. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_hdf5.py +0 -0
  44. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_lif_metadata.py +0 -0
  45. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_nd2_legacy.py +0 -0
  46. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_nd2_metadata.py +0 -0
  47. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_nd2_run.py +0 -0
  48. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_nd2_structure.py +0 -0
  49. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_tiff_metadata.py +0 -0
  50. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_tiff_variants.py +0 -0
  51. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/_vsi_tree.py +0 -0
  52. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/bdv.py +0 -0
  53. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/cellomics.py +0 -0
  54. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/columbus.py +0 -0
  55. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/companion.py +0 -0
  56. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/cv7000.py +0 -0
  57. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/dv.py +0 -0
  58. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/flex.py +0 -0
  59. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/harmony.py +0 -0
  60. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/hdf5.py +0 -0
  61. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/ics.py +0 -0
  62. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/ilastik.py +0 -0
  63. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/ims.py +0 -0
  64. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/incell.py +0 -0
  65. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/jdce.py +0 -0
  66. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/klb.py +0 -0
  67. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/lif.py +0 -0
  68. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/luxendo.py +0 -0
  69. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/metaxpress.py +0 -0
  70. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/micromanager.py +0 -0
  71. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/mrc.py +0 -0
  72. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/nd2.py +0 -0
  73. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/ndpis.py +0 -0
  74. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/oir.py +0 -0
  75. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/omp2info.py +0 -0
  76. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/raster.py +0 -0
  77. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/scanr.py +0 -0
  78. {micro_reader-0.4.4 → micro_reader-0.5.0}/src/micro_reader/backends/vsi.py +0 -0
@@ -10,6 +10,7 @@ dist/
10
10
 
11
11
  # Rust / maturin
12
12
  codecs/target/
13
+ core/target/
13
14
 
14
15
  # editors and OS
15
16
  .vscode/
@@ -0,0 +1,314 @@
1
+ Metadata-Version: 2.5
2
+ Name: micro-reader
3
+ Version: 0.5.0
4
+ Summary: Low-level, memory-bounded pixel reading for microscopy formats: read exactly the rectangle you ask for.
5
+ Project-URL: Homepage, https://github.com/bugraoezdemir/micro-reader
6
+ Project-URL: Source, https://github.com/bugraoezdemir/micro-reader
7
+ Project-URL: Issues, https://github.com/bugraoezdemir/micro-reader/issues
8
+ Author-email: Bugra Oezdemir <bugraa.ozdemir@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: bioimage,cryo-em,czi,eer,image-io,imaris,ims,leica,lif,lsm,memory-bounded,microscopy,mrc,nd2,oir,ome-tiff,tiff
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: micro-reader-codecs<0.1,>=0.0.4
22
+ Requires-Dist: micro-reader-core<0.1,>=0.0.1
23
+ Requires-Dist: numpy>=1.24
24
+ Requires-Dist: tifffile>=2025.5.21
25
+ Provides-Extra: all
26
+ Requires-Dist: h5py>=3.11; extra == 'all'
27
+ Requires-Dist: imagecodecs; extra == 'all'
28
+ Provides-Extra: codecs
29
+ Requires-Dist: imagecodecs; extra == 'codecs'
30
+ Provides-Extra: dev
31
+ Requires-Dist: h5py>=3.11; extra == 'dev'
32
+ Requires-Dist: imagecodecs; extra == 'dev'
33
+ Requires-Dist: liffile; extra == 'dev'
34
+ Requires-Dist: nd2; extra == 'dev'
35
+ Requires-Dist: pillow; extra == 'dev'
36
+ Requires-Dist: pylibczirw; (python_version < '3.14') and extra == 'dev'
37
+ Requires-Dist: pytest; extra == 'dev'
38
+ Requires-Dist: readlif; extra == 'dev'
39
+ Requires-Dist: zstandard; extra == 'dev'
40
+ Provides-Extra: hdf5
41
+ Requires-Dist: h5py>=3.11; extra == 'hdf5'
42
+ Provides-Extra: ims
43
+ Requires-Dist: h5py>=3.11; extra == 'ims'
44
+ Provides-Extra: test
45
+ Requires-Dist: h5py>=3.11; extra == 'test'
46
+ Requires-Dist: imagecodecs; extra == 'test'
47
+ Requires-Dist: liffile; extra == 'test'
48
+ Requires-Dist: nd2; extra == 'test'
49
+ Requires-Dist: pillow; extra == 'test'
50
+ Requires-Dist: pylibczirw; (python_version < '3.14') and extra == 'test'
51
+ Requires-Dist: pytest; extra == 'test'
52
+ Requires-Dist: readlif; extra == 'test'
53
+ Requires-Dist: zstandard; extra == 'test'
54
+ Description-Content-Type: text/markdown
55
+
56
+ # micro-reader
57
+
58
+ **Fast, memory-bounded reading of image regions from large microscopy files.**
59
+
60
+ `micro-reader` is a Python library for reading regions of interest from microscopy images. It lets you access a small part of a large image without loading the entire image into memory, enabling streaming of image regions from arbitrary microscopy datasets.
61
+
62
+ The library supports a wide range of microscopy formats through a common interface. It reads only the data needed for each request, works with the file's stored resolution levels, and uses parallel decoding to make region access fast.
63
+
64
+ [Documentation](https://bugraoezdemir.github.io/micro-reader/) · [PyPI](https://pypi.org/project/micro-reader/) · [Changelog](https://github.com/bugraoezdemir/micro-reader/blob/main/CHANGELOG.md)
65
+
66
+ > **Alpha release (0.x)**
67
+ >
68
+ > The API may change between releases. Pin the version you use in your projects.
69
+
70
+ ## Installation
71
+
72
+ ```bash
73
+ pip install micro-reader
74
+ ```
75
+
76
+ Requires Python 3.11 or newer. The native image decoders are provided by `micro-reader-codecs` and the native read engine by `micro-reader-core`. Both are installed automatically. Prebuilt wheels are available for Linux (x86-64 and ARM), macOS (Intel and Apple silicon) and Windows (x86-64).
77
+
78
+ Some formats and less common TIFF compression methods require optional dependencies:
79
+
80
+ ```bash
81
+ pip install "micro-reader[hdf5]" # HDF5-based formats
82
+ pip install "micro-reader[codecs]" # additional TIFF codecs
83
+ pip install "micro-reader[all]" # both
84
+ ```
85
+
86
+ The HDF5 extra supports Imaris (`.ims`), ilastik, BigDataViewer, Luxendo and Fiji HDF5 files. The codecs extra adds support for less common TIFF compression methods, including LERC, CCITT fax and float24.
87
+
88
+ ## Quick start
89
+
90
+ Open a microscopy file, choose an image and read the region you need:
91
+
92
+ ```python
93
+ import micro_reader
94
+
95
+ with micro_reader.open("image.czi") as f:
96
+ image = f.images[0]
97
+
98
+ print(image.axes, image.shape, image.dtype)
99
+ # tczyx (1, 3, 40, 5120, 6144) uint16
100
+
101
+ # Read a 2000 × 2048 region from channel 1, plane 10
102
+ region = image.read(
103
+ c=1, z=10,
104
+ y=slice(0, 2048),
105
+ x=slice(1000, 3000),
106
+ )
107
+
108
+ print(region.shape)
109
+ # (1, 2048, 2000): t is kept, c and z are dropped
110
+ ```
111
+
112
+ You can also use NumPy-style indexing:
113
+
114
+ ```python
115
+ region = image[0, 1, 10, 0:2048, 1000:3000]
116
+ ```
117
+
118
+ The returned array contains only the requested region. The memory required for the read therefore depends on the region and the underlying storage blocks, and is independent of the total size of the image.
119
+
120
+ Images use the axes `t c z y x`. Other dimensions, such as series, tiles, views, wells and fields, are represented as separate images and identified by their indices. Use `f.select()` to find images by these indices:
121
+
122
+ ```python
123
+ image = f.select(series=1, tile=3)[0]
124
+ ```
125
+
126
+ ## Reading regions from large images
127
+
128
+ Microscopy files often contain images that are too large to load into memory comfortably. Whole-slide scans, large mosaics and high-resolution volumetric images are common examples.
129
+
130
+ `micro-reader` is designed to access these datasets by region. When you request a rectangular area, it reads and decodes the data needed to produce that area, rather than loading the complete image first.
131
+
132
+ For compressed files, the amount of data that must be decoded depends on how the image is stored. Some formats allow individual regions or rows to be decoded independently. Others store pixels in larger blocks that must be decoded together. `micro-reader` handles these differences and reports how much data was actually read through `image.stats`.
133
+
134
+ ### Example: a whole-slide CZI
135
+
136
+ This 3.6 GB Zeiss CZI slide scan contains 6,093 JPEG XR-compressed tiles. Open it as a mosaic to access each scan region as one image:
137
+
138
+ ```python
139
+ f = micro_reader.open("22_0670_6D_11_MUS_3.czi", tiles="mosaic")
140
+
141
+ for image in f.images:
142
+ print(image.name, image.shape)
143
+
144
+ # ScanRegion0 (1, 3, 1, 79995, 60633)
145
+ # ScanRegion1 (1, 3, 1, 76768, 56314)
146
+ # ScanRegion2 (1, 3, 1, 71377, 56337)
147
+ # label (1, 3, 1, 545, 689)
148
+ # slide preview (1, 3, 1, 717, 1568)
149
+ ```
150
+
151
+ Read a small RGB region from one of the scan areas:
152
+
153
+ ```python
154
+ image = f.images[0]
155
+
156
+ region = image[0, :, 0, 40000:42048, 30000:32048]
157
+ region.shape
158
+ # (3, 2048, 2048)
159
+ ```
160
+
161
+ The file also contains a resolution pyramid, which can be used to read smaller versions of the image without calculating them from the full-resolution data:
162
+
163
+ ```python
164
+ len(image.resolutions)
165
+ # 8
166
+
167
+ overview = image.resolutions[-1].read()
168
+ ```
169
+
170
+ With `tiles="mosaic"`, tiles are placed at their recorded positions on a common canvas. They are not registered or blended. By default, tiles remain separate images with their own stage positions, which is useful when you want to perform registration or stitching yourself.
171
+
172
+ ### Example: a high-content screening plate
173
+
174
+ The same interface can be used with plate-based acquisitions:
175
+
176
+ ```python
177
+ f = micro_reader.open("1053601756.wpi") # Yokogawa CV8000 plate
178
+
179
+ plate = f.plates[0]
180
+ plate.name
181
+ # '1053601756'
182
+
183
+ len(plate.wells), len(f.images)
184
+ # (384, 2304)
185
+
186
+ fields = f.select(plate_name=plate.name, well_name="B2")
187
+ # The six fields acquired in well B2 of this plate
188
+ # Each field is an Image object and has its API
189
+
190
+ [ch.name for ch in fields[0].metadata.channels]
191
+ # ['Hoechst', 'Concanavalin', 'SYTO',
192
+ # 'WGA_Phalloidin', 'MitoTracker', 'TL']
193
+
194
+ # Read a field like any other Image object
195
+ nuclei = fields[0].read(c=0)
196
+ ```
197
+
198
+ > **Important!**
199
+ >
200
+ > `select()` matches every index in the File object by default. Without `plate_name` (or the plate's position, `plate`), a well name selects that well in every plate the file holds. It is therefore good practice to name every index you want to search within.
201
+ >
202
+ > Each plate's name is in `f.plates[i].name`, and `print(f)` lists the plates with their names. A plate whose file records no name has the name `""`; select it by position instead, for example `plate=0`.
203
+
204
+ See [Getting started](https://bugraoezdemir.github.io/micro-reader/getting-started/) for a step-by-step introduction.
205
+
206
+ ## Memory-bounded image reading
207
+
208
+ A region read does not require the complete image to fit in memory. `micro-reader` reads the strips, tiles, subblocks or chunks that overlap the requested region.
209
+
210
+ It can also decode large compressed blocks in smaller parts when the compression method allows it. This includes Deflate, LZW, zstd, JPEG 2000 and JPEG with restart markers. For compression methods that require a complete block to be decoded, the block size determines the minimum amount of data that must be processed.
211
+
212
+ All decoding is subject to a process-wide memory limit. This helps keep memory use under control when reading large images or processing several regions concurrently:
213
+
214
+ ```python
215
+ micro_reader.set_memory_limit("2GB")
216
+ ```
217
+
218
+ The library also provides read statistics, including the number of pixels returned and the number of pixels that had to be read or decoded. These help identify cases where the file's storage layout makes a region read more expensive than expected.
219
+
220
+ See [Memory and threads](https://bugraoezdemir.github.io/micro-reader/guide/performance/) for details.
221
+
222
+ ## Fast image decoding
223
+
224
+ `micro-reader` uses native decoding libraries provided by `micro-reader-codecs`. These include libjpeg-turbo, jxrlib, OpenJPEG, libdeflate and zstd.
225
+
226
+ Decoding is parallelised across CPU cores, and native decoding releases Python's global interpreter lock. A single read can therefore make use of multiple cores. For TIFF and CZI files, the read engine in `micro-reader-core` reads, decodes and places all the pieces of a region in one call, on its own threads. Decoded blocks are also cached, so nearby region requests can reuse data that has already been decoded.
227
+
228
+ The benchmarks below show typical reading times for several microscopy formats.
229
+
230
+ ## Supported formats
231
+
232
+ | Format | Supported variants |
233
+ | --- | --- |
234
+ | **TIFF / BigTIFF** | TIFF, OME-TIFF, ImageJ, Zeiss LSM, MetaMorph STK, Micro-Manager, ScanImage and whole-slide TIFFs (Aperio SVS, Hamamatsu NDPI, Leica SCN, Ventana BIF, Akoya QPTIFF, Philips) |
235
+ | **OME companion files** | `.companion.ome` sets of OME-TIFF files |
236
+ | **Zeiss CZI** | Mosaic tiles, stored resolution pyramids and JPEG XR slide scans |
237
+ | **Nikon ND2** | Including legacy JPEG 2000 files |
238
+ | **Leica** | LIF, LOF, LIFEXT, XLIF, XLEF, XLCF |
239
+ | **Olympus / Evident** | OIR, OIB, OIF and VSI slide scans |
240
+ | **Hamamatsu NDPIS** | Fluorescence sets with one NDPI file per channel |
241
+ | **Imaris** | `.ims`, requires the `[hdf5]` extra |
242
+ | **Other HDF5** | ilastik, BigDataViewer / BigStitcher, Luxendo and Fiji HDF5, requires the `[hdf5]` extra |
243
+ | **ICS / IDS** | ICS 1.0 and 2.0 |
244
+ | **MetaMorph** | `.nd` acquisitions |
245
+ | **Micro-Manager 1.4** | Image-per-file acquisitions |
246
+ | **DeltaVision** | `.dv`, `.r3d` |
247
+ | **MRC** | Common MRC modes |
248
+ | **KLB** | Keller Lab Block files |
249
+ | **JPEG / PNG / BMP** | Common raster image formats |
250
+ | **Screening plates** | Harmony, Columbus, MetaXpress, ImageXpress HCS.ai, IN Cell, CellVoyager, Opera Flex, scanR and Cellomics; also CZI, ND2, OME companion and OME-TIFF files recorded on Yokogawa CQ1 plates |
251
+
252
+ The [Formats](https://bugraoezdemir.github.io/micro-reader/formats/) page describes format-specific features and metadata support.
253
+
254
+ The following formats are not yet supported: DICOM whole-slide images, 3DHISTECH MRXS, Hamamatsu VMS, Zeiss ZVI, Becker & Hickl SDT, PicoQuant PTU, Imaris 3 files stored as TIFF, and ICS 1.0 files with Unix-compressed pixels.
255
+
256
+ ## Benchmarks
257
+
258
+ The following measurements were made with micro-reader 0.4.4 on a laptop with an Intel Core Ultra 7 255H (16 cores), 31 GB RAM and an NVMe SSD, running Windows 11.
259
+
260
+ The default settings were used (16 decoding threads). Each measurement is the median of three runs in fresh processes. The 512 × 512 measurements are the median over 100 randomly selected regions at full resolution.
261
+
262
+ All times are for reading from disk. The operating system's file cache, the copy of recently read file data that the operating system keeps in memory, was emptied before every run and again before every large read. Reading the same data a second time is faster.
263
+
264
+ Peak memory recorded during the read includes the returned array. "≈ read region's size" marks reads whose peak memory is almost entirely the returned array itself.
265
+
266
+ | File | File size | Read | Time | Peak memory |
267
+ | --- | ---: | --- | ---: | ---: |
268
+ | Hamamatsu NDPI slide (JPEG, 101,376 × 188,160) | 6.9 GB | 512 × 512 RGB region | 4.6 ms | |
269
+ | | | 8192 × 8192 RGB region (192 MB) | 0.33 s | 378 MB |
270
+ | Ventana BIF slide (JPEG, 93,951 × 105,813) | 3.9 GB | 512 × 512 RGB region | 8.5 ms | |
271
+ | | | 8192 × 8192 RGB region (192 MB) | 0.21 s | 384 MB |
272
+ | Zeiss CZI slide scan (JPEG XR, 6,093 tiles) | 3.6 GB | 512 × 512 RGB region | 31 ms | |
273
+ | | | 8192 × 8192 RGB region (192 MB) | 0.52 s | 383 MB |
274
+ | Aperio SVS slide (JPEG) | 596 MB | 512 × 512 RGB region | 1.5 ms | |
275
+ | | | 8192 × 8192 RGB region (192 MB) | 0.24 s | 379 MB |
276
+ | MRC image (uncompressed, 67,320 × 50,960) | 6.9 GB | 512 × 512 region | 29 ms | |
277
+ | | | 8192 × 8192 region (128 MB) | 0.85 s | 121 MB (≈ read region's size) |
278
+ | ICS / IDS, deconvolved (float32, 4 c × 226 z of 1352 × 1352) | 6.6 GB | One channel: 226 z of 1352 × 1352 (1.5 GB) | 0.92 s | 1.5 GB (≈ read region's size) |
279
+ | Micro-Manager OME-TIFF, two files (140 t × 3 c × 21 z) | 4.7 GB | One channel: 140 t × 21 z of 512 × 512 (1.4 GB) | 0.26 s | 1.4 GB (≈ read region's size) |
280
+ | Imaris IMS (gzip chunks, float32, 9 c × 569 z) | 3.1 GB | One channel: 569 z of 512 × 512 (569 MB) | 0.17 s | 636 MB |
281
+ | Nikon ND2, 46 XY points | 395 MB | Whole file: 46 points × 31 t × 2 c (362 MB) | 0.24 s | 356 MB (≈ read region's size) |
282
+ | Zeiss CZI plate: 20 wells, 500 fields | 27.5 GB | Open | 1.8 s | |
283
+ | | | One well: 25 fields × 7 c × 3 z of 1144 × 1144 (1.3 GB) | 0.29 s | 1.3 GB (≈ read region's size) |
284
+ | Zeiss CZI fluorescence mosaic (5 × 9 tiles per well) | 738 MB | One channel of a well: 2 t × 4 z of 3444 × 2944 (77 MB) | 0.04 s | 74 MB (≈ read region's size) |
285
+ | CellVoyager CV8000 plate: 384 wells, 2,304 fields, 18,452 files | 35 GB | Open | 1.9 s | |
286
+ | | | One well: 6 fields × 6 c × 3 z of 996 × 996, from 108 files (204 MB) | 0.21 s | 205 MB (≈ read region's size) |
287
+
288
+ Actual performance depends on hardware and storage.
289
+
290
+ ## Learn more
291
+
292
+ - **[Getting started](https://bugraoezdemir.github.io/micro-reader/getting-started/):** Install the package, open an image and read a region.
293
+ - **[Concepts](https://bugraoezdemir.github.io/micro-reader/concepts/):** Files, images, indices, axes and coordinate systems.
294
+ - **[User guide](https://bugraoezdemir.github.io/micro-reader/guide/opening/):** Opening files, finding images, reading regions, resolution levels, metadata and plates.
295
+ - **[Formats](https://bugraoezdemir.github.io/micro-reader/formats/):** Supported formats, format-specific features and optional dependencies.
296
+ - **[API reference](https://bugraoezdemir.github.io/micro-reader/reference/):** Public functions, classes, attributes and errors.
297
+ - **[Examples](https://bugraoezdemir.github.io/micro-reader/examples/):** Recipes for image processing, Zarr export, Dask, plates and parallel workers.
298
+
299
+ ## Used by
300
+
301
+ - **[EuBI-Bridge](https://github.com/Euro-BioImaging/EuBI-Bridge)** converts microscopy files to OME-Zarr and uses micro-reader as its default reader for supported formats.
302
+ - **[dyna-zarr](https://pypi.org/project/dyna-zarr/)** uses `micro_reader.Image` as a lazy data source for writing Zarr arrays.
303
+
304
+ ## Feedback
305
+
306
+ Bug reports, requests for additional formats and sample files are welcome on [GitHub](https://github.com/bugraoezdemir/micro-reader/issues).
307
+
308
+ ### Development note
309
+
310
+ The project has been developed with substantial AI assistance. Its functionality is continuously tested against real datasets, but some issues or edge cases may remain undiscovered.
311
+
312
+ ## License
313
+
314
+ `micro-reader`, `micro-reader-codecs` and `micro-reader-core` are MIT licensed. The wheels of the two native packages include third-party libraries. Their notices are available in [`codecs/THIRD_PARTY_LICENSES.txt`](https://github.com/bugraoezdemir/micro-reader/blob/main/codecs/THIRD_PARTY_LICENSES.txt) and [`core/THIRD_PARTY_LICENSES.txt`](https://github.com/bugraoezdemir/micro-reader/blob/main/core/THIRD_PARTY_LICENSES.txt).
@@ -0,0 +1,259 @@
1
+ # micro-reader
2
+
3
+ **Fast, memory-bounded reading of image regions from large microscopy files.**
4
+
5
+ `micro-reader` is a Python library for reading regions of interest from microscopy images. It lets you access a small part of a large image without loading the entire image into memory, enabling streaming of image regions from arbitrary microscopy datasets.
6
+
7
+ The library supports a wide range of microscopy formats through a common interface. It reads only the data needed for each request, works with the file's stored resolution levels, and uses parallel decoding to make region access fast.
8
+
9
+ [Documentation](https://bugraoezdemir.github.io/micro-reader/) · [PyPI](https://pypi.org/project/micro-reader/) · [Changelog](https://github.com/bugraoezdemir/micro-reader/blob/main/CHANGELOG.md)
10
+
11
+ > **Alpha release (0.x)**
12
+ >
13
+ > The API may change between releases. Pin the version you use in your projects.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install micro-reader
19
+ ```
20
+
21
+ Requires Python 3.11 or newer. The native image decoders are provided by `micro-reader-codecs` and the native read engine by `micro-reader-core`. Both are installed automatically. Prebuilt wheels are available for Linux (x86-64 and ARM), macOS (Intel and Apple silicon) and Windows (x86-64).
22
+
23
+ Some formats and less common TIFF compression methods require optional dependencies:
24
+
25
+ ```bash
26
+ pip install "micro-reader[hdf5]" # HDF5-based formats
27
+ pip install "micro-reader[codecs]" # additional TIFF codecs
28
+ pip install "micro-reader[all]" # both
29
+ ```
30
+
31
+ The HDF5 extra supports Imaris (`.ims`), ilastik, BigDataViewer, Luxendo and Fiji HDF5 files. The codecs extra adds support for less common TIFF compression methods, including LERC, CCITT fax and float24.
32
+
33
+ ## Quick start
34
+
35
+ Open a microscopy file, choose an image and read the region you need:
36
+
37
+ ```python
38
+ import micro_reader
39
+
40
+ with micro_reader.open("image.czi") as f:
41
+ image = f.images[0]
42
+
43
+ print(image.axes, image.shape, image.dtype)
44
+ # tczyx (1, 3, 40, 5120, 6144) uint16
45
+
46
+ # Read a 2000 × 2048 region from channel 1, plane 10
47
+ region = image.read(
48
+ c=1, z=10,
49
+ y=slice(0, 2048),
50
+ x=slice(1000, 3000),
51
+ )
52
+
53
+ print(region.shape)
54
+ # (1, 2048, 2000): t is kept, c and z are dropped
55
+ ```
56
+
57
+ You can also use NumPy-style indexing:
58
+
59
+ ```python
60
+ region = image[0, 1, 10, 0:2048, 1000:3000]
61
+ ```
62
+
63
+ The returned array contains only the requested region. The memory required for the read therefore depends on the region and the underlying storage blocks, and is independent of the total size of the image.
64
+
65
+ Images use the axes `t c z y x`. Other dimensions, such as series, tiles, views, wells and fields, are represented as separate images and identified by their indices. Use `f.select()` to find images by these indices:
66
+
67
+ ```python
68
+ image = f.select(series=1, tile=3)[0]
69
+ ```
70
+
71
+ ## Reading regions from large images
72
+
73
+ Microscopy files often contain images that are too large to load into memory comfortably. Whole-slide scans, large mosaics and high-resolution volumetric images are common examples.
74
+
75
+ `micro-reader` is designed to access these datasets by region. When you request a rectangular area, it reads and decodes the data needed to produce that area, rather than loading the complete image first.
76
+
77
+ For compressed files, the amount of data that must be decoded depends on how the image is stored. Some formats allow individual regions or rows to be decoded independently. Others store pixels in larger blocks that must be decoded together. `micro-reader` handles these differences and reports how much data was actually read through `image.stats`.
78
+
79
+ ### Example: a whole-slide CZI
80
+
81
+ This 3.6 GB Zeiss CZI slide scan contains 6,093 JPEG XR-compressed tiles. Open it as a mosaic to access each scan region as one image:
82
+
83
+ ```python
84
+ f = micro_reader.open("22_0670_6D_11_MUS_3.czi", tiles="mosaic")
85
+
86
+ for image in f.images:
87
+ print(image.name, image.shape)
88
+
89
+ # ScanRegion0 (1, 3, 1, 79995, 60633)
90
+ # ScanRegion1 (1, 3, 1, 76768, 56314)
91
+ # ScanRegion2 (1, 3, 1, 71377, 56337)
92
+ # label (1, 3, 1, 545, 689)
93
+ # slide preview (1, 3, 1, 717, 1568)
94
+ ```
95
+
96
+ Read a small RGB region from one of the scan areas:
97
+
98
+ ```python
99
+ image = f.images[0]
100
+
101
+ region = image[0, :, 0, 40000:42048, 30000:32048]
102
+ region.shape
103
+ # (3, 2048, 2048)
104
+ ```
105
+
106
+ The file also contains a resolution pyramid, which can be used to read smaller versions of the image without calculating them from the full-resolution data:
107
+
108
+ ```python
109
+ len(image.resolutions)
110
+ # 8
111
+
112
+ overview = image.resolutions[-1].read()
113
+ ```
114
+
115
+ With `tiles="mosaic"`, tiles are placed at their recorded positions on a common canvas. They are not registered or blended. By default, tiles remain separate images with their own stage positions, which is useful when you want to perform registration or stitching yourself.
116
+
117
+ ### Example: a high-content screening plate
118
+
119
+ The same interface can be used with plate-based acquisitions:
120
+
121
+ ```python
122
+ f = micro_reader.open("1053601756.wpi") # Yokogawa CV8000 plate
123
+
124
+ plate = f.plates[0]
125
+ plate.name
126
+ # '1053601756'
127
+
128
+ len(plate.wells), len(f.images)
129
+ # (384, 2304)
130
+
131
+ fields = f.select(plate_name=plate.name, well_name="B2")
132
+ # The six fields acquired in well B2 of this plate
133
+ # Each field is an Image object and has its API
134
+
135
+ [ch.name for ch in fields[0].metadata.channels]
136
+ # ['Hoechst', 'Concanavalin', 'SYTO',
137
+ # 'WGA_Phalloidin', 'MitoTracker', 'TL']
138
+
139
+ # Read a field like any other Image object
140
+ nuclei = fields[0].read(c=0)
141
+ ```
142
+
143
+ > **Important!**
144
+ >
145
+ > `select()` matches every index in the File object by default. Without `plate_name` (or the plate's position, `plate`), a well name selects that well in every plate the file holds. It is therefore good practice to name every index you want to search within.
146
+ >
147
+ > Each plate's name is in `f.plates[i].name`, and `print(f)` lists the plates with their names. A plate whose file records no name has the name `""`; select it by position instead, for example `plate=0`.
148
+
149
+ See [Getting started](https://bugraoezdemir.github.io/micro-reader/getting-started/) for a step-by-step introduction.
150
+
151
+ ## Memory-bounded image reading
152
+
153
+ A region read does not require the complete image to fit in memory. `micro-reader` reads the strips, tiles, subblocks or chunks that overlap the requested region.
154
+
155
+ It can also decode large compressed blocks in smaller parts when the compression method allows it. This includes Deflate, LZW, zstd, JPEG 2000 and JPEG with restart markers. For compression methods that require a complete block to be decoded, the block size determines the minimum amount of data that must be processed.
156
+
157
+ All decoding is subject to a process-wide memory limit. This helps keep memory use under control when reading large images or processing several regions concurrently:
158
+
159
+ ```python
160
+ micro_reader.set_memory_limit("2GB")
161
+ ```
162
+
163
+ The library also provides read statistics, including the number of pixels returned and the number of pixels that had to be read or decoded. These help identify cases where the file's storage layout makes a region read more expensive than expected.
164
+
165
+ See [Memory and threads](https://bugraoezdemir.github.io/micro-reader/guide/performance/) for details.
166
+
167
+ ## Fast image decoding
168
+
169
+ `micro-reader` uses native decoding libraries provided by `micro-reader-codecs`. These include libjpeg-turbo, jxrlib, OpenJPEG, libdeflate and zstd.
170
+
171
+ Decoding is parallelised across CPU cores, and native decoding releases Python's global interpreter lock. A single read can therefore make use of multiple cores. For TIFF and CZI files, the read engine in `micro-reader-core` reads, decodes and places all the pieces of a region in one call, on its own threads. Decoded blocks are also cached, so nearby region requests can reuse data that has already been decoded.
172
+
173
+ The benchmarks below show typical reading times for several microscopy formats.
174
+
175
+ ## Supported formats
176
+
177
+ | Format | Supported variants |
178
+ | --- | --- |
179
+ | **TIFF / BigTIFF** | TIFF, OME-TIFF, ImageJ, Zeiss LSM, MetaMorph STK, Micro-Manager, ScanImage and whole-slide TIFFs (Aperio SVS, Hamamatsu NDPI, Leica SCN, Ventana BIF, Akoya QPTIFF, Philips) |
180
+ | **OME companion files** | `.companion.ome` sets of OME-TIFF files |
181
+ | **Zeiss CZI** | Mosaic tiles, stored resolution pyramids and JPEG XR slide scans |
182
+ | **Nikon ND2** | Including legacy JPEG 2000 files |
183
+ | **Leica** | LIF, LOF, LIFEXT, XLIF, XLEF, XLCF |
184
+ | **Olympus / Evident** | OIR, OIB, OIF and VSI slide scans |
185
+ | **Hamamatsu NDPIS** | Fluorescence sets with one NDPI file per channel |
186
+ | **Imaris** | `.ims`, requires the `[hdf5]` extra |
187
+ | **Other HDF5** | ilastik, BigDataViewer / BigStitcher, Luxendo and Fiji HDF5, requires the `[hdf5]` extra |
188
+ | **ICS / IDS** | ICS 1.0 and 2.0 |
189
+ | **MetaMorph** | `.nd` acquisitions |
190
+ | **Micro-Manager 1.4** | Image-per-file acquisitions |
191
+ | **DeltaVision** | `.dv`, `.r3d` |
192
+ | **MRC** | Common MRC modes |
193
+ | **KLB** | Keller Lab Block files |
194
+ | **JPEG / PNG / BMP** | Common raster image formats |
195
+ | **Screening plates** | Harmony, Columbus, MetaXpress, ImageXpress HCS.ai, IN Cell, CellVoyager, Opera Flex, scanR and Cellomics; also CZI, ND2, OME companion and OME-TIFF files recorded on Yokogawa CQ1 plates |
196
+
197
+ The [Formats](https://bugraoezdemir.github.io/micro-reader/formats/) page describes format-specific features and metadata support.
198
+
199
+ The following formats are not yet supported: DICOM whole-slide images, 3DHISTECH MRXS, Hamamatsu VMS, Zeiss ZVI, Becker & Hickl SDT, PicoQuant PTU, Imaris 3 files stored as TIFF, and ICS 1.0 files with Unix-compressed pixels.
200
+
201
+ ## Benchmarks
202
+
203
+ The following measurements were made with micro-reader 0.4.4 on a laptop with an Intel Core Ultra 7 255H (16 cores), 31 GB RAM and an NVMe SSD, running Windows 11.
204
+
205
+ The default settings were used (16 decoding threads). Each measurement is the median of three runs in fresh processes. The 512 × 512 measurements are the median over 100 randomly selected regions at full resolution.
206
+
207
+ All times are for reading from disk. The operating system's file cache, the copy of recently read file data that the operating system keeps in memory, was emptied before every run and again before every large read. Reading the same data a second time is faster.
208
+
209
+ Peak memory recorded during the read includes the returned array. "≈ read region's size" marks reads whose peak memory is almost entirely the returned array itself.
210
+
211
+ | File | File size | Read | Time | Peak memory |
212
+ | --- | ---: | --- | ---: | ---: |
213
+ | Hamamatsu NDPI slide (JPEG, 101,376 × 188,160) | 6.9 GB | 512 × 512 RGB region | 4.6 ms | |
214
+ | | | 8192 × 8192 RGB region (192 MB) | 0.33 s | 378 MB |
215
+ | Ventana BIF slide (JPEG, 93,951 × 105,813) | 3.9 GB | 512 × 512 RGB region | 8.5 ms | |
216
+ | | | 8192 × 8192 RGB region (192 MB) | 0.21 s | 384 MB |
217
+ | Zeiss CZI slide scan (JPEG XR, 6,093 tiles) | 3.6 GB | 512 × 512 RGB region | 31 ms | |
218
+ | | | 8192 × 8192 RGB region (192 MB) | 0.52 s | 383 MB |
219
+ | Aperio SVS slide (JPEG) | 596 MB | 512 × 512 RGB region | 1.5 ms | |
220
+ | | | 8192 × 8192 RGB region (192 MB) | 0.24 s | 379 MB |
221
+ | MRC image (uncompressed, 67,320 × 50,960) | 6.9 GB | 512 × 512 region | 29 ms | |
222
+ | | | 8192 × 8192 region (128 MB) | 0.85 s | 121 MB (≈ read region's size) |
223
+ | ICS / IDS, deconvolved (float32, 4 c × 226 z of 1352 × 1352) | 6.6 GB | One channel: 226 z of 1352 × 1352 (1.5 GB) | 0.92 s | 1.5 GB (≈ read region's size) |
224
+ | Micro-Manager OME-TIFF, two files (140 t × 3 c × 21 z) | 4.7 GB | One channel: 140 t × 21 z of 512 × 512 (1.4 GB) | 0.26 s | 1.4 GB (≈ read region's size) |
225
+ | Imaris IMS (gzip chunks, float32, 9 c × 569 z) | 3.1 GB | One channel: 569 z of 512 × 512 (569 MB) | 0.17 s | 636 MB |
226
+ | Nikon ND2, 46 XY points | 395 MB | Whole file: 46 points × 31 t × 2 c (362 MB) | 0.24 s | 356 MB (≈ read region's size) |
227
+ | Zeiss CZI plate: 20 wells, 500 fields | 27.5 GB | Open | 1.8 s | |
228
+ | | | One well: 25 fields × 7 c × 3 z of 1144 × 1144 (1.3 GB) | 0.29 s | 1.3 GB (≈ read region's size) |
229
+ | Zeiss CZI fluorescence mosaic (5 × 9 tiles per well) | 738 MB | One channel of a well: 2 t × 4 z of 3444 × 2944 (77 MB) | 0.04 s | 74 MB (≈ read region's size) |
230
+ | CellVoyager CV8000 plate: 384 wells, 2,304 fields, 18,452 files | 35 GB | Open | 1.9 s | |
231
+ | | | One well: 6 fields × 6 c × 3 z of 996 × 996, from 108 files (204 MB) | 0.21 s | 205 MB (≈ read region's size) |
232
+
233
+ Actual performance depends on hardware and storage.
234
+
235
+ ## Learn more
236
+
237
+ - **[Getting started](https://bugraoezdemir.github.io/micro-reader/getting-started/):** Install the package, open an image and read a region.
238
+ - **[Concepts](https://bugraoezdemir.github.io/micro-reader/concepts/):** Files, images, indices, axes and coordinate systems.
239
+ - **[User guide](https://bugraoezdemir.github.io/micro-reader/guide/opening/):** Opening files, finding images, reading regions, resolution levels, metadata and plates.
240
+ - **[Formats](https://bugraoezdemir.github.io/micro-reader/formats/):** Supported formats, format-specific features and optional dependencies.
241
+ - **[API reference](https://bugraoezdemir.github.io/micro-reader/reference/):** Public functions, classes, attributes and errors.
242
+ - **[Examples](https://bugraoezdemir.github.io/micro-reader/examples/):** Recipes for image processing, Zarr export, Dask, plates and parallel workers.
243
+
244
+ ## Used by
245
+
246
+ - **[EuBI-Bridge](https://github.com/Euro-BioImaging/EuBI-Bridge)** converts microscopy files to OME-Zarr and uses micro-reader as its default reader for supported formats.
247
+ - **[dyna-zarr](https://pypi.org/project/dyna-zarr/)** uses `micro_reader.Image` as a lazy data source for writing Zarr arrays.
248
+
249
+ ## Feedback
250
+
251
+ Bug reports, requests for additional formats and sample files are welcome on [GitHub](https://github.com/bugraoezdemir/micro-reader/issues).
252
+
253
+ ### Development note
254
+
255
+ The project has been developed with substantial AI assistance. Its functionality is continuously tested against real datasets, but some issues or edge cases may remain undiscovered.
256
+
257
+ ## License
258
+
259
+ `micro-reader`, `micro-reader-codecs` and `micro-reader-core` are MIT licensed. The wheels of the two native packages include third-party libraries. Their notices are available in [`codecs/THIRD_PARTY_LICENSES.txt`](https://github.com/bugraoezdemir/micro-reader/blob/main/codecs/THIRD_PARTY_LICENSES.txt) and [`core/THIRD_PARTY_LICENSES.txt`](https://github.com/bugraoezdemir/micro-reader/blob/main/core/THIRD_PARTY_LICENSES.txt).
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "micro-reader"
9
- version = "0.4.4"
9
+ version = "0.5.0"
10
10
  description = "Low-level, memory-bounded pixel reading for microscopy formats: read exactly the rectangle you ask for."
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.11"
@@ -29,7 +29,8 @@ classifiers = [
29
29
  # TIFF covers most microscopy images, so it is not an extra (Bugra,
30
30
  # 2026-10-01) until micro-reader parses TIFF itself (post-0.0.1). The floor
31
31
  # matches eubi-bridge's (tifffile>=2025.5.21), so both install together.
32
- dependencies = ["numpy>=1.24", "micro-reader-codecs>=0.0.4,<0.1", "tifffile>=2025.5.21"]
32
+ dependencies = ["numpy>=1.24", "micro-reader-codecs>=0.0.4,<0.1", "micro-reader-core>=0.0.1,<0.1",
33
+ "tifffile>=2025.5.21"]
33
34
 
34
35
  [project.urls]
35
36
  Homepage = "https://github.com/bugraoezdemir/micro-reader"
@@ -19,10 +19,11 @@ from ._io import cache_limit, cached_bytes, set_cache_limit
19
19
  from ._pool import decode_threads, set_decode_threads
20
20
  from ._registry import BACKENDS, open # noqa: A004 - the public entry point
21
21
  from ._groups import FileGroup, Grouping, group_files
22
+ from ._many import read_many
22
23
  from .backends.czi import DamagedFileWarning
23
24
 
24
25
  __all__ = [
25
- "open", "group_files", "FileGroup", "Grouping", "File", "Image", "INDEX_NAMES", "PLATE_INDICES", "SAMPLED_INDICES", "ReadStats",
26
+ "open", "read_many", "group_files", "FileGroup", "Grouping", "File", "Image", "INDEX_NAMES", "PLATE_INDICES", "SAMPLED_INDICES", "ReadStats",
26
27
  "BACKENDS", "Metadata", "Channel", "Quantity", "Plate", "Well", "Field", "Acquisition",
27
28
  "Axis", "CoordinateSystem", "Transformation", "Collection",
28
29
  "decode_threads", "set_decode_threads", "memory_limit", "set_memory_limit",