# PyMIF โ€” Python code for users of the Mesoscopic Imaging Facility **PyMIF** (source code [here](https://github.com/grinic/pymif)) 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)](https://www.embl.org/groups/mesoscopic-imaging-facility/) into the [OME-NGFF (Zarr)](https://ngff.openmicroscopy.org/) 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: ```bash conda create -n pymif python=3.10 conda activate pymif ``` Installation is then done by cloning the repository: ```bash 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. ```python 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](../documentation/demo.gif) *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](https://github.com/grinic/pymif/tree/main/examples). ### ๐Ÿงช Running Tests ```bash 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: ```python Tuple[List[dask.array], Dict[str, Any]] ``` - Follow this metadata schema: ```python { "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()`