PyMIF โ Python code for users of the Mesoscopic Imaging Facility๏
PyMIF (source code here) is a modular Python package to read, visualize, and write multiscale (pyramidal) microscopy image data from a variety of microscope platforms available at the Mesoscopic Imaging Facility (MIF) into the OME-NGFF (Zarr) format.
๐ฆ Features๏
โ Read and parse image metadata from multiple microscope vendors and data formats:
Viventis (
.ome + .tif
)Luxendo (
.xml + .h5
)Opera PE (
.ome.tiff
)Zeiss (
.czi
)Generic OME-Zarr
Numpy or Dask array
โ Abstract base class
MicroscopeManager
ensures uniform interface for all readersโ Lazy loading via Dask for memory-efficient processing
โ Build pyramidal (multiscale) OME-Zarr archives from raw data or existing pyramids
โ Write OME-Zarr with:
Blosc or GZIP compression
Nested directory layout
Full NGFF + OMERO metadata (channel names, colors, scales, units)
Optional parallelization with
dask-distribute
โ Visualize pyramids in Napari using
napari-ome-zarr
plugin:Using lazy loading for fast visualization, or
Using in-memory loading of any resolution layer for interactivity.
โ Compatible with automated workflows and interactive exploration (Jupyter + scripts)
๐๏ธ Project Structure๏
pymif/
โโโ pymif
โ โโโ microscope_manager
โ โโโ luxendo_manager.py
โ โโโ viventis_manager.py
โ โโโ opera_manager.py
โ โโโ zeiss_manager.py
โ โโโ zarr_manager.py
โ โโโ array_manager.py
โ โโโ microscope_manager.py
โ โโโ utils/
โ โโโ pyramid.py
โ โโโ visualize.py
โ โโโ add_labels.py
โ โโโ write.py
โ
โโโ examples/
| โโโ example_luxendo.ipynb
| โโโ example_viventis.ipynb
| โโโ example_opera.ipynb
| โโโ example_zeiss.ipynb
| โโโ example_zarr.ipynb
โ โโโ example_array.ipynb
โ
โโโ tests/
โ โโโ ...
โ
โโโ requirements.txt
โโโ setup.py
โโโ README.md
๐ Getting Started๏
๐ฅ Installation๏
It is recommended to install pymif in a clean conda environment:
conda create -n pymif python=3.10
conda activate pymif
Installation is then done by cloning the repository:
git clone https://github.com/grinic/pymif.git
cd pymif
python -m pip install -e .
๐ Example Usage๏
With the following code, we read Viventis image data and parse the corresponding metadata. Next, we build a pyramidal structure of 3 resolution layers and save it into an OME-Zarr format. Finally, we load the new dataset and visualize it in napari.
import pymif.microscope_manager as mm
dataset = mm.ViventisManager("path/to/Position_1")
dataset.build_pyramid(num_levels=3)
dataset.write("output.zarr")
dataset_zarr = mm.ZarrManager("output.zarr")
viewer = dataset_zarr.visualize(start_level=0, in_memory=False)
Demonstration of pymif usage. Data: near newborn mouse embryo (~1.5 cm long). Fluorescence signal: methylene blue + autofluorescence. Sample processed and imaged by Montserrat Coll at the Mesoscopic Imaging Facility. Video speed: 2.5X real speed.
For more examples, see examples.
๐งช Running Tests๏
pytest tests/
โ Adding New Microscope Support and Contributing๏
Contributions/PRs are welcome! If you would like to help and add a new format:
Subclass MicroscopeManager
Implement read() returning:
Tuple[List[dask.array], Dict[str, Any]]
Follow this metadata schema:
{
"size": [... per level ...],
"scales": [... per level ...],
"units": (...),
"axes": "tczyx",
"channel_names": [...],
"channel_colors": [...],
"time_increment": ...,
"time_increment_unit": ...,
...
}
You will automatically inherit all MicroscopeManager
methods, including:
build_pyramid()
,write()
,visualize()
,reorder_channels()
,update_metadata()