Extracting OME XML metadata
Posted: Thu Jan 12, 2012 11:26 am
Dear All,
I would like to extract the OME XML metadata for my images using python. I know the image contains the information I am after since when I export it as OME TIFF it contains the following metadata:
The item that I am interested in is the ExposureTime attribute. I can obtain this through the gateway if I extract the annotations. One of them is 'original_metadata.txt' and will contain a set of key-values pairs for attributes including:
I can also extract the original log file for the DeltaVision image file and get the exposure time from that.
I would prefer to use the 'original_metadata.txt' as it is easier to parse. However there appears to be a bug in the ImageWrapper.loadOriginalMetadata() function within the API since I do not get any values returned for my image. Reading the source code for this function it loops over the annotations list and for each one checks that it is a file annotation and isOriginalMetadata() is true. However for my image this is not the case. Below I show some python code using the gateway to get the data:
I am not sure why the wrapper for original_metadata.txt is not being picked up as the metadata. Is this a genuine bug or am I missing something when creating my wrapper objects (e.g. loading states)?
Within FileAnnotationWrapper.isOriginalMetadata(self) should the following code be changed:
to
At the moment it looks like I will have to manually loop over the annotations myself and identify the metadata file using the name.
Thanking you in advance.
Alex
I would like to extract the OME XML metadata for my images using python. I know the image contains the information I am after since when I export it as OME TIFF it contains the following metadata:
- Code: Select all
<Plane DeltaT="0.0" ExposureTime="5.000000237487257E-4" PositionX="-40.36" PositionY="63.14" PositionZ="-2.195" TheC="0" TheT="0" TheZ="0"/>
The item that I am interested in is the ExposureTime attribute. I can obtain this through the gateway if I extract the annotations. One of them is 'original_metadata.txt' and will contain a set of key-values pairs for attributes including:
- Code: Select all
Image 1. Exposure time=0.500 secs
I can also extract the original log file for the DeltaVision image file and get the exposure time from that.
I would prefer to use the 'original_metadata.txt' as it is easier to parse. However there appears to be a bug in the ImageWrapper.loadOriginalMetadata() function within the API since I do not get any values returned for my image. Reading the source code for this function it loops over the annotations list and for each one checks that it is a file annotation and isOriginalMetadata() is true. However for my image this is not the case. Below I show some python code using the gateway to get the data:
- Code: Select all
>>> img = conn.getObject('Image', 2228)
>>> meta = img.loadOriginalMetadata()
>>> print meta
None
>>> for a in img.listAnnotations():
... print "%s (%s) = %s" % (a.getFileName(), a._obj.ns.val, a.isOriginalMetadata())
...
original_metadata.txt (openmicroscopy.org/omero/import/companionFile) = False
E05_111220_EH3_p184_55_R3D.dv.log (openmicroscopy.org/omero/import/companionFile) = False
I am not sure why the wrapper for original_metadata.txt is not being picked up as the metadata. Is this a genuine bug or am I missing something when creating my wrapper objects (e.g. loading states)?
Within FileAnnotationWrapper.isOriginalMetadata(self) should the following code be changed:
- Code: Select all
if self._obj.ns is not None and \
self._obj.ns.val == omero.constants.namespaces.NSCOMPANIONFILE and \
self._obj.file.name.val.startswith("original_metadata"):
return True
to
- Code: Select all
if self._obj.ns is not None and \
self._obj.ns.val == omero.constants.namespaces.NSCOMPANIONFILE and \
self.getFileName().startswith("original_metadata"):
return True
At the moment it looks like I will have to manually loop over the annotations myself and identify the metadata file using the name.
Thanking you in advance.
Alex