We're Hiring!

Access original metadata from script

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Access original metadata from script

Postby ppouchin » Wed Nov 16, 2011 9:56 am

Hi !

I've finally started making scripts for OMERO...
Well, I made only one tiny little script, and it's mostly a modification of an official script: it renames multiple images at once... which is useful to get rid of the "DropBox" folder (and its parents) in the names...

Now, I'd like to try something else... Our LIF and LSM files miss some metadata once imported (excitation wavelength, colors and acquisition date). I know you're looking into these problems but I'd like to give users the possibility to, at least, restore their colors with a simple click.

Wavelengths are complicated in LIF files... I even wonder if it's possible to associate a wavelength to a channel for these files... And the "timestamps" don't even appear in the metadata (either in Omero or Fiji...), so the information on the acquisition date seems lost...

Anyway, I'd like to just access the original metadata to check the channel descriptions, but I could not find how... Is there an easy way... ?
Last edited by ppouchin on Thu Dec 08, 2011 2:02 pm, edited 2 times in total.
ppouchin
 
Posts: 98
Joined: Thu Dec 02, 2010 2:08 pm

Re: Access original metadata from script

Postby wmoore » Wed Nov 16, 2011 11:31 am

Yes,

I think everything you need should be in this example:

https://github.com/will-moore/openmicro ... etadata.py

The 'conn' object is the same one that you get in the scripts via
Code: Select all
conn = BlitzGateway(client_obj=client)


We will be merging these examples into our main code base soon.

Cheers,

Will.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Access original metadata from script

Postby wmoore » Wed Nov 16, 2011 12:02 pm

You might find this code useful for setting colours and wavelengths on images.

Code: Select all
from omero.rtypes import *
image = conn.getObject("Image", iId)

cNames = ['DAPI', 'Red', 'GFP', 'Yellow']
colors = [(0,0,255), (255,0,0), (0,255,0), (255,255,0)]     # blue, red, green, yellow,
exWaves = [100, 200, 300, 400]
emWaves = [150, 250, 350, 450]

for i, c in enumerate(image.getChannels()):
    lc = c.getLogicalChannel()
    lc.setName(cNames[i])
    lc.save()
    # Use the logical channel to save wavelengths
    lcObj = lc._obj
    lcObj.excitationWave = omero.rtypes.rint(exWaves[i])
    lcObj.emissionWave = omero.rtypes.rint(emWaves[i])
    conn.getUpdateService().saveObject(lcObj)
    r, g, b = colors[i]
    # need to reload channels to avoid optimistic lock on update
    cObj = conn.getQueryService().get("Channel", c.id)
    cObj.red = omero.rtypes.rint(r)
    cObj.green = omero.rtypes.rint(g)
    cObj.blue = omero.rtypes.rint(b)
    cObj.alpha = omero.rtypes.rint(255)
    conn.getUpdateService().saveObject(cObj)
image.resetRDefs()  # reset based on colors above



You can see from the metadata example in the above post how to get Filter wavelength info for each channel. This is where we'd aim to store the wavelength info for Leica files, since they have this info in the file, but to create filters and add them to channels to store all the wavelength info you have is tricky.

Hope this helps,

Will.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Access original metadata from script

Postby ppouchin » Wed Nov 16, 2011 1:41 pm

Thank you !

Unfortunately, when I use :
Code: Select all
om = image.loadOriginalMetadata()


Nothing seems to be returned... (om is None...)
Does it try to access the metadata from an archived file ?
ppouchin
 
Posts: 98
Joined: Thu Dec 02, 2010 2:08 pm

Re: Access original metadata from script

Postby wmoore » Wed Nov 16, 2011 2:31 pm

Hmmm, seems like there is a bug in that code (just noticed that the webclient is not displaying Original Metadata either!).
We will get this fixed, but in the meantime this should work for you:

Code: Select all
for ann in image.listAnnotations():
    if ann.getFile() and ann.getFile().getName().startswith("original_metadata"):
        t_file = []
        for piece in ann.getFileInChunks():
            t_file.append(piece)
        temp_file = "".join(t_file).split('\n')
        for l in temp_file:
            if l.startswith("[GlobalMetadata]"):
                print l
            elif l.startswith("[SeriesMetadata]"):
                print l
            else:
                if len(l) < 1:
                    l = None
                else:
                    l = tuple(l.split("="))
                print l


Cheers,

Will.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Access original metadata from script

Postby ppouchin » Wed Nov 16, 2011 4:11 pm

Using your code (and the source of the loadOriginalMetadata method), I wrote a temporary function which emulates the original method.

I am now able to go through the metadata and check the LUTs... Soon it will be correctly applied to images...

Thanks for your help !
ppouchin
 
Posts: 98
Joined: Thu Dec 02, 2010 2:08 pm

Re: Access original metadata from script

Postby wmoore » Wed Nov 16, 2011 10:17 pm

Glad it's working - A couple of final points:

You should be aware that the format of the key - value pairs in Original metadata shouldn't be considered an 'API'. It's not guaranteed to be the same across different versions of Bio-Formats / OMERO, it may vary with different versions/types of LSM or LIF files etc.

When you have something working, you might be interested in making it available for others. Either for users or simply as an example for other developers. You can submit it here viewforum.php?f=16 (as you can see, we have limited (1) submission so far!).
Also might be useful for us to see what you're doing, for future features or just pointing out improvements etc.

Cheers,

Will.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Access original metadata from script

Postby ppouchin » Thu Nov 24, 2011 9:58 am

I submitted my first small script and I am now trying to make a second one to manage some other metadata.

I was wondering if the "timestamps" that appear in the original file are somehow kept because I don't see them in the metadata...
("TimeStamp|HighInteger", ...)
ppouchin
 
Posts: 98
Joined: Thu Dec 02, 2010 2:08 pm

Re: Access original metadata from script

Postby wmoore » Thu Nov 24, 2011 12:47 pm

You'll need to give me some more details of what you mean:

- Which file (LSM? LIF?)
- Where do they "appear"? When viewed in the acquisition software / Zeiss/Leica viewer / ImageJ?

Are they displayed in the "Image Details" of the "General" tab on the right?
Acquisition and Import dates.

Cheers,

Will.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Access original metadata from script

Postby ppouchin » Thu Nov 24, 2011 1:49 pm

Oh, yes. I forgot to mention the format. I was talking about LIF files.
In LAS AF, I can see "timestamps". But whether I use Fiji (with the original file) or Omero, I don't see anything like that in the metadata.
I think there should be something like here.

The problem is that the "acquisition" date for LIF files (and for LSM too) is wrong. It seems to use that "last changed" date (but I'm not sure). I thought I would restore the date stored in the metadata, but I don't see any "timestamp" in the metadata, so I thought, maybe, it was stored somewhere else... or maybe is it "lost" by bio-formats... ?
ppouchin
 
Posts: 98
Joined: Thu Dec 02, 2010 2:08 pm

Next

Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron