Skip to main content

Read and Write OME-TIFFs in Python

Project description

About

pyometiff is a Python library for reading and writing OME-TIFF files that are compliant with the OME-XML specifications.

pyometiff tries to cover most of the tags in the latest OMEXML format specification, while most of the available Python conversion tools are often missing key tags like PhysicalSizeXUnit which are fundamental in any microscopy environment.

Installation

Run the following to install:

pip install pyometiff

Usage

pyometiff exposes two main classes: OMETIFFReader and OMETIFFWriter which you can use to read and write OME TIFF files.

To open a OME-TIFF image you can create an OMETIFFReaderobject and call its .read() method.

import pathlib
from pyometiff import OMETIFFReader
img_fpath = pathlib.Path("/path/to/img.ome.tiff")

reader = OMETIFFReader(fpath=img_fpath)

img_array, metadata, xml_metadata = reader.read()

similarly, to write an OME-TIFF file, we use the OMETIFFWriter class and its .write() method as in the example.

import pathlib
from pyometiff import OMETIFFWriter
output_fpath = pathlib.Path.cwd().joinpath("test_out.ome.tiff")

# a template metadata dict is available at OMETIFFReader._get_metadata_template()

metadata_dict = {
    "PhysicalSizeX" : "0.88",
    "PhysicalSizeXUnit" : "µm",
    "PhysicalSizeY" : "0.88",
    "PhysicalSizeYUnit" : "µm",
    "PhysicalSizeZ" : "3.3",
    "PhysicalSizeZUnit" : "µm",
    "Channels" : {
        "405" : {
            "Name" : "405nm",
            "SamplesPerPixel": 1,
            "ExcitationWavelength": 405.,
            "ExcitationWavelengthUnit": "nm"
        },
        "488" : {
            "Name" : "488nm",
            "SamplesPerPixel": 1,
            "ExcitationWavelength": 488.,
            "ExcitationWavelengthUnit": "nm"
        },
        "638" : {
            "Name" : "638nm",
            "SamplesPerPixel": 1,
            "ExcitationWavelength": 638.,
            "ExcitationWavelengthUnit": "nm"
        },
    }

# our data in npy format
npy_array_data = np.array(shape=(2, 10, 3, 256, 256))
# a string describing the dimension ordering
dimension_order = "ZTCYX"

writer = OMETIFFWriter(
    fpath=output_fpath,
    dimension_order=dimension_order,
    array=npy_array_data,
    metadata=metadata,
    explicit_tiffdata=False)

writer.write()

Licensing

pyometiff is distributed under the GNU General Public License v3.0 (GNU GPLv3),

see the LICENSE file for more info.

This implementation is partially based on aicsimageio by the Allen Institute for Cell Science and python-bioformats by the Broad Institute, part of the CellProfiler project.

The relative licensing and copyright notices are included in the LICENSE file.

External Resources

Cite

DOI

Zenodo DOI: 10.5281/zenodo.7520378

@software{filippo_castelli_2024_10612149,
  author       = {Filippo Castelli and
                  Giacomo Mazzamuto},
  title        = {filippocastelli/pyometiff: 1.0.0},
  month        = feb,
  year         = 2024,
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.10612149},
  url          = {https://doi.org/10.5281/zenodo.10612149}
}

Contacts

Author:

Filippo Maria Castelli, PhD

filippocastelli42@gmail.com

[formerly] LENS, European Laboratory for Non-linear Spectroscopy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyometiff-1.0.1.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

pyometiff-1.0.1-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

Details for the file pyometiff-1.0.1.tar.gz.

File metadata

  • Download URL: pyometiff-1.0.1.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for pyometiff-1.0.1.tar.gz
Algorithm Hash digest
SHA256 517879948e62670009f171183065d4bc07269a24d306436bfe18007dd2e2429b
MD5 a498a612f37725b2e5b9bdaec7b025ab
BLAKE2b-256 7f29efc03addb26d3a26c6e5ed6117e64c536f69261dd4fa8cb45d57a6a37535

See more details on using hashes here.

File details

Details for the file pyometiff-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyometiff-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for pyometiff-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 15a60ef8c13cba9e9d3b29d16543276b13c5c6555709ddff3ed3979eaba2af1f
MD5 ca4ebcb4a76859c3ac3a5c47c908b875
BLAKE2b-256 10f8ad0b35488c656a7d4254bec41a538aeafeef34ebff96bfeaa3e4651463cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page