Cleanest way to access python-bioformats metadata

I’m trying to find the cleanest way to access metadata from an OME Bioformats file using python-bioformats. Ideally I’d grab the metadata from the metadata property in bioformats.ImageReader. This returns a javabridge.JB_Object. OK, no problem, I can access the data from that object with javabridge.jutil.call(). However, I have a difficult time getting anything besides XYZCT from this object. Still determined to get metadata from within ImageReader, I wrote the following:


class ImageReader2(bioformats.ImageReader):

...

    def md(self):
        if self._md is None:
            self._md = []
            _io = self.rdr.getSeries()
            idxs = np.arange(self.series_count)
            for _i in idxs:
                self.rdr.setSeries(_i)
                series_md = javabridge.jutil.jdictionary_to_string_dictionary(self.rdr.getSeriesMetadata())
                self._md.append(series_md)
            self.rdr.setSeries(_io)
        return self._md

This gives me a metadata dictionary per series, which is ideal. Is there a better method than this that allows metadata access through ImageReader? I’d prefer not to load the metadata separately from the file using bioformats.get_omexml_metadata() if I already have access to this metadata through my initial ImageReader load. Thanks for any help with this!

Hi @zacsimile, accessing the metadata through ImageReader is indeed the correct way to go. There are a couple of different types of metadata, the reader.getSeriesMetadata() will return core metadata for the given series. On top of this there may be other format specific metadata fields which will be saved in reader.getGlobalMetadata(). This will return a Hashtable<String, Object> which will contain key, value paris for the remaining metadata fields not defined in OME-XML.

So this one additional call to add the global metadata will likely return the missing values that you are looking for.

Hi @dgault, thanks for the help! I did try reader.getGlobalMetadata(), but that is returning an empty Hashtable for me. I’m opening a LIF file in python-bioformats. I’ll post a GitHub issue there.