Skip to content

Instantly share code, notes, and snippets.

@will-moore
will-moore / omero_figure_export.py
Last active December 15, 2020 07:26
Export OMERO.figure file as PDF (or TIFF) using the scripting service.
"""
See http://lists.openmicroscopy.org.uk/pipermail/ome-users/2017-February/006362.html
and
https://forum.image.sc/t/use-python-to-export-figures-from-omero/46520
"""
from omero.rtypes import wrap
from omero.gateway import BlitzGateway
import omero
# select obj, minIndex(ws), maxIndex(ws) from Plate as obj join fetch obj.wells wells left outer join fetch wells.wellSamples ws where obj.id in (:ids) group by obj.id
2017-01-23 16:50:16,095 INFO [ome.services.sessions.state.SessionCache] (2-thread-5) Synchronizing session cache. Count = 4
2017-01-23 16:50:16,095 INFO [ ome.services.util.ServiceHandler] (2-thread-5) Executor.doWork -- ome.services.sessions.SessionManagerImpl.reload[5e9cdf94-4184-40ee-a3da-9c5693f55812]
2017-01-23 16:50:16,095 INFO [ ome.services.util.ServiceHandler] (2-thread-5) Args: [null, InternalSF@33779587]
2017-01-23 16:50:16,108 INFO [ ome.security.basic.EventHandler] (2-thread-5) Auth: user=0,group=0,event=null(Sessions),sess=d30fd532-ae16-47a0-a3cc-5dbb3a9b3a91
2017-01-23 16:50:16,116 INFO [ org.perf4j.TimingLogger] (2-thread-5) start[1485190216095] time[20] tag[omero.call.success.ome.services.sessions.SessionManagerImpl$6.doWork]
2017-01-23 16:50:16,116 INFO [ ome.services.u
# query is
select obj , minIndex(ws), maxIndex(ws) from Plate as obj join fetch obj.wells wells left outer join fetch wells.wellSamples ws where obj.id in (:ids)
2017-01-23 15:54:27,130 INFO [ org.perf4j.TimingLogger] (.Server-83) start[1485186867124] time[6] tag[omero.call.exception]
2017-01-23 15:54:27,133 WARN [ ome.services.util.ServiceHandler] (.Server-83) InvalidDataAccessResourceUsageException thrown.
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select plate0_.id as col_0_0_, min(wellsample2_.well_index) as col_1_0_, max(wellsample2_.well_index) as col_2_0_, wells1_.id as id143_1_, wellsample2_.id as id146_2_, plate0_.id as id109_0_, wells1_.id as id143_1_, wellsample2_.id as id146_2_, plate0_.columnNamingConvention as columnNa2_109_0_, plate0_.columns as columns109_0_, plate0_.defaultSample as defaultS4_109_0_, plate0_.description as descript5_109_0_, plate0_.creation_id as creation17_109_0_, plate0_.external_id as external
@will-moore
will-moore / microbit:snake.js
Created January 18, 2017 13:20
"Worst snake ever" game from bbc microbit, created on the Code Kingdoms JavaScript editor.
// When the BBC micro:bit runs.
function onStart( ) {
microbit.draw(Pattern("01000.01100.01110.01100.01000"));
wait(200);
}
function onPressA( ) {
/* create variables to keep track of
# Pearson coefficient described at https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3074624/
# Start with
# $ omero shell --login
conn = omero.gateway.BlitzGateway(client_obj=client)
i = conn.getObject("Image", 62137)
p = i.getPrimaryPixels()
# get 2D planes and reshape to 1D array
@will-moore
will-moore / luts.py
Last active September 19, 2016 09:04
Script to generate previews of LookupTables in OMERO. See https://github.com/openmicroscopy/openmicroscopy/pull/4764
from omero.gateway import BlitzGateway
from PIL import Image
conn = BlitzGateway("user-3", "ome", host="eel.openmicroscopy.org", port=4064)
# Image is a 'fake' bio-formats image (grey intensity gradient)
imageId = 25501
conn.connect()
@will-moore
will-moore / webgateway_json.py
Last active July 26, 2016 09:03
Using http://docs.python-requests.org/ to access OMERO via json api. For OMERO 5.2.x and earlier. See discussion at https://www.openmicroscopy.org/community/viewtopic.php?f=6&t=8077
import requests
session = requests.Session()
BASE_URL = "https://test.openmicroscopy.org/omero/"
# BASE_URL = "http://localhost:4080/"
login_url = BASE_URL + "webclient/login/"
r = session.get(login_url)
token = r.cookies['csrftoken']
import requests
session = requests.Session()
# Start by getting supported versions from the base url...
r = session.get('http://localhost:4080/webgateway/api/')
# we get a list of versions
versions = r.json()
print 'Versions', versions
@will-moore
will-moore / Plot_csv.py
Last active June 1, 2016 11:31
OMERO script to download csv attached to images and upload a plot as a new image
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import omero.scripts as scripts
from omero.gateway import BlitzGateway
from omero.rtypes import rstring, rlong
import numpy
try:
from PIL import Image # see ticket:2597
# Alternatively start with omero shell, instead of first 2 lines below, do this:
# $ bin/omero shell --login
# conn = omero.gateway.BlitzGateway(client_obj=client)
conn = BlitzGateway("will", "ome", host="localhost", port=4064)
conn.connect()
updateService = conn.getUpdateService()
roiService = conn.getRoiService()
from omero.rtypes import rstring
imageId = 3731