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)

Demo 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()