micro-reader 0.4.2__tar.gz → 0.4.4__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 (74) hide show
  1. {micro_reader-0.4.2 → micro_reader-0.4.4}/PKG-INFO +24 -2
  2. {micro_reader-0.4.2 → micro_reader-0.4.4}/README.md +22 -0
  3. {micro_reader-0.4.2 → micro_reader-0.4.4}/pyproject.toml +2 -2
  4. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_codecs.py +24 -10
  5. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_version.py +1 -1
  6. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/czi.py +39 -7
  7. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/tiff.py +39 -1
  8. {micro_reader-0.4.2 → micro_reader-0.4.4}/.gitignore +0 -0
  9. {micro_reader-0.4.2 → micro_reader-0.4.4}/LICENSE +0 -0
  10. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/__init__.py +0 -0
  11. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_axes.py +0 -0
  12. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_base.py +0 -0
  13. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_cfb.py +0 -0
  14. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_errors.py +0 -0
  15. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_eubi_guard.py +0 -0
  16. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_fileset.py +0 -0
  17. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_groups.py +0 -0
  18. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_index.py +0 -0
  19. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_io.py +0 -0
  20. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_jpeg_restarts.py +0 -0
  21. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_lambda.py +0 -0
  22. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_memory.py +0 -0
  23. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_metadata.py +0 -0
  24. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_mosaic.py +0 -0
  25. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_naming.py +0 -0
  26. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_outline.py +0 -0
  27. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_parts.py +0 -0
  28. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_plate.py +0 -0
  29. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_pool.py +0 -0
  30. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_registry.py +0 -0
  31. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_spatial.py +0 -0
  32. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_stack.py +0 -0
  33. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/_stream.py +0 -0
  34. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/__init__.py +0 -0
  35. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_czi_metadata.py +0 -0
  36. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_ets.py +0 -0
  37. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_hdf5.py +0 -0
  38. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_lif_metadata.py +0 -0
  39. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_nd2_legacy.py +0 -0
  40. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_nd2_metadata.py +0 -0
  41. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_nd2_run.py +0 -0
  42. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_nd2_structure.py +0 -0
  43. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_tiff_metadata.py +0 -0
  44. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_tiff_variants.py +0 -0
  45. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/_vsi_tree.py +0 -0
  46. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/bdv.py +0 -0
  47. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/cellomics.py +0 -0
  48. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/columbus.py +0 -0
  49. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/companion.py +0 -0
  50. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/cv7000.py +0 -0
  51. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/dv.py +0 -0
  52. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/flex.py +0 -0
  53. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/harmony.py +0 -0
  54. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/hdf5.py +0 -0
  55. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/ics.py +0 -0
  56. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/ilastik.py +0 -0
  57. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/ims.py +0 -0
  58. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/incell.py +0 -0
  59. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/jdce.py +0 -0
  60. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/klb.py +0 -0
  61. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/lif.py +0 -0
  62. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/luxendo.py +0 -0
  63. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/metamorph.py +0 -0
  64. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/metaxpress.py +0 -0
  65. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/micromanager.py +0 -0
  66. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/mrc.py +0 -0
  67. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/nd2.py +0 -0
  68. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/ndpis.py +0 -0
  69. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/oif.py +0 -0
  70. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/oir.py +0 -0
  71. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/omp2info.py +0 -0
  72. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/raster.py +0 -0
  73. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/scanr.py +0 -0
  74. {micro_reader-0.4.2 → micro_reader-0.4.4}/src/micro_reader/backends/vsi.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: micro-reader
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Low-level, memory-bounded pixel reading for microscopy formats: read exactly the rectangle you ask for.
5
5
  Project-URL: Homepage, https://github.com/bugraoezdemir/micro-reader
6
6
  Project-URL: Source, https://github.com/bugraoezdemir/micro-reader
@@ -18,7 +18,7 @@ Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Programming Language :: Python :: 3.14
19
19
  Classifier: Topic :: Scientific/Engineering :: Image Processing
20
20
  Requires-Python: >=3.11
21
- Requires-Dist: micro-reader-codecs<0.1,>=0.0.3
21
+ Requires-Dist: micro-reader-codecs<0.1,>=0.0.4
22
22
  Requires-Dist: numpy>=1.24
23
23
  Requires-Dist: tifffile>=2025.5.21
24
24
  Provides-Extra: all
@@ -862,6 +862,28 @@ export MICRO_READER_DECODE_THREADS=4
862
862
 
