See https://docs.openmicroscopy.org/latest/omero/developers/Python.html
from omero.gateway import BlitzGateway
from getpass import getpass
def connect(hostname, username, password):
"""
Connect to an OMERO server
:param hostname: Host name
:param username: User
:param password: Password
:return: Connected BlitzGateway
"""
conn = BlitzGateway(username, password,
host=hostname, secure=True)
conn.connect()
conn.c.enableKeepAlive(60)
return conn
HOST = 'wss://workshop.openmicroscopy.org/omero-ws'
conn = connect(HOST, input("Username: "),
getpass("OMERO Password: "))
print("Connected as {}".format(conn.getUser().getName()))
Username: trainer-1 OMERO Password: ········ Connected as trainer-1
def load_images(conn, dataset_id):
"""
Load the images in the specified dataset
:param conn: The BlitzGateway
:param dataset_id: The dataset's id
:return: The Images or None
"""
dataset = conn.getObject("Dataset", dataset_id)
images = []
for image in dataset.listChildren():
images.append(image)
if len(images) == 0:
return None
for image in images:
print("---- Processing image", image.id)
return images
images = load_images(conn, input("Dataset ID: "))
print(images[0]._obj.id)
Dataset ID: 2391 ---- Processing image 28662 ---- Processing image 57226 ---- Processing image 28663 ---- Processing image 57227 ---- Processing image 28664 ---- Processing image 57228 ---- Processing image 28665 ---- Processing image 28666 ---- Processing image 28667 ---- Processing image 28668 ---- Processing image 57229 ---- Processing image 28669 ---- Processing image 57230 ---- Processing image 28670 ---- Processing image 57231 ---- Processing image 28671 ---- Processing image 28672 ---- Processing image 28673 ---- Processing image 28674 ---- Processing image 28675 object #0 (::omero::RLong) { _val = 28662 }
conn.close()
Copyright (C) 2019-2020 University of Dundee. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.