[ome-devel] connecting to omero via python

Josh Moore josh at glencoesoftware.com
Wed Feb 9 16:26:47 GMT 2011


Hi Adam,

a bit late to the thread, but hopefully still useful. (Sorry forgot to send this.)

On Feb 4, 2011, at 7:45 PM, Adam Fraser wrote:

> I'm in the process of developing the first OMERO interface from CellProfiler
> 2.0 <http://cellprofiler.org/>, and I'd like a little help in writing clean
> efficient code. The first module I'm working on is one that will import
> image channels into CP directly from OMERO.
> 
>> From a user point of view, the controls will look like this:
> 
> *server*: *my server*
> *username*: *afraser*
> *password*: *******
> *project*: *adams_project*
> *dataset*: *adams_dataset*
> 
> 
> ...and they'll specify a name for each of their channels somehow:
> 
> *channel 1 name*: *DNA*
> *channel 2 name*: *Actin*
> (add channel button)
> 
> (these names will be used in the input controls of downstream modules in
> CellProfiler)
> 
> Just before the pipeline is run, I'd like to connect to the server, and
> create a list of all the image ids that I'll be accessing during each
> iteration. One way to do this would be:
> 
>        c = omero.client(self.server.value)
>        s = c.createSession(self.username.value, self.password.value)
>        cs = s.getContainerService()
>        blitzcon = client_wrapper(self.username.value,
>                                  self.password.value,
>                                  host=self.host.value, port=4064)
> 
>        blitzcon.connect()
>        for p in blitzcon.listProjects():
>            for dataset in p.listChildren():
>                if dataset.getName() == self.dataset.value
>                    *dataset_id* = dataset.getId()
> 
>        imgs = cs.getImages("Dataset", [*dataset_id*], None)
>        d = self.get_dictionary(image_set_list)
>        for i, img in enumerate(imgs):
>            image_set = image_set_list.get_image_set(i)
>            d[i] = img.getId().getValue()
> 
> I emboldened dataset_id because you can see that I am establishing a whole
> second connection just to get it because I was unable to find equivalent
> methods within omero.gateway which I am using (so far) for everything else.

If you are using client_wrapper and, therefore, omero.gateway.BlitzGateway already,
then it would perhaps be better to create blitzcon first and then use its
omero.client object.

       blitzcon = client_wrapper(self.username.value,
                                 self.password.value,
                                 host=self.host.value, port=4064)
       c = blitzcon.c
       s = c.sf
       ...        
       cs = s.getContainerService()

But do note that we are in the process of refactoring BlitzGateway to unify its
methods with those in Insight so this API should be considered internal for the
moment. If you have suggestions, we'd love to hear them.

> I was hoping someone could give me a better way of doing this. Additionally
> I have yet to run into trouble regarding keeping the session alive, but I'm
> not doing anything special to prevent it from going away so I expect this
> will be a problem eventually.

Very likely, as soon as the client is inactive for 10 minutes or so. You can
start by using the "omero.keep_alive" property described here:

http://git.openmicroscopy.org/?p=ome.git;a=blob;f=etc/ice.config;h=2021d9f7399cac08bef5db2bbe50bde6f5e93292;hb=master#l67

> Thanks for your help,
> Adam

Gladly,
~Josh


More information about the ome-devel mailing list