863
863
  The native codec implementations are provided by the separate Rust package `micro-reader-codecs`, which is installed automatically.
864
864
 
865
+ ### Benchmarks
866
+
867
+ Measured with micro-reader 0.4.3 on a laptop (Intel Core Ultra 7 255H, 16 cores, 31 GB RAM, NVMe SSD, Windows 11), on an otherwise idle machine, files in the OS file cache, default settings (16 decoding threads). Each number is the median of three runs, each in a fresh process. A 512 × 512 region is the median over 100 random regions at full resolution. Peak memory is the process's peak memory above its level after opening the file, during the read, including the returned array.
868
+
869
+ | File | File size | Read | Time | Peak memory |
870
+ | --- | ---: | --- | ---: | ---: |
871
+ | Hamamatsu NDPI slide (JPEG) | 198 MB | 512 × 512 RGB region | 4.0 ms | |
872
+ | | | 8192 × 8192 RGB region (192 MB) | 0.39 s | 377 MB |
873
+ | Aperio SVS slide (JPEG) | 596 MB | 512 × 512 RGB region | 1.5 ms | |
874
+ | | | 8192 × 8192 RGB region (192 MB) | 0.21 s | 380 MB |
875
+ | Zeiss CZI slide scan (JPEG XR, 6,093 tiles) | 3.6 GB | 512 × 512 RGB region | 28 ms | |
876
+ | | | 8192 × 8192 RGB region (192 MB) | 0.50 s | 376 MB |
877
+ | Zeiss CZI fluorescence mosaic (5 × 9 tiles per well) | 738 MB | 512 × 512 region | 0.15 ms | |
878
+ | | | one channel of a well: 2 t × 4 z of 3444 × 2944 (77 MB) | 0.02 s | 78 MB |
879
+ | Micro-Manager OME-TIFF | 435 MB | 512 × 512 region | 0.49 ms | |
880
+ | | | one channel: 28 t of 1608 × 1608 (138 MB) | 0.01 s | 139 MB |
881
+ | Nikon ND2, 46 XY points | 395 MB | the whole file: 46 points × 31 t × 2 c (362 MB) | 0.10 s | 357 MB |
882
+ | Imaris IMS (gzip chunks) | 452 MB | one channel: 312 z of 512 × 512 (78 MB) | 0.03 s | 153 MB |
883
+ | CellVoyager CV8000 plate: 384 wells, 2,304 fields, 18,452 files | 35 GB | open | 0.67 s | |
884
+
885
+ JPEG XR regions cost the most: the tiles of this scan are 1600 × 1200 and can only be decoded whole, so a small region costs one to four whole-tile decodes, which run in parallel. Numbers vary with hardware, storage and whether the file is already in the OS cache.
886
+
865
887
  ## Memory usage
866
888
 
867
889
  Memory usage is controlled by a configurable limit:
@@ -808,6 +808,28 @@ export MICRO_READER_DECODE_THREADS=4
808
808
 
809
809
  The native codec implementations are provided by the separate Rust package `micro-reader-codecs`, which is installed automatically.
810
810
 
811
+ ### Benchmarks
812
+
813
+ Measured with micro-reader 0.4.3 on a laptop (Intel Core Ultra 7 255H, 16 cores, 31 GB RAM, NVMe SSD, Windows 11), on an otherwise idle machine, files in the OS file cache, default settings (16 decoding threads). Each number is the median of three runs, each in a fresh process. A 512 × 512 region is the median over 100 random regions at full resolution. Peak memory is the process's peak memory above its level after opening the file, during the read, including the returned array.
814
+
815
+ | File | File size | Read | Time | Peak memory |
816
+ | --- | ---: | --- | ---: | ---: |
817
+ | Hamamatsu NDPI slide (JPEG) | 198 MB | 512 × 512 RGB region | 4.0 ms | |
818
+ | | | 8192 × 8192 RGB region (192 MB) | 0.39 s | 377 MB |
819
+ | Aperio SVS slide (JPEG) | 596 MB | 512 × 512 RGB region | 1.5 ms | |
820
+ | | | 8192 × 8192 RGB region (192 MB) | 0.21 s | 380 MB |
821
+ | Zeiss CZI slide scan (JPEG XR, 6,093 tiles) | 3.6 GB | 512 × 512 RGB region | 28 ms | |
822
+ | | | 8192 × 8192 RGB region (192 MB) | 0.50 s | 376 MB |
823
+ | Zeiss CZI fluorescence mosaic (5 × 9 tiles per well) | 738 MB | 512 × 512 region | 0.15 ms | |
824
+ | | | one channel of a well: 2 t × 4 z of 3444 × 2944 (77 MB) | 0.02 s | 78 MB |
825
+ | Micro-Manager OME-TIFF | 435 MB | 512 × 512 region | 0.49 ms | |
826
+ | | | one channel: 28 t of 1608 × 1608 (138 MB) | 0.01 s | 139 MB |
827
+ | Nikon ND2, 46 XY points | 395 MB | the whole file: 46 points × 31 t × 2 c (362 MB) | 0.10 s | 357 MB |
828
+ | Imaris IMS (gzip chunks) | 452 MB | one channel: 312 z of 512 × 512 (78 MB) | 0.03 s | 153 MB |
829
+ | CellVoyager CV8000 plate: 384 wells, 2,304 fields, 18,452 files | 35 GB | open | 0.67 s | |
830
+
831
+ JPEG XR regions cost the most: the tiles of this scan are 1600 × 1200 and can only be decoded whole, so a small region costs one to four whole-tile decodes, which run in parallel. Numbers vary with hardware, storage and whether the file is already in the OS cache.
832
+
811
833
  ## Memory usage
