micro-reader 0.4.0__tar.gz → 0.4.1__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.
- {micro_reader-0.4.0 → micro_reader-0.4.1}/PKG-INFO +1 -1
- {micro_reader-0.4.0 → micro_reader-0.4.1}/pyproject.toml +1 -1
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_version.py +1 -1
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/bdv.py +110 -5
- {micro_reader-0.4.0 → micro_reader-0.4.1}/.gitignore +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/LICENSE +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/README.md +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/__init__.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_axes.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_base.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_cfb.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_codecs.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_errors.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_eubi_guard.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_fileset.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_groups.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_index.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_io.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_jpeg_restarts.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_lambda.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_memory.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_mosaic.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_naming.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_outline.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_parts.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_plate.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_pool.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_registry.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_spatial.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_stack.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/_stream.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/__init__.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_czi_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_ets.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_hdf5.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_lif_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_nd2_legacy.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_nd2_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_nd2_run.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_nd2_structure.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_tiff_metadata.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_tiff_variants.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/_vsi_tree.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/cellomics.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/columbus.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/companion.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/cv7000.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/czi.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/dv.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/flex.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/harmony.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/hdf5.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/ics.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/ilastik.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/ims.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/incell.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/jdce.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/klb.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/lif.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/luxendo.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/metamorph.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/metaxpress.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/micromanager.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/mrc.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/nd2.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/ndpis.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/oif.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/oir.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/omp2info.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/raster.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/scanr.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/src/micro_reader/backends/tiff.py +0 -0
- {micro_reader-0.4.0 → micro_reader-0.4.1}/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.
|
|
3
|
+
Version: 0.4.1
|
|
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
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "micro-reader"
|
|
9
|
-
version = "0.4.
|
|
9
|
+
version = "0.4.1"
|
|
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"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""micro-reader's version, in one place (the package, the import guard)."""
|
|
2
|
-
__version__ = "0.4.
|
|
2
|
+
__version__ = "0.4.1"
|
|
@@ -21,7 +21,13 @@ HDF5::
|
|
|
21
21
|
|
|
22
22
|
Images: one per tile, angle and illumination (indices ``tile``, ``view``,
|
|
23
23
|
``illumination``, each only when it takes several values), its channels the
|
|
24
|
-
``c`` axis and its time points the ``t`` axis: ``tczyx``.
|
|
24
|
+
``c`` axis and its time points the ``t`` axis: ``tczyx``. With
|
|
25
|
+
``tiles="mosaic"`` the tiles of each angle and illumination are one image
|
|
26
|
+
(``_mosaic.Mosaic``): every level of the tiles placed on one canvas at their
|
|
27
|
+
nominal positions (below), a whole number of pixels from its corner, the later
|
|
28
|
+
tile on top where they overlap; nothing registered or blended. Tiles that
|
|
29
|
+
cannot be placed so (no position, positions apart along z, different pixel
|
|
30
|
+
sizes) are refused: read them with ``tiles="separate"``. Stored levels are
|
|
25
31
|
the image's ``resolutions``. BigDataViewer stores unsigned 16-bit pixels as
|
|
26
32
|
signed 16-bit HDF5 data; they are read as ``uint16``.
|
|
27
33
|
|
|
@@ -64,6 +70,7 @@ import numpy as np
|
|
|
64
70
|
|
|
65
71
|
from .. import _parts
|
|
66
72
|
from .._base import File, Image
|
|
73
|
+
from .._mosaic import Mosaic
|
|
67
74
|
from .._errors import (CompositeWarning, CorruptFileError, MissingImagesWarning,
|
|
68
75
|
UnsupportedFormatError)
|
|
69
76
|
from .._metadata import Channel, Metadata, Quantity, quantity
|
|
@@ -455,6 +462,106 @@ class _BdvImage(Image):
|
|
|
455
462
|
self._closed = True
|
|
456
463
|
|
|
457
464
|
|
|
465
|
+
class _BdvMosaic(Mosaic):
|
|
466
|
+
"""The tiles of one angle / illumination at one level on one canvas
|
|
467
|
+
(``tiles="mosaic"``); its metadata is the first tile's, placed at the canvas
|
|
468
|
+
corner."""
|
|
469
|
+
|
|
470
|
+
def __init__(self, position, tiles, name, index, corner: dict, members: set):
|
|
471
|
+
super().__init__(position, tiles, name, index)
|
|
472
|
+
self._corner = corner # axis -> Quantity of the canvas corner
|
|
473
|
+
self._members = members
|
|
474
|
+
self._own_name = None
|
|
475
|
+
|
|
476
|
+
def _read_metadata(self):
|
|
477
|
+
from dataclasses import replace
|
|
478
|
+
md = self._tiles[0][0].metadata
|
|
479
|
+
return replace(md, position={**md.position, **self._corner})
|
|
480
|
+
|
|
481
|
+
def _member_paths(self) -> set:
|
|
482
|
+
return set(self._members)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
class _PlacedViews:
|
|
486
|
+
"""The placement of a mosaic: its canvas corner, a position in ``GLOBAL``
|
|
487
|
+
and no edge (the tiles' registrations do not carry over to the canvas)."""
|
|
488
|
+
|
|
489
|
+
def __init__(self, position: dict):
|
|
490
|
+
self._placement = _Placement(position)
|
|
491
|
+
|
|
492
|
+
def placement(self) -> "_Placement":
|
|
493
|
+
return self._placement
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
def _mosaics(pyramids: list, where: str) -> list:
|
|
497
|
+
"""Each angle / illumination's tile pyramids as one pyramid of mosaics: every
|
|
498
|
+
level's tiles at their nominal positions (``_place``), in pixels of that level
|
|
499
|
+
from the canvas corner, rounded to whole pixels (as LIF tile scans are); drawn in
|
|
500
|
+
tile order, the later on top. Refused (UnsupportedFormatError, naming why) when a
|
|
501
|
+
tile has no position along y and x, the tiles lie apart along another axis (the
|
|
502
|
+
canvas is a y / x plane), or their pixel sizes or numbers of levels differ."""
|
|
503
|
+
groups: dict = {}
|
|
504
|
+
for pyramid in pyramids:
|
|
505
|
+
key = tuple((k, v) for k, v in pyramid[0].index.items() if k != "tile")
|
|
506
|
+
groups.setdefault(key, []).append(pyramid)
|
|
507
|
+
out = []
|
|
508
|
+
for key, members in groups.items():
|
|
509
|
+
members.sort(key=lambda pyramid: pyramid[0].index["tile"])
|
|
510
|
+
label = " ".join(f"{k} {v}" for k, v in key if k != "series")
|
|
511
|
+
what = f"{where}: tiles='mosaic'{f' ({label})' if label else ''}"
|
|
512
|
+
placed = [pyramid[0]._views.placement().position for pyramid in members]
|
|
513
|
+
if any(not {"x", "y"} <= set(position) for position in placed):
|
|
514
|
+
raise UnsupportedFormatError(
|
|
515
|
+
f"{what}: a tile has no position on the acquisition grid (its views turn, "
|
|
516
|
+
f"shear or mirror, or disagree): read the tiles with tiles='separate'")
|
|
517
|
+
for axis in sorted(set().union(*placed) - {"x", "y"}):
|
|
518
|
+
values = {round(position[axis].to(placed[0][axis].unit).value, 9)
|
|
519
|
+
for position in placed if axis in position}
|
|
520
|
+
if len(values) > 1 or any(axis not in position for position in placed):
|
|
521
|
+
raise UnsupportedFormatError(
|
|
522
|
+
f"{what}: the tiles lie apart along {axis} ({sorted(values)}); a mosaic "
|
|
523
|
+
f"places tiles in y and x only: read them with tiles='separate'")
|
|
524
|
+
sizes = [pyramid[0].metadata.pixel_sizes for pyramid in members]
|
|
525
|
+
unit = placed[0]["x"].unit
|
|
526
|
+
steps = []
|
|
527
|
+
for axis in "yx":
|
|
528
|
+
if any(axis not in size for size in sizes):
|
|
529
|
+
raise UnsupportedFormatError(f"{what}: a tile has no pixel size along {axis}")
|
|
530
|
+
values = {round(size[axis].to(unit).value, 12) for size in sizes}
|
|
531
|
+
if len(values) != 1:
|
|
532
|
+
raise UnsupportedFormatError(f"{what}: the tiles' pixel sizes along {axis} "
|
|
533
|
+
f"differ ({sorted(values)})")
|
|
534
|
+
steps.append(values.pop())
|
|
535
|
+
if len({len(pyramid) for pyramid in members}) != 1:
|
|
536
|
+
raise UnsupportedFormatError(f"{what}: the tiles store different numbers of "
|
|
537
|
+
f"levels {sorted({len(p) for p in members})}")
|
|
538
|
+
y0 = min(position["y"].to(unit).value for position in placed)
|
|
539
|
+
x0 = min(position["x"].to(unit).value for position in placed)
|
|
540
|
+
offsets = [((position["y"].to(unit).value - y0) / steps[0],
|
|
541
|
+
(position["x"].to(unit).value - x0) / steps[1]) for position in placed]
|
|
542
|
+
corner = {"y": Quantity(y0, unit), "x": Quantity(x0, unit)}
|
|
543
|
+
views = _PlacedViews({**placed[0], **corner})
|
|
544
|
+
files = set().union(*(pyramid[0]._member_paths() for pyramid in members))
|
|
545
|
+
mosaic_pyramid = []
|
|
546
|
+
for level in range(len(members[0])):
|
|
547
|
+
canvas = []
|
|
548
|
+
for pyramid, (dy, dx) in zip(members, offsets):
|
|
549
|
+
base, image = pyramid[0], pyramid[level]
|
|
550
|
+
fy = base.shape[-2] / image.shape[-2] # this level's downsampling
|
|
551
|
+
fx = base.shape[-1] / image.shape[-1]
|
|
552
|
+
canvas.append((image, round(dy / fy), round(dx / fx)))
|
|
553
|
+
first = members[0][level]
|
|
554
|
+
index = {k: v for k, v in first.index.items() if k != "tile"}
|
|
555
|
+
name = f"{where} {label}".strip()
|
|
556
|
+
mosaic = _BdvMosaic(0, canvas, name, index, corner, files)
|
|
557
|
+
mosaic._views = views
|
|
558
|
+
mosaic_pyramid.append(mosaic)
|
|
559
|
+
for mosaic in mosaic_pyramid:
|
|
560
|
+
mosaic._resolutions = mosaic_pyramid
|
|
561
|
+
out.append(mosaic_pyramid)
|
|
562
|
+
return out
|
|
563
|
+
|
|
564
|
+
|
|
458
565
|
def _pixel_type(datasets, declared: set, where: str):
|
|
459
566
|
"""(dtype the image has, view to apply to the stored values or None).
|
|
460
567
|
bdv-core (Hdf5ImageLoader): a setup group's ``dataType`` attribute names the
|
|
@@ -558,10 +665,6 @@ def _build(h5, path: str, xml: Optional[_Xml], resolutions: str, tiles: str,
|
|
|
558
665
|
else:
|
|
559
666
|
dims, index_names, ranks = ["sequence"], ["sequence"], {"sequence": [s.id for s in setups]}
|
|
560
667
|
groups = {(s.id,): [s] for s in setups}
|
|
561
|
-
if tiles == "mosaic" and "tile" in index_names:
|
|
562
|
-
raise UnsupportedFormatError(f"{where}: tiles='mosaic': micro-reader does not compose "
|
|
563
|
-
"BigDataViewer tiles (each tile is its own image)")
|
|
564
|
-
|
|
565
668
|
absent = []
|
|
566
669
|
images_by_level = []
|
|
567
670
|
for g, (gkey, group) in enumerate(sorted(groups.items())):
|
|
@@ -622,6 +725,8 @@ def _build(h5, path: str, xml: Optional[_Xml], resolutions: str, tiles: str,
|
|
|
622
725
|
image._resolutions = pyramid
|
|
623
726
|
image._own_name = own
|
|
624
727
|
images_by_level.append(pyramid)
|
|
728
|
+
if tiles == "mosaic" and "tile" in index_names and images_by_level:
|
|
729
|
+
images_by_level = _mosaics(images_by_level, where)
|
|
625
730
|
lost = getattr(xml, "missing_files", [])
|
|
626
731
|
lost_text = (f"; {len(lost)} of the partition files the XML lists are missing (e.g. "
|
|
627
732
|
f"{lost[0]!r})" if lost else "")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|