From 1d97e50f7fdca907e3dead928a362d4842f84032 Mon Sep 17 00:00:00 2001 From: Christian Evenhuis Date: Wed, 20 Mar 2019 23:38:22 +1100 Subject: [PATCH 1/2] ext changed by Fiji script added script params to replace hard coded USERNAME, HOST etc --- practical/jython/open_image.py | 96 ++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 practical/jython/open_image.py diff --git a/practical/jython/open_image.py b/practical/jython/open_image.py new file mode 100644 index 00000000..10059cd6 --- /dev/null +++ b/practical/jython/open_image.py @@ -0,0 +1,96 @@ +#@ String(label="Username") USERNAME +#@ String(label="Password", style='password') PASSWORD +#@ String(label="Host",value='outreach.openmicroscopy.org') HOST +#@ Integer(label="Port",value=4064) PORT +#@ Integer(label="ImageId" ) image_id + + +# ----------------------------------------------------------------------------- +# Copyright (C) 2017 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. +# +# ------------------------------------------------------------------------------ + +# This script downloads a file and opens it in ImageJ using Bio-Formats +# importer. +# Use this script in the Scripting Dialog of Fiji (File > New > Script). +# Select Python as language in the Scripting Dialog. +# Error handling is omitted to ease the reading of the script but this +# should be added if used in production to make sure the services are closed +# Information can be found at +# https://docs.openmicroscopy.org/omero/5.4.1/developers/Java.html + +import tempfile +import shutil + +from java.lang import Long + + +# OMERO Dependencies +from omero.gateway import Gateway +from omero.gateway import LoginCredentials +from omero.gateway import SecurityContext +from omero.gateway.facility import TransferFacility +from omero.log import SimpleLogger + +from ij import IJ + + +# Setup +# ===== + + + +def connect_to_omero(): + "Connect to OMERO" + + credentials = LoginCredentials() + credentials.getServer().setHostname(HOST) + credentials.getServer().setPort(PORT) + credentials.getUser().setUsername(USERNAME.strip()) + credentials.getUser().setPassword(PASSWORD.strip()) + simpleLogger = SimpleLogger() + gateway = Gateway(simpleLogger) + gateway.connect(credentials) + return gateway + + +def download_image(gateway, image_id, path): + "Download the files composing the image" + + transfer = gateway.getFacility(TransferFacility) + user = gateway.getLoggedInUser() + ctx = SecurityContext(user.getGroupId()) + return transfer.downloadImage(ctx, path, Long(image_id)) + + +# Connect to OMERO +gateway = connect_to_omero() + +# Download the image. This could be composed of several files +tmp_dir = tempfile.mkdtemp() +print(tmp_dir) + +files = download_image(gateway, image_id, tmp_dir) +for f in files: + options = "open=" + f.getAbsolutePath() + options += " autoscale color_mode=Default " + options += "view=[Standard ImageJ] stack_order=Default" + IJ.run("Bio-Formats Importer", options) + break + +shutil.rmtree(tmp_dir) +gateway.disconnect() From bfaf3b583ee3a06f3d1471942542056642be3e93 Mon Sep 17 00:00:00 2001 From: Christian Evenhuis Date: Wed, 20 Mar 2019 23:41:08 +1100 Subject: [PATCH 2/2] made smae changes to open_image.jy so that diffs can be compared --- practical/jython/open_image.jy | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/practical/jython/open_image.jy b/practical/jython/open_image.jy index bf98f674..8463aaea 100644 --- a/practical/jython/open_image.jy +++ b/practical/jython/open_image.jy @@ -1,3 +1,9 @@ +#@ String(label="Username") USERNAME +#@ String(label="Password", style='password') PASSWORD +#@ String(label="Host",value='outreach.openmicroscopy.org') HOST +#@ Integer(label="Port",value=4064) PORT +#@ Integer(label="ImageId" ) image_id + # ----------------------------------------------------------------------------- # Copyright (C) 2017 University of Dundee. All rights reserved. # @@ -42,17 +48,6 @@ from omero.log import SimpleLogger from ij import IJ -# Setup -# ===== - -# OMERO Server details -HOST = "outreach.openmicroscopy.org" -PORT = 4064 -# parameters to edit -image_id = "1001" -USERNAME = "username" -PASSWORD = "password" - def connect_to_omero(): "Connect to OMERO"