[ome-devel] connecting to omero via python
Will Moore
will at lifesci.dundee.ac.uk
Mon Feb 7 23:21:49 GMT 2011
Hi Adam,
I should warn you that the whole python API is a bit ad hoc at the
moment, since it's been developed experimentally for a number of
different use cases (E.g. scripts, web-client) and we're in the
process of rationalising this to some extent.
At the moment you have to look in a bunch of different places to find
the functionality you need (as you've seen).
The solution I've attached uses the latest trunk code, although the
methods may have been unchanged since the 4.2.2 release?
I wasn't sure what you meant by
project = 'xxx'
dataset = 'xxx'
I imagine you want to let users connect to OMERO, browse their
Projects (choose one) browse it's Datasets and select one with images
to process.
The only bit that is missing from the attached script is getting the
user's choice.
Hope that gets you going, and that any changes in the API don't cause
too much pain!
Will.
On 7 Feb 2011, at 21:43, Adam Fraser wrote:
> Hi Will,
>
> Thanks for your response, I would have gotten back to you sooner but
> I was traveling.
>
> On Sat, Feb 5, 2011 at 3:04 AM, Will Moore
> <will at lifesci.dundee.ac.uk> wrote:
> Hi Adam,
>
> Sorry for the confusion, but the connection you're using for most
> stuff is the 'blitzcon' connection?
>
> No, I was primarily connecting via:
> c = omero.client('ome2-copy.fzk.de')
> s = c.createSession('afraser', '****')
> g = s.createGateway()
>
> Or is 'blitzcon' the "second" connection you're using to get Dataset
> ID?
>
> yup.
>
> Confusingly, we have a 'gateway' service in the createSession()
> connection, but we also refer to the 'blitzcon' connection as
> omero.gateway
>
> hrm, I'm definitely confused then because I can do g.getPlane(ID,
> 0,0,0) with the above gateway, but there's no such getPlane method
> in what we're calling blitzcon.
>
> Also confusingly, I can get a session from blitzcon, but it's
> apparently not the same as the type of session I get from
> omero.clients.BaseClient.createSession(user, password)
>
> blitzcon = client_wrapper("afraser", "****", host="ome2-
> copy.fzk.de", port=4064)
> blitzcon.connect()
> s = blitzcon.getSession()
> s.getGateway() #fails
>
> ... of course the only reason I'm trying to get the gateway here is
> because I need getPlane().
>
>
> You want to allow the user to browse their Projects and Datasets by
> name, to get Dataset ID?
> You can use the container service to list Projects and Datasets...
>
> >>> projects = cs.loadContainerHierarchy("Project", None, None)
> >>> for p in projects:
> >>> print p.getName().getValue()
> >>> for d in p.linkedDatasetList():
> >>> print d.getName().getValue()
>
> Ok, this would prevent me from having to connect via the blitzcon
> thing but...
>
>
> But if you know the name of the Dataset from the start, and you
> simply want the ID, you CAN use the query service.
>
> Hrm, I know _nothing_ about the db schema, so I'd like to avoid this
> unless it's going to give me a serious performance improvement.
>
> Generally you will find it much easier to work with the blitzcon
> connection.
>
> Ok, so I should use blitzcon = omero.client_wrapper(...), that's
> fine. Thanks for clearing this up. I don't want to use the gateway
> if it's going to change on me, I had the impression it was the right
> thing to use after reading this page.
>
> So here's where this puts me in terms of code:
>
> import omero
> from omero import client_wrapper
> import numpy as np
>
> user = 'xxx'
> pw = 'xxx'
> host = 'xxx'
> project = 'xxx'
> dataset = 'xxx'
>
> blitzcon = client_wrapper(user, pw, host, port=4064)
> blitzcon.connect()
>
> # get all image ids from dataset:
> image_ids = #???
>
> for image_id in image_ids:
> im = blitzcon.getImage(image_id)
> # Get raw image plane.
> # previously: plane = g.getPlane(image_id, 0, 0, 0)
> plane = #???
> px = im.getPixels(0)
> h = px.getSizeY().getValue()
> w = px.getSizeX().getValue()
> imdata = np.array(list(plane))
> imdata.shape = (h,w)
> # now I can do stuff with imdata
>
> Any chance you can help me fill in those 2 blanks?
>
> Thanks again,
> Adam
William Moore
Wellcome Trust Centre for Gene Regulation & Expression
College of Life Sciences
MSI/WTB/JBC Complex
University of Dundee
Dow Street
Dundee DD1 5EH
United Kingdom
Phone 01382 386364
http://openmicroscopy.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20110207/a7a51c21/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: adamFraser.py
Type: text/x-python-script
Size: 1199 bytes
Desc: not available
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20110207/a7a51c21/attachment-0001.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20110207/a7a51c21/attachment-0003.html>
More information about the ome-devel
mailing list