Skip to content

Reading OME XML from ome.tif file #125

@hadim

Description

@hadim

Hi,

I woud like to know if you could add a method to easly read OME XML file from .ome.tif file. Because I really don't know what it the best way to implement it so I prefer to ask you directly. OME XML can be read when opening the tiff stack with TiffStack_tifffile.

I wrote a small piece of code to show you how xml can be accessed for TiffFile object.

import matplotlib as mpl
import matplotlib.pyplot as plt

import numpy as np
import pandas as pd

import pims
import trackpy as tp

import xmltodict

frames = pims.TiffStack_tifffile("my_file.ome.tif")
if frames._tiff.is_ome:
    t = frames._tiff[0]
    xmlstr = t.tags['image_description'].value
    print(xmlstr[:100])
    print()

    namespaces = {'http://www.openmicroscopy.org/Schemas/OME/2013-06': None,
                              'http://www.openmicroscopy.org/Schemas/SA/2013-06': None}
    md = xmltodict.parse( xmlstr, process_namespaces=True, namespaces=namespaces)

    p = md['OME']['Image']['Pixels']
    print(p['@TimeIncrement'])
    print(p['@PhysicalSizeX'])
    print(p['@PhysicalSizeY'])
    print(p['@PhysicalSizeZ'])
b'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<ns0:OME xmlns="http://www.openmicroscopy.org/Schemas/OME/201'

10.076799392700195
0.065
0.065
0.3

Two more things:

  • I use a small python module called xmltodict to convert xml file to a dict which is really more convenient to deal with. Since OME XML are rarely huge file even if you don't want to use an external module maybe we/you can add a small method doing the conversion into pims codebase.
  • I saw a PR adding bioformats support to pims and I think it's great. However in my case I really don't know to load java because I only deal with OME XML files and I am afraid bioformats will only slowing me down when processing a large number of files.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions