Tile position from Olympus .oir file + python-bioformats

I have a series of Olympus .oir files from a multi-area time lapse acquisition. One such file is:

I can use Python + bioformats to load this file and extract the image data. I can also start to see the associated metadata with this code:

import javabridge
import bioformats

matlFile = r'D:\barSeq\bxSeqIntTest_Cycle\matl.omp2info'

img = bioformats.load_image(fileName)  # Image data
xmlRaw = bioformats.get_omexml_metadata(fileName)
metadata = bioformats.OMEXML(xmlRaw) # OMEXML object w/ metadata

print(metadata.image().get_Name())  # Should output 'bxSeqIntTest_A01_G001_0001.oir'

I’d like to get the XYZ physical coordinates for each plane in this file. I’m assuming this information is somewhere in the OMEXML object but I can’t seem to figure out exactly where. Has anyone managed to get this info out of an .oir file and could point out the method or property name to use?

In java you access it via

metadata.getPlanePosition[XYZ](index_of_series, index_of_plane)

and it’s a similar line for the voxelSize:

metadata.getPixelsPhysicalSizeX(iSerie);

I guess it’s the same for python ?

One detail, an object of type Length is returned, for which you need to set a unit in order to get a value. Look for instance at the code below:

PS: for @joshmoore and @will-moore is there the same kind of function for the omero api ? I remember having troubles accessing the stage location.

Yes, get Length has l.getValue() and l.getUnit().
For example, this code:

is used to generate the position values in this JSON: http://idr.openmicroscopy.org/webgateway/well/4925/children/

2 Likes

Thanks for the tips. I’m going to have to plead ignorance on this and ask for a bit more of a basic example.

Continuing from the example above,

metadata.getPlanePosition()

is not an attribute or method in the Python OMEXML object. Similar for

metadata.getPixelsPhysicalSizeX()

The latter is accessible with

metadata.image().Pixels.PhysicalSizeX

but there isn’t an immediately obvious corresponding property for the position of the plane. Digging a bit more through the class directory shows that

metadata.image().Pixels.plane().PositionX

might be on the right path, but this yields

IndexError: list index out of range

I’m sure this is a funny syntax issue, but not sure where to go from here. Any tips?

metadata.image().Pixels.plane().PositionX should be correct, the error you are seeing suggests there are no plane elements on the Pixels object.

It might be worth looking at the OME-XML of the file to see if that particular file actually has the plane position data populated or not. The quickest way might be through the command line tools at Bio-Formats Downloads | Open Microscopy Environment (OME). You can view the xml using the command showinf -nopix -omexml path/to/myFile.tiff