812
834
 
813
835
  Memory usage is controlled by a configurable limit:
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "micro-reader"
9
- version = "0.4.2"
9
+ version = "0.4.4"
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,7 @@ 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.3,<0.1", "tifffile>=2025.5.21"]
32
+ dependencies = ["numpy>=1.24", "micro-reader-codecs>=0.0.4,<0.1", "tifffile>=2025.5.21"]
33
33
 
34
34
  [project.urls]
35
35
  Homepage = "https://github.com/bugraoezdemir/micro-reader"
@@ -415,22 +415,36 @@ def jxl_decode_into(data, out: np.ndarray, *, native: bool | None = None):
415
415
  image.dtype.itemsize * 8)
416
416
 
417
417
 
418
- def jpegxr_decode_into(data, out: np.ndarray, *, native: bool | None = None):
418
+ def jpegxr_decode_into(data, out: np.ndarray, *, bgr: bool = False,
419
+ native: bool | None = None):
419
420
  """A JPEG XR codestream -> *out* (colour R, G, B; fixed point as float32).
420
421
  micro-reader-codecs 0.0.3 on decodes it with jxrlib, as imagecodecs does and
421
- with the same pixel-format conversions; imagecodecs otherwise."""
422
+ with the same pixel-format conversions; imagecodecs otherwise.
423
+
424
+ *bgr*: colour comes out B, G, R(, A) instead (what a CZI tile stores).
425
+ micro-reader-codecs 0.0.4 on writes 8-bit B, G, R codestreams (Zeiss tiles) as
426
+ stored, skipping jxrlib's conversion pass; other sources are swapped in *out*."""
427
+ order = "rgb"
422
428
  if _use_native(native, "jpegxr_decode_into"):
429
+ flat = memoryview(out).cast("B")
423
430
  try:
424
- _native.jpegxr_decode_into(data, memoryview(out).cast("B"))
425
- return
431
+ try:
432
+ info = _native.jpegxr_decode_into(data, flat, bgr=bgr) if bgr else \
433
+ _native.jpegxr_decode_into(data, flat)
434
+ except TypeError: # micro-reader-codecs 0.0.3: no bgr
435
+ info = _native.jpegxr_decode_into(data, flat)
426
436
  except ValueError as exc:
427
437
  raise CorruptFileError(f"corrupt JPEG XR data: {exc}") from exc
428
- codecs = _imagecodecs("JPEG XR data", native_from="0.0.3")
429
- try:
430
- image = codecs.jpegxr_decode(bytes(data))
431
- except Exception as exc: # noqa: BLE001
432
- raise CorruptFileError(f"corrupt JPEG XR data: {exc}") from exc
433
- _fill(out, image, "JPEG XR")
438
+ order = info[5] if len(info) > 5 else "rgb"
439
+ else:
440
+ codecs = _imagecodecs("JPEG XR data", native_from="0.0.3")
441
+ try:
442
+ image = codecs.jpegxr_decode(bytes(data))
443
+ except Exception as exc: # noqa: BLE001
444
+ raise CorruptFileError(f"corrupt JPEG XR data: {exc}") from exc
445
+ _fill(out, image, "JPEG XR")
446
+ if bgr and order != "bgr" and out.ndim >= 3 and out.shape[-1] in (3, 4):
447
+ out[..., [0, 2]] = out[..., [2, 0]] # R, G, B -> B, G, R in place
434
448
 
