Page 1 of 1

Extracting OME XML metadata

PostPosted: Thu Jan 12, 2012 11:26 am
by a.herbert
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:

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

Re: Extracting OME XML metadata

PostPosted: Thu Jan 12, 2012 11:47 am
by a.herbert
Update:

I have changed the code in omero_dist/lib/python/omero/gateway/__init__.py as suggested in my previous post to:

Code: Select all
    def isOriginalMetadata(self):
        """
        Checks if this file annotation is an 'original_metadata' file
       
        @return:    True if namespace and file name follow metadata convention
        @rtype:     Boolean
        """
       
        try:
            #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"):
            if self._obj.ns is not None and self._obj.ns.val == omero.constants.namespaces.NSCOMPANIONFILE and self.getFileName().startswith("original_metadata"):
                return True
        except:
            logger.info(traceback.format_exc())
        return False


The call to ImageWrapper.loadOriginalMetadata() now returns the metadata.

Regards,

Alex

Re: Extracting OME XML metadata

PostPosted: Thu Jan 12, 2012 12:01 pm
by wmoore
Thanks Alex,

This bug has been noted and fixed in the development version of OMERO.

Mentioned in these forums (with workarounds):
http://www.openmicroscopy.org/community ... 3333#p3333
http://www.openmicroscopy.org/community ... f=16&t=920

Apologies for the hassle.

Will.

Re: Extracting OME XML metadata

PostPosted: Thu Jan 12, 2012 2:35 pm
by a.herbert
Hi Will,

Thanks for the info.

I started this thread because the forum search returned no results. Instead it produced this message:

Code: Select all
The following words in your search query were ignored because they are too common words: metadata


I get this for most of my searches using the forum search engine. Is there a problem with the forum search? Next time I'll use Google instead. That would have saved me some effort.

Regards,

Alex

Re: Extracting OME XML metadata

PostPosted: Thu Jan 12, 2012 4:23 pm
by wmoore
Thanks for that Alex. We've fixed some of the search parameters so things should be working a bit better now.

Cheers, Will.