iivs-lib
A Python toolkit for multi-modal holographic systems and cellular analysis.
📦 Installation
Requires Python 3.13 or newer.
# With uv (recommended)
uv add iivs-lib
# With pip
pip install iivs-lib
Image I/O ships by default: imagecodecs (to decode the LZW-compressed Koala
Image/*.tif uint8 previews) is a core dependency — handling image-like
microscope data is this library's primary job. The only extra is [torch],
which adds PyTorch for iivs.dhm.analysis.pytorch — tensor-in / tensor-out
OPD / dry-mass twins with autograd (uv add "iivs-lib[torch]").
🚀 Quick start
from iivs.dhm.data.phase import PhaseBinFolder, PhaseUnit
from iivs.dhm.analysis import calc_drymass
# Lazily open a phase acquisition (a folder of numbered .bin frames).
phase = PhaseBinFolder("scan/Phase/Float/Bin", target_unit=PhaseUnit.RADIANS)
phase.frame_shape # (H, W), shared across frames
img = phase[0] # first frame as a float32 array (decoded on access)
# Per-frame dry mass over a segmented cell:
mass_pg = calc_drymass(
img, pixel_size=phase.header.pixel_size, mask=cell_mask
)
🧩 Modules
Each package ships a detailed README in the source tree — the endpoints,
examples, and the inherited sequence interface:
hologram,
phase,
intensity,
data (overview
and timestamp),
analysis.
iivs.dhm.data
Readers, writers, and lazy sequences for Lyncée Tec Koala acquisition data (validated end-to-end against a real Koala acquisition — every format, the sequences, and the round trips between them).
hologram— uint8 holograms:.tifviaload_hologram_tif/save_hologram_tifwithHologramTifFolder/HologramTifList; a single multi-frame.rawviaHologramRawFile(a lazynp.memmap),read_hologram_raw_header/save_hologram_raw; header-less.npyframes viaHologramNpyFolder.phase— float32.binphase images:load_phase_bin/save_phase_bin/read_phase_bin_header, the typedPhaseBinHeaderandPhaseUnit, andconvert_phase_unit; folder/list sequencesPhaseBinFolder/PhaseBinList. The same quantitative phase from Koala'sFloat/Txtexport viaload_phase_txt,PhaseTxtFolder/PhaseTxtList. The uint8Image/*.tifdisplay previews (not quantitative) viaPhaseTifFolder/PhaseTifList. Header-less.npyframes viaPhaseNpyFolder(pixel_size/unit/height_scalepassed to the constructor;numpy.load, pickle disabled).intensity— float32.binintensity reconstructions (exported alongside phase):load_intensity_bin/save_intensity_bin/read_intensity_bin_header, the typedIntensityBinHeader, and folder/list sequencesIntensityBinFolder/IntensityBinList; plus theFloat/Txttwinsload_intensity_txt,IntensityTxtFolder/IntensityTxtList, the uint8Image/*.tifpreviewsIntensityTifFolder/IntensityTifList, and header-less.npyframes viaIntensityNpyFolder(pixel_sizepassed in). The phase and intensity.binformats share thecommon.KoalaBinHeaderbase.timestamp— per-frame acquisition timing: theTimestamprecord,TimestampsTxtFile(Koalatimestamps.txt), andTimestampsFixedFPS(synthesized from a frame rate).
phase and intensity also expose suffix-dispatch entry points that pick
the format by a path's extension — load_phase / read_phase_header /
save_phase, phase_list / phase_folder (and the intensity twins) — plus
save_phase_folder / save_intensity_folder to write any (e.g. a kaparoo-
composed) image sequence to a numbered folder. load_phase / load_intensity
take return_header (the header is None for the header-less .npy).
A timelapse module opens a whole Koala acquisition from its root folder:
KoalaTimelapse composes the per-modality PhaseGroup / IntensityGroup (each
picking its Float/{Bin,Txt} format), the holograms, timestamps.txt, and
phbounds.txt display bounds, with lazy access, frame-count consistency checks
(is_consistent), and content validate. search_timelapses finds every
acquisition under a root; KOALA_TIMELAPSE_TREE describes the layout for
hierarchy.validate.
Every sequence is a kaparoo.data.sequences.DataSequence, so it indexes,
slices, and iterates lazily; same-shape sources also expose frame_shape by
mixing in iivs.common.data.FrameShapedMixin (so a uniform source is its
<Modality>FloatSequence / <Modality>ImageSequence plus that mixin). For
phase and intensity the quantitative float32 sources are
<Modality>FloatSequence and the uint8 Image/*.tif previews are
<Modality>ImageSequence, both under the <Modality>Sequence base.
Numbered-folder sequences share the KoalaFrameFolder discovery/validation
base in iivs.dhm.data.koala, and validate their arrays via iivs.common.data's
validate_float32_array / validate_uint8_array.
iivs.dhm.analysis
Physical quantities derived from phase, each via an engine object that precomputes its conversion factor (with one-shot function conveniences):
opd— optical path difference (OPD = phase * wavelength / (2*pi), in nm).OPDConverter(convert_from_phase/convert_to_phase, scaleopd_scale);phase_to_opd/opd_to_phase.height— optical height (height = phase * wavelength / (2*pi * refractive_delta), in nm; the sample thickness of the QPI literature).OpticalHeightConverter(scaleheight_scale; OPD enters through phase);phase_to_height/height_to_phase/opd_to_height/height_to_opd.area— projected area (pixel_count * pixel_size^2, in um^2) of the masked footprint on an image's grid; the image's values never enter.ProjectedAreaCalculator(scalearea_scale);calc_projected_area.volume— optical volume (sum(height * pixel_area), in um^3 = fL; equivalentlyprojected_area * mean(height)).OpticalVolumeCalculator(calccanonical,calc_from_opd/calc_from_heightenter through phase; scalevolume_scale, um^3 per rad);calc_optical_volume(phase) /calc_optical_volume_from_opd/calc_optical_volume_from_height.drymass— dry mass (pg) via the Barer relation.DryMassCalculator(calccanonical,calc_from_opd/calc_from_heightenter through phase, over a background-corrected map, optionally masked by a boolean or integer-label region; scaledrymass_scale, pg per rad);calc_drymass(phase) /calc_drymass_from_opd/calc_drymass_from_heightare the one-shots.
The wavelength and alpha defaults come from
iivs.dhm.constants, the lab's microscope settings —
shared by analysis and data, and belonging to neither. Override per experiment
when the setup differs.
Using with PyTorch (autograd)
The convert_* / calc_* methods operate on NumPy arrays. Install the
iivs-lib[torch] extra for iivs.dhm.analysis.pytorch — tensor-in / tensor-out
twins that keep the input tensor's device, dtype, and autograd graph (the
calibration scalars are shared with the NumPy engines). The Torch
OpticalPathDifference / DryMass are pure pointwise nn.Modules (so they fit
nn.Sequential / torch.compile); masking and reduction are the separate
iivs.common.data.pytorch reductions, which the calc_* one-shots compose:
from iivs.dhm.analysis.pytorch.opd import phase_to_opd
from iivs.dhm.analysis.pytorch.drymass import calc_drymass
opd = phase_to_opd(phase, wavelength=666e-9) # Tensor (CPU/GPU), grad kept
mass = calc_drymass(phase, pixel_size=px, mask=cell) # Tensor, grad kept
Or, without the dependency, multiply by the cached scale factors (plain floats) with native ops yourself:
opd = phase * conv.opd_scale # phase: Tensor -> OPD (nm), grad kept
mass = opd[mask].sum() * calc.drymass_scale # OPD -> dry mass (pg), grad kept
iivs.common.data
Technique-agnostic data primitives — nothing here knows what a hologram is, so a
future technique can build on them without importing dhm.
ArrayFileList[U]— the dtype-generic base every file-backed sequence extends, withFrameShapedMixinmarking the same-shape sources andValueRangeMixinadding a cachedvalue_range()over all frames.load_float32_npy/save_float32_npyand theuint8pair, plusread_npy_shape/write_npy— header-less.npyI/O, keyed by dtype (which is all that varies) rather than by modality. Pickle is disabled, so an object array cannot be written and one written elsewhere is refused rather than unpickled.validate_float32_array/validate_uint8_arrayand their widerfloat/uintforms — dtype + shape + non-finite checks, withon_nonfinite("ignore"/"warn"/"raise") the policy every loader and saver in the library threads through.Sum/Mean/Norm/Variance/Std— masked region reductions: reduce a(..., H, W)map over the regions of a mask (a boolean image or stack, or an integer label image; regions may overlap), withregion_stack/apply_maskthe shared primitives. A Torch twin iniivs.common.data.pytorchmirrors them as autograd-friendlynn.Modules.Timestamp/TimestampSequence/TimestampsFixedFPS— per-frame timing, which any time-lapse acquisition has; the Koalatimestamps.txtreader implements this interface fromdhm.
iivs.common.visualization
Technique-agnostic display helpers, shared across every modality.
auto_rescale— ImageJ-style auto-contrast (Enhance Contrast + Normalize): clipssaturated% of pixels via NaN-safe percentile bounds, stretches ontoout_range(or the dtype's full span), and casts back to the input dtype. Works on any numeric image or stack, so phase / intensity / hologram share it.
📋 TODO
See TODO.md for tracked open items.
📜 Changelog
See CHANGELOG.md for the version history.
🙏 Acknowledgements
The file formats read and written by iivs.dhm.data are
Lyncée Tec's proprietary Koala formats. The .bin
format — Koala's float32 binary container, shared by the phase and intensity
reconstructions — was cross-checked against their reference implementation,
pyKoalaUtils (MIT). iivs-lib is
an independent reimplementation and contains no code from it.
⚖️ License
This project is distributed under the terms of the MIT license.
Metadata
Release files for iivs-lib 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iivs_lib-0.5.0.tar.gz | 97.7 kB | With provenance | Details for iivs_lib-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iivs_lib-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for iivs_lib-0.5.0-py3-none-any.whl |
Total release size: 239.3 kB
Release files / iivs_lib-0.5.0.tar.gz
| Download URL | iivs_lib-0.5.0.tar.gz |
|---|---|
| Size | 97.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f9665266205a196f251a7b570ed36b5f7def0929ac73f75637f22ccfca9bb19
|
|
BLAKE2b-256 checksum How to use checksums |
ccff9cd85229fc0d59154b412760efdef69b1904c3b0e1bc755bbd3b41f4c60d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency logRelease files / iivs_lib-0.5.0-py3-none-any.whl
| Download URL | iivs_lib-0.5.0-py3-none-any.whl |
|---|---|
| Size | 141.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfcb1d0e5e9c5a4f0138c5587727e23adaa89edc6381e558109e949fbf123f08
|
|
BLAKE2b-256 checksum How to use checksums |
c499a97ce0881ac76e41324b4878485c3e4e7a90180149e059535ddeb580135c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency logSecurity for iivs-lib 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for iivs_lib-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.