435
449
 
436
450
  def eer_decode_into(data, out: np.ndarray, skipbits: int, horzbits: int, vertbits: int,
@@ -1,2 +1,2 @@
1
1
  """micro-reader's version, in one place (the package, the import guard)."""
2
- __version__ = "0.4.2"
2
+ __version__ = "0.4.4"
@@ -544,15 +544,18 @@ class _CziImage(Image):
544
544
 
545
545
  def _image_codec(self, s: Subblock, data: bytes, tile) -> None:
546
546
  """JPEG, JPEG lossless, JPEG XR, JPEG XL: they give R, G, B; stored
547
- into *tile* in the file's B, G, R order like every other codec."""
547
+ into *tile* in the file's B, G, R order like every other codec. JPEG XR
548
+ decodes straight into *tile* in that order (Zeiss tiles store B, G, R: no
549
+ conversion and no copy; a 1600 x 1200 tile spent ~10 ms of ~40 on them)."""
550
+ if s.compression == JPEG_XR:
551
+ view = tile.reshape(s.height, s.width, self._samples) # *tile* is contiguous
552
+ _codecs.jpegxr_decode_into(data, view, bgr=self._samples > 1)
553
+ return
548
554
  decoded = np.empty((s.height, s.width, self._samples), self._file_dtype)
549
555
  if s.compression in (JPEG, JPEG_LOSSLESS):
550
556
  width, height, samples, bits = _codecs.jpeg_decode_into(data, decoded)
551
- elif s.compression == JPEG_XL:
557
+ else: # JPEG_XL
552
558
  width, height, samples, bits = _codecs.jxl_decode_into(data, decoded)
553
- else: # JPEG_XR
554
- _codecs.jpegxr_decode_into(data, decoded)
555
- width, height, samples = s.width, s.height, self._samples
556
559
  if (width, height, samples) != (s.width, s.height, self._samples):
557
560
  raise CorruptFileError(
558
561
  f"{self._czi.path!r}: subblock codestream is {width} x {height} x {samples}, "
@@ -781,6 +784,33 @@ class _CziImage(Image):
781
784
  read += self._draw(s, piece, y0, xs, dst)
782
785
  return read
783
786
 
787
+ def _predecode(self, bands, xs) -> int:
788
+ """A read with fewer row bands than tiles to decode whole (a viewer's
789
+ 512 x 512 region of a slide scan: one band, 1-4 JPEG XR tiles) would decode
790
+ them one after another inside its band: decode them on the pool first, into
791
+ the decode cache, and the bands only compose. Only what the cache can keep
792
+ (half its limit), so larger reads stay band by band; the pixels decoded."""
793
+ if _pool.decode_threads() < 2:
794
+ return 0
795
+ from .. import _io
796
+ cache = self._czi.decode_cache
797
+ want, total = {}, 0
798
+ for tiles, b0, b1 in bands:
799
+ region = (b0, b1, xs.start, xs.stop)
800
+ for i in tiles.query(region):
801
+ s = tiles.subblocks[i]
802
+ if s.compression == UNCOMPRESSED or s.position in want:
803
+ continue
804
+ nbytes = s.height * s.width * self._samples * self._file_dtype.itemsize
805
+ if _memory.should_stream(nbytes) or nbytes > cache.max_bytes // 4 \
806
+ or not tiles.visible(i, region) or cache.get(s.position) is not None:
807
+ continue
808
+ want[s.position] = s
809
+ total += nbytes
810
+ if len(want) <= len(bands) or total > _io.cache_limit() // 2:
811
+ return 0
812
+ return _pool.run([lambda s=s: self._decoded(s)[1] for s in want.values()])
813
+
784
814
  def _read_block(self, block):
785
815
  if self._closed:
786
816
  raise ValueError("this CZI image has been closed: its file was closed "
@@ -792,7 +822,7 @@ class _CziImage(Image):
792
822
  + ((self._samples,) if ss is not None else ()), dtype=self.dtype)
793
823
  row_bytes = max(1, (xs.stop - xs.start) * self._samples * self._file_dtype.itemsize)
794
824
  per_task = max(1, RAW_TASK_BYTES // row_bytes)
795
- tasks = []
825
+ tasks, bands = [], []
796
826
  for key in itertools.product(*(range(s.start, s.stop) for s in plane_spans)):
797
827
  tiles = self._planes.get(key)
798
828
  if tiles is None:
@@ -802,8 +832,10 @@ class _CziImage(Image):
802
832
  for b0 in range(ys.start, ys.stop, rows_per_task):
803
833
  b1 = min(ys.stop, b0 + rows_per_task)
804
834
  part = dst[b0 - ys.start:b1 - ys.start]
835
+ bands.append((tiles, b0, b1))
805
836
  tasks.append(lambda a=(tiles, b0, b1, xs, part): self._draw_band(*a))
806
- read = _pool.run(tasks)
837
+ read = self._predecode(bands, xs)
838
+ read += _pool.run(tasks)
807
839
  if ss is not None and (ss.start, ss.stop) != (0, self._samples):
808
840
  out = out[..., ss]
809
841
  return out, read
@@ -1433,6 +1433,44 @@ def open_pages(path: str) -> _TiffFile:
1433
1433
  return pages_file(tif, path)
1434
1434
 
1435
1435
 
1436
+ def _imagej_stopped_early(tif, series: list) -> list:
1437
+ """The ImageJ series of a file holding fewer planes than its metadata names (an
1438
+ acquisition stopped early: ScanImage, 3 of 24 frames).
1439
+
1440
+ tifffile 2026.11.12 and later drop such a series and list the pages as one generic
1441
+ series, so its planes would read as separate images without their axes; earlier
1442
+ versions kept the shape the metadata names. micro-reader rebuilds that shape, so
1443
+ the file reads the same with any tifffile: the missing planes as zeros, with a
1444
+ MissingImagesWarning (``_SeriesImage``). Only ImageJ's own plane order (czt) with
1445
+ one sample per pixel or RGB is rebuilt; anything else stays as tifffile lists it.
1446
+ """
1447
+ if not tif.is_imagej or len(series) != 1 or series[0].kind != "generic":
1448
+ return series
1449
+ meta = tif.imagej_metadata or {}
1450
+ if str(meta.get("order", "czt")).lower() not in ("czt", "default"):
1451
+ return series
1452
+ try:
1453
+ frames, slices, channels, images = (int(meta.get(k, 1)) for k in
1454
+ ("frames", "slices", "channels", "images"))
1455
+ except (TypeError, ValueError):
1456
+ return series
1457
+ pages = list(series[0].pages)
1458
+ page = pages[0] if pages else None
1459
+ if page is None or min(frames, slices, channels) < 1 or page.shaped[0] > 1:
1460
+ return series
1461
+ if channels > 1 and images == frames * slices and page.shaped[4] == channels:
1462
+ channels = 1 # RGB declared as channels
1463
+ lead = (frames, slices, channels)
1464
+ if int(np.prod(lead, dtype=np.int64)) <= len(pages):
1465
+ return series # not a stopped acquisition
1466
+ # squeezed as tifffile lists its series (size-1 axes dropped, Y and X kept)
1467
+ dims = [(n, a) for n, a in zip(lead + tuple(page.shape), "TZC" + page.axes)
1468
+ if n > 1 or a in "YX"]
1469
+ shape, axes = tuple(n for n, _ in dims), "".join(a for _, a in dims)
1470
+ return [type(series[0])(pages, shape, page.dtype, axes, parent=tif, # TiffPageSeries
1471
+ name=series[0].name, kind="imagej")]
1472
+
1473
+
1436
1474
  def plain_pages(tif) -> bool:
1437
1475
  """Whether tifffile already reads *tif* as plain pages (an OME ``BinaryOnly``
1438
1476
  stub has no image of its own, so tifffile lists its pages as they are)."""
@@ -1551,7 +1589,7 @@ def _open(tif, path, tiles, resolutions, rename, companion, multifile, plates=Fa
1551
1589
  f"{path!r}: PerkinElmer Opera Flex file (a TIFF with a FlexXML tag): the flex "
1552
1590
  "backend reads it as a plate when it is named .flex (micro_reader.open(path, "
1553
1591
  "backend='flex'))")
1554
- series = list(tif.series)
1592
+ series = _imagej_stopped_early(tif, list(tif.series))
1555
1593
  if tif.is_lsm:
1556
1594
  # Zeiss LSM stores a small RGB preview of every plane (reduced
1557
1595
  # pages); Bio-Formats does not list them, and neither does
File without changes
File without changes