We're Hiring!

Thumbnail pixels and annotations/tag

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.

Re: Thumbnail pixels and annotations/tag

Postby cxallan » Wed Feb 17, 2010 5:13 pm

First thing to note is that OMERO only provides IDs (and unloaded objects) for relations that are 1:1. So you must perform a query based on that Image ID to do what you want. Python examples follow.

Option 1, query against the Pixels set itself:

Code: Select all
>>> iquery = sf.getQueryService()
>>> image = iquery.find('Image', 1L)
>>> pixels = iquery.findByQuery('from Pixels as p where p.image = %d' \
...      % image.id.val, None)
>>> pixels.id
object #0 (::omero::RLong)
{
    _val = 1
}
>>> pixels.id
object #0 (::omero::RLong)
{
    _val = 1
}


Option 2, query with a fetch:

Code: Select all
>>> image = iquery.findByQuery('from Image as image join fetch image.pixels '
...                            'where image.id = %d' % 1L, None)
>>> image.id
object #0 (::omero::RLong)
{
    _val = 1
}
>>> image.getPrimaryPixels().id.val
1L


These are HQL queries, which is an object oriented query language included as part of Hibernate. You can read more about HQL here:

http://docs.jboss.org/hibernate/stable/ ... ryhql.html
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am

Re: Thumbnail pixels and annotations/tag

Postby cxallan » Wed Feb 17, 2010 5:18 pm

If you don't like string comprehension you can also use a ParametersI object:

Code: Select all
...
>>> params = omero.sys.ParametersI()
>>> params.addId(1L)
object #0 (::omero::sys::Parameters)
{
    map =
    {
        key = id
        value = object #1 (::omero::RLong)
        {
            _val = 1
        }
    }
    theFilter = <nil>
    theOptions = <nil>
}
>>> image = iquery.findByQuery('from Image as image join fetch image.pixels '
...                            'where image.id = :id', params)
>>> image.id
object #0 (::omero::RLong)
{
    _val = 1
}
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am

Previous

Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 0 guests