Skip to content

Instantly share code, notes, and snippets.

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 / 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']
@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()
# 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 / 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
# 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
# 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
@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
@will-moore
will-moore / microbit:simple-tetris.js
Last active March 2, 2024 18:17
Simple tetris game for microbit using Code-kingdoms editor
let gameOver = false
let y = 0
let x = 0
let rowFull = false
let canFall = false
let delay = 0
input.onButtonPressed(Button.A, () => {
led.unplot(x, y)
if (x > 0 && !(led.point(x - 1, y))) {
x = x - 1
@will-moore
will-moore / original_metadata_to_map_ann.py
Created April 27, 2017 15:05
Convert OMERO image Original metadata into a map annotation on the Image
import omero
from omero.gateway import BlitzGateway
# See https://www.openmicroscopy.org/community/viewtopic.php?f=4&t=8268
imageId = 72416
conn = BlitzGateway("username", "password", host="localhost", port=4064)
conn.connect()
image = conn.getObject("Image", imageId)