Table Of Contents

Previous topic

omero.testlib package

Next topic

omeroweb package

This Page

omero.util package

Submodules

omero.util.OmeroPopo module

@author Donald MacDonald &nbsp;&nbsp;&nbsp;&nbsp; <a href=”mailto:donald@lifesci.dundee.ac.uk“>donald@lifesci.dundee.ac.uk</a> @version 3.0 <small> (<b>Internal version:</b> $Revision: $Date: $) </small> @since 3.0-Beta4.2

class omero.util.OmeroPopo.DataObject

Bases: object

asIObject()
getDetails()
getDirty()
getId()
isLoaded()
setDirty(boolean)
setId(id)
setValue(value)
class omero.util.OmeroPopo.EllipseData(shape=None)

Bases: omero.util.OmeroPopo.ShapeData

containsPoints()
getRadiusX()
getRadiusY()
getX()
getY()
setRadiusX(radiusx)
setRadiusY(radiusy)
setX(x)
setY(y)
transformPoint(transform, point)
class omero.util.OmeroPopo.ImageData(image=None)

Bases: omero.util.OmeroPopo.DataObject

getDescription()
getName()
setDescription(description)
setName(name)
class omero.util.OmeroPopo.MaskData(maskShape=None)

Bases: omero.util.OmeroPopo.ShapeData

getHeight()
getMask()
getWidth()
getX()
getY()
setHeight(height)
setMask(mask)
setWidth(width)
setX(x)
setY(y)
class omero.util.OmeroPopo.PolygonData(shape=None)

Bases: omero.util.OmeroPopo.ShapeData

Angle2D(x1, y1, x2, y2)
containsPoints()
fromPoints(type)
getBoundingRectangle()
getContents(string, start, end)
getMaskPoints()
getPoints()
getPoints1()
getPoints2()
getPointsString()
inPolygon(p)
parsePointsToList(pts)
parseShapeStringToPoints()
setPointsFromList(points, points1, point2, mask)
setPointsString(pts)
toCoords(ptsList)
toString(pointsList)
class omero.util.OmeroPopo.ROICoordinate(z=0, t=0)
getTimepoint()
getZSection()
setTimepoint(t)
setZSection(z)
class omero.util.OmeroPopo.ROIData(roi=None)

Bases: omero.util.OmeroPopo.DataObject

addShapeData(shape)
getImage()
getIterator()
getPlaneCount()
getShapeCount()
getShapes(z, t)
getShapesInRange(start, end)
initialise()
removeShapeData(shape)
setImage(image)
class omero.util.OmeroPopo.RectData(rectShape=None)

Bases: omero.util.OmeroPopo.ShapeData

containsPoints()
getHeight()
getWidth()
getX()
getY()
setHeight(height)
setWidth(width)
setX(x)
setY(y)
transformPoint(transform, point)
class omero.util.OmeroPopo.ShapeData

Bases: omero.util.OmeroPopo.DataObject

contains(point)
containsPoints()
getROICoordinate()
getT()
getText()
getTransform()
getZ()
setROICoordinate(coord)
setT(theT)
setText(text)
setTransform(transform)
setZ(theZ)
transformToMatrix(str)
class omero.util.OmeroPopo.WorkflowData(workflow=None)

Bases: omero.util.OmeroPopo.DataObject

addKeyword(keyword)
containsKeyword(keyword)
getKeywords()
getNamespace()
removeKeyword(keyword)
setKeywords(keywords)
setKeywordsFromString(keywords)
setNamespace(namespace)
omero.util.OmeroPopo.shapeWrapper(serverSideShape)

Wrap the serverSide shape as the appropriate OmeroPopos @param serverSideShape The shape object to wrap. @return See above.

omero.util.OmeroPopo.toCSV(list)

Convert a list to a Comma Separated Value string. @param list The list to convert. @return See above.

omero.util.OmeroPopo.toList(csvString)

Convert a csv string to a list of strings @param csvString The CSV string to convert. @return See above.

omero.util.ROIDrawingUtils module

Example code to draw 10 ellipses randomly on an image:

import ROI_utils;
import ROIDrawingUtils;
from random import randint;

l = [];
for i in range(0,10):
    e = ROI_utils.EllipseData(
        ROI_utils.ROICoordinate(),
        randint(100, 300), randint(100, 300),
        randint(20, 50), randint(20, 50))
    l.append(e);
d = ROIDrawingUtils.DrawingCanvas();
d.createImage(400,400)
v = d.drawElements(l);
d.image.show()

Example code to draw a polyline on an image an display it in PIL:

try:
    from PIL import Image, ImageDraw # see ticket:2597
except ImportError:
    import Image, ImageDraw # see ticket:2597

import ROI_utils
import ROIDrawingUtils

drawingCanvas = ROIDrawingUtils.DrawingCanvas();
points = [10,30, 40, 80, 100, 150]
polygonData = ROI_utils.PolylineData(ROI_utils.ROICoordinate(), points);
drawingCanvas.createImage(400,400);
drawingCanvas.drawElements([polygonData]);
drawingCanvas.image.show()
class omero.util.ROIDrawingUtils.DrawingCanvas
createImage(width, height)
drawElements(elementList)
drawEllipse(x, y, radiusx, radiusy, shapeSettings, affineTransform=None)
drawLine(x1, y1, x2, y2, shapeSettings, affineTransform=None)
drawMask(x, y, width, height, bytes, shapeSettings, affineTransform=None)
drawPolygon(pointTupleList, shapeSettings, affineTransform=None)
drawPolyline(pointTupleList, shapeSettings, affineTransform=None)
drawRectangle(x, y, w, h, shapeSettings, affineTransform=None)
drawText(x, y, text, shapeSettings, affineTransform=None)
getFillColour(shapeSettings)
getStrokeColour(shapeSettings)
getStrokeWidth(shapeSettings)
setImage(image, width, height)

omero.util.ROI_utils module

class omero.util.ROI_utils.EllipseData(roicoord=<omero.util.ROI_utils.ROICoordinate instance at 0x32624710>, x=0, y=0, radiusX=0, radiusY=0)

Bases: omero.util.ROI_utils.ShapeData, omero.util.ROI_utils.ROIDrawingI

acceptVisitor(visitor)
createBaseType()
getGeometryFromROI(roi)
setROIGeometry(ellipse)
class omero.util.ROI_utils.LineData(roicoord=<omero.util.ROI_utils.ROICoordinate instance at 0x33009488>, x1=0, y1=0, x2=0, y2=0)

Bases: omero.util.ROI_utils.ShapeData, omero.util.ROI_utils.ROIDrawingI

acceptVisitor(visitor)
createBaseType()
getGeometryFromROI(roi)
setGeometry(line)
class omero.util.ROI_utils.MaskData(roicoord=<omero.util.ROI_utils.ROICoordinate instance at 0x330095a8>, bytes=None, x=0, y=0, width=0, height=0)

Bases: omero.util.ROI_utils.ShapeData, omero.util.ROI_utils.ROIDrawingI

acceptVisitor(visitor)
createBaseType()
getGeometryFromROI(roi)
setGeometry(mask)
class omero.util.ROI_utils.PointData(roicoord=<omero.util.ROI_utils.ROICoordinate instance at 0x33009d40>, x=0, y=0)

Bases: omero.util.ROI_utils.ShapeData, omero.util.ROI_utils.ROIDrawingI

acceptVisitor(visitor)
createBaseType()
getGeometryFromROI(roi)
setGeometry(point)
class omero.util.ROI_utils.PolygonData(roicoord=<omero.util.ROI_utils.ROICoordinate instance at 0x32816710>, pointsList=(0, 0))

Bases: omero.util.ROI_utils.ShapeData, omero.util.ROI_utils.ROIDrawingI

acceptVisitor(visitor)
createBaseType()
getGeometryFromROI(roi)
listToString(pointsList)
setGeometry(polygon)
stringToTupleList(pointString)
class omero.util.ROI_utils.PolylineData(roicoord=<omero.util.ROI_utils.ROICoordinate instance at 0x32816ea8>, pointsList=(0, 0))

Bases: omero.util.ROI_utils.ShapeData, omero.util.ROI_utils.ROIDrawingI

acceptVisitor(visitor)
createBaseType()
getGeometryFromROI(roi)
listToString(pointsList)
setGeometry(point)
stringToTupleList(pointString)
class omero.util.ROI_utils.ROICoordinate(z=0, t=0)
setCoordFromROI(roi)
setROICoord(roi)
class omero.util.ROI_utils.ROIDrawingI
acceptVisitor(visitor)
class omero.util.ROI_utils.RectangleData(roicoord=<omero.util.ROI_utils.ROICoordinate instance at 0x32624290>, x=0, y=0, width=0, height=0)

Bases: omero.util.ROI_utils.ShapeData, omero.util.ROI_utils.ROIDrawingI

acceptVisitor(visitor)
createBaseType()
getGeometryFromROI(roi)
setGeometry(rectangle)
class omero.util.ROI_utils.ShapeData
acceptVisitor(visitor)
createBaseType()
fromROI(roi)
getCoordFromROI(roi)
getGeometryFromROI(roi)
getROI()
getShapeSettingsFromROI(roi)
setCoord(coord)
setROICoord(roi)
setROIGeometry(roi)
setROIShapeSettings(roi)
setShapeSettings(settings)
class omero.util.ROI_utils.ShapeSettingsData
getFillSettings()
getSettings()
getShapeSettingsFromROI(roi)
getStrokeSettings()
setFillSettings(colour)
setROIShapeSettings(shape)
setStrokeSettings(colour, width=1)
omero.util.ROI_utils.abstract()
omero.util.ROI_utils.pointsStringToXYlist(string)

Method for converting the string returned from omero.model.ShapeI.getPoints() into list of (x,y) points. E.g: “points[309,427, 366,503, 190,491] points1[309,427, 366,503, 190,491] points2[309,427, 366,503, 190,491]” or the new format: “309,427 366,503 190,491”

omero.util.ROI_utils.xyListToBbox(xyList)

Returns a bounding box (x,y,w,h) that will contain the shape represented by the XY points list

omero.util.cleanse module

Reconcile and cleanse where necessary an OMERO data directory of orphaned data.

class omero.util.cleanse.Cleanser(query_service, object_type)

Bases: object

Keeps file cleansing state and performs OMERO database reconciliation of files within an OMERO binary repository.

PYRAMID_FILE = '_pyramid'
PYRAMID_LOCK = '.pyr_lock'
PYRAMID_TEMP = '.tmp'
QUERY_THRESHOLD = 25
cleanse(root)

Begins a cleansing operation from a given OMERO binary repository root directory. /OMERO/Files or /OMERO/Pixels for instance.

do_cleanse()

Actually performs the reconciliation check against OMERO and removes relevant files.

finalize()

Takes the final set of deferred paths and performs a reconciliation check against OMERO for them. This method’s purpose is basically to catch the final set of paths in the deferred path list and/or perform any cleanup.

query_or_defer(path)

Adds a given path to the list of deferred paths. If the number of deferred paths has reached the QUERY_THRESHOLD (to reduce database hits) a reconciliation check will happen against OMERO.

omero.util.cleanse.cleanse(data_dir, client, dry_run=False)
omero.util.cleanse.delete_empty_dirs(repo, root, client, dry_run)
omero.util.cleanse.fixpyramids(data_dir, query_service, dry_run=False, config_service=None, admin_service=None)
omero.util.cleanse.initial_check(config_service, admin_service=None)
omero.util.cleanse.is_empty_dir(repo, directory, may_delete_dir, to_delete)
omero.util.cleanse.main()

Default main() that performs OMERO data directory cleansing.

omero.util.cleanse.usage(error)

Prints usage so that we don’t have to. :)

omero.util.concurrency module

class omero.util.concurrency.AtExitEvent(verbose=None, name='Unknown')

Bases: threading._Event

threading.Event extension which provides an additional method setAtExit() which sets “atexit” to true.

This class was introduced in 4.2.1 to work around issue #3260 in which logging from background threads produced error messages.

atexit
name
setAtExit()
class omero.util.concurrency.Timer(interval, function, args=None, kwargs=None)

Bases: threading._Timer

Based on threading._Thread but allows for resetting the Timer.

t = Timer(30.0, f, args=[], kwargs={}) t.start() t.cancel() # stop the timer’s action if it’s still waiting

# or

t.reset()

After excecution, the status of the run can be checked via the “completed” and the “exception” Event instances.

reset()
run()
omero.util.concurrency.get_event(name='Unknown')

Returns a threading.Event instance which is registered to be “set” (Event.set()) on system exit.

omero.util.decorators module

class omero.util.decorators.TimeIt(level=10, name=None)

Bases: object

Decorator to measure the execution time of a function. Assumes that a logger global var is available and is the logger instance from logging.getLogger().

@param level: the level to use for logging @param name: the name to use when logging, function name is used if None

logger = <logging.Logger instance at 0x12584440>
omero.util.decorators.locked(func)

Decorator for using the self._lock argument of the calling instance

omero.util.decorators.perf(func)

Decorator for (optionally) printing performance statistics

omero.util.decorators.remoted(func)

Decorator for catching any uncaught exception and converting it to an InternalException

omero.util.decorators.setsessiongroup(func)

For BlitzObjectWrapper class derivate functions, sets the session group to match the object group.

omero.util.decorators.timeit(func)

Shortcut version of the TimeIt decorator class. Logs at logging.DEBUG level.

omero.util.figureUtil module

A collection of utility methods used by Figure scripts for producing publication type of figures.

@author William Moore &nbsp;&nbsp;&nbsp;&nbsp; <a href=”mailto:will@lifesci.dundee.ac.uk“>will@lifesci.dundee.ac.uk</a> @author Jean-Marie Burel &nbsp;&nbsp;&nbsp;&nbsp; <a href=”mailto:j.burel@dundee.ac.uk“>j.burel@dundee.ac.uk</a> @author Donald MacDonald &nbsp;&nbsp;&nbsp;&nbsp; <a href=”mailto:donald@lifesci.dundee.ac.uk“>donald@lifesci.dundee.ac.uk</a> @version 3.0 <small> (<b>Internal version:</b> $Revision: $Date: $) </small> @since 3.0-Beta4.1

omero.util.figureUtil.addScalebar(scalebar, xIndent, yIndent, image, pixels, colour)

Adds a scalebar at the bottom right of an image, No text.

@param scalebar length of scalebar in microns @param xIndent indent from the right of the image @param yIndent indent from the bottom of the image @param image the PIL image to add scalebar to @param pixels the pixels object @param colour colour of the overlay as r,g,b tuple

omero.util.figureUtil.formatTime(seconds, timeUnits)

Returns a string formatting of the time (in seconds) according to the chosen timeUnits: “SECS_MILLIS”, “SECS”, “MINS”, “HOURS”, “MINS_SECS”, “HOURS_MINS”, “HOURS_MINS_SECS”, “HOURS_MINS_SECS_MILLIS”

@param seconds: Time in seconds. float or int @param timeUnits: A string denoting the format. One of the choices above. @return: A string, such as “10” or “3:20”

omero.util.figureUtil.getDatasetsProjectsFromImages(queryService, imageIds)

Query returns a map where each key is the imageId and the value is a list of (projectName, datasetName) tuples. If the image does not have a Dataset AND Project, the map will hold an empty list for that imageId.

@param queryService: The Omero query service @param imageIds: A list of image IDs. [long] @return: A map imageId:[(projectName, datasetName)]

omero.util.figureUtil.getTagsFromImages(metadataService, imageIds)

Query returns a map of key = imageId, value = [tagNames] for the image

@param metadataService: The Omero metadata service @param imageIds: A list of image IDs. [long] @return: A map of imageId:[tagName]

omero.util.figureUtil.getTimeLabels(queryService, pixelsId, tIndexes, sizeT, timeUnits=None, showRoiDuration=False)

Returns a list of time labels e.g. “10”, “20” for the first plane at each t-index (C=0 and Z=0). If no planeInfo is available, returns plane number/total e.g “3/10” If time units are not specified, the most suitable units are chosen based on the max time. The list of label returned includes the timeUnits as the last string in the list, in case you didn’t specify it.

@param queryService: The Omero query service @param pixelsId: The ID of the pixels you want info for @param tIndexes: List of t-index to get the times for.

Assumed to be in t order.
@param sizeT: The T dimension size of the pixels.
Used if no plane info

@param timeUnits: Format choice, see formatTime(). String @param showRoiDuration: If true, times shown are from the start of

the ROI frames, otherwise use movie timestamp.

@return: A list of strings, ordered same as tIndexes

omero.util.figureUtil.getTimes(queryService, pixelsId, tIndexes, theZ=None, theC=None)

Get the time in seconds (float) for the first plane (C = 0 & Z = 0) at each time-point for the defined pixels. Returns a map of tIndex: timeInSecs

@param queryService: The Omero queryService @param pixelsId: The ID of the pixels object. long @param tIndexes: List of time indexes. [int] @param theZ: The Z plane index. Default is 0 @param theC: The Channel index. Default is 0 @return: A map of tIndex: timeInSecs

omero.util.figureUtil.getVerticalLabels(labels, font, textGap)

Returns an image with the labels written vertically with the given font, black on white background

omero.util.imageUtil module

A collection of utility methods based on the Python Imaging Library (PIL) used for making figures.

@author William Moore &nbsp;&nbsp;&nbsp;&nbsp; <a href=”mailto:will@lifesci.dundee.ac.uk“>will@lifesci.dundee.ac.uk</a> @author Jean-Marie Burel &nbsp;&nbsp;&nbsp;&nbsp; <a href=”mailto:j.burel@dundee.ac.uk“>j.burel@dundee.ac.uk</a> @author Donald MacDonald &nbsp;&nbsp;&nbsp;&nbsp; <a href=”mailto:donald@lifesci.dundee.ac.uk“>donald@lifesci.dundee.ac.uk</a> @version 3.0 <small> (<b>Internal version:</b> $Revision: $Date: $) </small> @since 3.0-Beta4.1

omero.util.imageUtil.RGBIntToRGB(RGB)

Returns a tuple of (r,g,b) from an integer colour r, g, b are 0-255.

@param RGB: A colour as integer. Int @return: A tuple of (r,g,b)

omero.util.imageUtil.RGBIntToRGBA(RGB)

Returns a tuple of (r,g,b,a) from an integer colour r, g, b, a are 0-255.

@param RGB: A colour as integer. Int @return: A tuple of (r,g,b,a)

omero.util.imageUtil.checkRGBRange(value)

Checks that the value is between 0 and 255. Returns integer value If the value is not valid, return 255 (better to see something than nothing!)

@param value: The value to check. @return: An integer between 0 and 255

omero.util.imageUtil.getFont(fontsize)

Returns a PIL ImageFont Sans-serif true-type font of the specified size or a pre-compiled font of fixed size if the ttf font is not found

@param fontsize: The size of the font you want @return: A PIL Font

omero.util.imageUtil.getThumbnail(thumbnailStore, pixelsId, length)

Returns a thumbnail (as string) from the pixelsId, the longest side is ‘length’

@param thumbnailStore: The Omero thumbnail store @param pixelsId: The ID of the pixels. long @param length: Length of longest side. int @return: The thumbnail as a String,

or None if not found (invalid image)
omero.util.imageUtil.getThumbnailSet(thumbnailStore, length, pixelIds)

Returns map of thumbnails whose keys are the pixels id and the values are the image, the longest side is ‘length’

@param thumbnailStore: The Omero thumbnail store @param pixelIds: The collection of pixels ID. @param length: Length of longest side. int @return: See above

omero.util.imageUtil.getZoomFactor(imageSize, maxW, maxH)

Returns the factor by which the Image has to be shrunk so that its dimensions are less that maxW and maxH E.g. If the image must be half-sized, this method returns 2.0 (float)

@param imageSize: Size of the image as tuple (width, height) @param maxW: The max width after zooming @param maxH: The max height after zooming @return: The factor by which to shrink the image to be

within max width and height
omero.util.imageUtil.paintThumbnailGrid(thumbnailStore, length, spacing, pixelIds, colCount, bg=(255, 255, 255), leftLabel=None, textColour=(0, 0, 0), fontsize=None, topLabel=None)

Retrieves thumbnails for each pixelId, and places them in a grid, with White background. Option to add a vertical label to the left of the canvas Creates a PIL ‘Image’ which is returned

@param thumbnailStore: The omero thumbnail store. @param length: Length of longest thumbnail side. int @param spacing: The spacing between thumbnails and around the

edges. int

@param pixelIds: List of pixel IDs. [long] @param colCount: The number of columns. int @param bg: Background colour as (r,g,b).

Default is white (255,255,255)

@param leftLabel: Optional string to display vertically to the left. @param textColour: The colour of the text as (r,g,b).

Default is black (0,0,0)
@param fontsize: Size of the font.
Default is calculated based on thumbnail length. int

@return: The PIL Image canvas.

omero.util.imageUtil.pasteImage(image, canvas, x, y)

Pastes the image onto the canvas at the specified coordinates Image and canvas are instances of PIL ‘Image’

@param image: The PIL image to be pasted. Image @param canvas: The PIL image on which to paste. Image @param x: X coordinate (left) to paste @param y: Y coordinate (top) to paste

omero.util.imageUtil.resizeImage(image, maxW, maxH)

Resize the image so that it is as big as possible, within the dimensions maxW, maxH

@param image: The PIL Image to zoom @param maxW: The max width of the zoomed image @param maxH: The max height of the zoomed image @return: The zoomed image. PIL Image.

omero.util.image_utils module

Utility methods for dealing with scripts.

omero.util.image_utils.check_rgb_range(value)

Checks that the value is between 0 and 255. Returns integer value If the value is not valid, return 255 (better to see something than nothing!)

@param value: The value to check. @return: An integer between 0 and 255

omero.util.image_utils.get_font(fontsize)

Returns a PIL ImageFont Sans-serif true-type font of the specified size or a pre-compiled font of fixed size if the ttf font is not found

@param fontsize: The size of the font you want @return: A PIL Font

omero.util.image_utils.get_zoom_factor(image_size, max_width, max_height)

Returns the factor by which the Image has to be shrunk so that its dimensions are less that max_width and max_height e.g. if the image must be half-sized, this method returns 2.0 (float)

@param image_size: Size of the image as tuple (width, height) @param max_width: The max width after zooming @param max_height: The max height after zooming @return: The factor by which to shrink the image to be

within max width and height
omero.util.image_utils.int_to_rgba(rgba)

Returns a tuple of (r,g,b,a) from an integer color r, g, b, a are 0-255.

@param rgba: A color as integer. Int @return: A tuple of (r,g,b,a)

omero.util.image_utils.paint_thumbnail_grid(thumbnail_store, length, spacing, pixel_ids, col_count, bg=(255, 255, 255), left_label=None, text_color=(0, 0, 0), fontsize=None, top_label=None)

Retrieves thumbnails for each pixelId, and places them in a grid, with White background. Option to add a vertical label to the left of the canvas Creates a PIL ‘Image’ which is returned

@param thumbnail_store: The omero thumbnail store. @param length: Length of longest thumbnail side, int @param spacing: The spacing between thumbnails and around the

edges. int

@param pixel_ids: List of pixel IDs. [long] @param col_count: The number of columns. int @param bg: Background colour as (r,g,b).

Default is white (255, 255, 255)

@param left_label: Optional string to display vertically to the left. @param text_color: The color of the text as (r,g,b).

Default is black (0, 0, 0)
@param fontsize: Size of the font.
Default is calculated based on thumbnail length, int

@return: The PIL Image canvas.

omero.util.image_utils.paste_image(image, canvas, x, y)

Pastes the image onto the canvas at the specified coordinates Image and canvas are instances of PIL ‘Image’

@param image: The PIL image to be pasted. Image @param canvas: The PIL image on which to paste. Image @param x: X coordinate (left) to paste @param y: Y coordinate (top) to paste

omero.util.image_utils.resize_image(image, max_width, max_height)

Resize the image so that it is as big as possible, within the dimensions max_width, max_height

@param image: The PIL Image to zoom @param max_width: The max width of the zoomed image @param max_height: The max height of the zoomed image @return: The zoomed image. PIL Image.

omero.util.import_candidates module

Utility method for calling the equivalent of “bin/omero import -f”. Results are parsed when using as_dictionary.

Copyright 2009 Glencoe Software, Inc. All rights reserved. Use is subject to license terms supplied in LICENSE.txt

omero.util.import_candidates._to_list(path)

Guarantees that a list of strings will be returned. Handles unicode caused by “%s” % path.path.

omero.util.import_candidates.as_dictionary(path, readers='')

Run as_stdout, parses the output and returns a dictionary of the form:

{
    some_file_in_group :
        [
            some_file_in_group
            some_other_file_in_group
            ...
            last_file_in_group
        ],
    some_file_in_second_group : ...
}
omero.util.import_candidates.as_stdout(path, readers='')

omero.util.importperf module

omero.util.metadata_mapannotations module

Utilities for manipulating map-annotations used as metadata

class omero.util.metadata_mapannotations.CanonicalMapAnnotation(ma, primary_keys=None)

Bases: object

A canonical representation of a map-annotation for metadata use This is based around the idea of a primary key derived from the combination of the namespace with 1+ keys-value pairs. A null namespace is treated as an empty string (‘’), but still forms part of the primary key.

ma: The omero.model.MapAnnotation object primary_keys: Keys from key-value pairs that will be used to form the

primary key.
add_parent(parenttype, parentid)

Add a parent descriptor Parameter types are important because they are used in a set

parenttype: An OMERO type string parentid: An OMERO object ID (integer)

get_mapann()

Update and return an omero.model.MapAnnotation with merged/combined fields

get_parents()
merge(other)

Adds any key/value pairs from other that aren’t in self Adds parents from other Does not update primary key

merge_parents(other)
process_keypairs(kvpairs, primary_keys)
class omero.util.metadata_mapannotations.MapAnnotationManager(combine=0)

Bases: object

Handles creation and de-duplication of MapAnnotations

MA_APPEND = 0
MA_NEW = 2
MA_OLD = 1
add(cma)

Adds a CanonicalMapAnnotation to the managed list.

Returns any CanonicalMapAnnotation that are no longer required, this may be cma or it may be a previously added annotation. The idea is that this can be used to de-duplicate existing OMERO MapAnnotations by calling add() on all MapAnnotations and deleting those which are returned

If MapAnnotations are combined the parents of the unwanted MapAnnotations are appended to the one that is kept by the manager.

Parameters:cma – A CanonicalMapAnnotation
add_from_namespace_query(session, ns, primary_keys)

Fetches all map-annotations with the given namespace This will only work if there are no duplicates, otherwise an exception will be thrown

WARNING: You should probably only use this in MA_APPEND mode since the parents of existing annotations aren’t fetched (requires a query for each parent type) WARNING: This may be resource intensive TODO: Use omero.utils.populate_metadata._QueryContext for batch queries

Parameters:
  • session – An OMERO session
  • ns – The namespace
  • primary_keys – Primary keys
get_map_annotations()
exception omero.util.metadata_mapannotations.MapAnnotationPrimaryKeyException(message)

Bases: exceptions.Exception

omero.util.metadata_utils module

Utilities for manipulating bulk-annotations

Includes classes to help with basic data-munging (TODO), and for formatting data for clients.

class omero.util.metadata_utils.BulkAnnotationConfiguration(default_cfg, column_cfgs)

Bases: object

Parent class for handling bulk-annotation column configurations

GROUPREQUIRED = set(['namespace', 'columns'])
OPTIONAL = set(['omitempty', 'type', 'visible', 'split', 'clientvalue', 'position', 'include', 'includeclient', 'clientname'])
REQUIRED = set(['name'])
get_column_config(cfg)

Replace unspecified fields in a column config with defaults If this is a group return a GroupConfig object

static get_default_cfg(cfg)

Get the default column configuration, fill in unspecified fields

classmethod validate_column_config(cfg)

Check whether a column config section is valid, throws Exception if not

classmethod validate_filled_column_config(cfg)

Check whether a column config section is valid after filling all optional fields with defaults

classmethod validate_group_config(cfg)

Check whether a group config section is valid, throws Exception if not Not recursive (doesn’t check columns for validity)

class omero.util.metadata_utils.GroupConfig(namespace, column_cfg)

Bases: object

class omero.util.metadata_utils.KeyValueGroupList(headers, default_cfg, column_cfgs)

Bases: omero.util.metadata_utils.BulkAnnotationConfiguration

Converts bulk-annotation rows into key-value lists

get_group_output_configs(column_cfgs, isdefault)

Get the full set of output column configs for a single group, taking into account specified column positions and columns included/excluded according to the defaults:

  • positioned columns are at the specified index (1-based)

  • gaps between positioned columns are filled with unpositioned columns in order of - Configured but unpositioned columns - Unconfigured columns in order of headers (assuming the default

    config is for them to be included)

  • If there are gaps and no remaining columns to be included raise an exception

get_output_configs()

Get the full set of output column configs including column groups The default set of column configs has an empty namespace

get_transformers()

Return a set of KeyValueListTransformer objects, one for each group

class omero.util.metadata_utils.KeyValueListPassThrough(headers, default_cfg=None, column_cfgs=None)

Bases: object

Converts bulk-annotation rows into key-value lists without any transformation

transform(rowvalues)

Pass through a table row unchanged :param values: A table rows :return: A row in the form

[(k1, v1), (k2, v2), ...]
class omero.util.metadata_utils.KeyValueListTransformer(headers, output_configs, name=None)

Bases: object

Converts bulk-annotation rows into key-value lists

transform(rowvalues)

Transform a table row :param rowvalues: A table row :return: The transformed rows in the form [(k1, v1), (k2, v2), ...].

v* will be a list of length: - 1 in most cases - 0 if omitempty=True and value was empty - 1+ if split option is enabled
static transform1(value, cfg)

Process a single value corresponding to a single table row-column

Returns:The key and a list of [value]. In general [values] will be a single item unless split is specified in cfg in which case there may be multiple.

omero.util.pixelstypetopython module

omero.util.pixelstypetopython.toArray(pixelType)
omero.util.pixelstypetopython.toNumpy(pixelType)
omero.util.pixelstypetopython.toPIL(pixelType)
omero.util.pixelstypetopython.toPython(pixelType)

omero.util.populate_metadata module

Populate bulk metadata tables from delimited text files.

class omero.util.populate_metadata.BulkToMapAnnotationContext(client, target_object, file=None, fileid=None, cfg=None, cfgid=None, attach=False, options=None)

Bases: omero.util.populate_metadata._QueryContext

Processor for creating MapAnnotations from BulkAnnotations.

_create_cmap_annotation(targets, rowkvs, ns)

Converts a CanonicalMapAnnotation object into OMERO MapAnnotations and AnnotationLinks. AnnotationLinks will have the parent and child set, where the child is a single MapAnnotation object shared amongst all links.

If the number of AnnotationLinks is small callers may choose to save the links and MapAnnotation using UpdateService directly, ignoring the second element of the tuple.

If the number of AnnotationLinks is large the caller should first save the MapAnnotation, call setChild on all AnnotationLinks to reference the saved MapAnnotation, and finally save all AnnotationLinks.

This complexity is unfortunately required to avoid going over the Ice message size.

Returns:A tuple of (AnnotationLinks, MapAnnotation)
_get_additional_targets(target)
_get_ns_primary_keys(ns)
_get_selected_namespaces()
_init_namespace_primarykeys()

Save a single Annotation, followed by the AnnotationLinks to that Annotation and return the number of links saved.

All AnnotationLinks must have ann as their child. Links will be saved in batches of batch_size.

See _create_map_annotation_links

Save AnnotationLinks including the child annotation in one go. See _create_map_annotation_links

_write_log(text)
get_bulk_annotation_file()
get_target(target_object)
parse()
populate(table)
write_to_omero(batch_size=1000, loops=10, ms=500)
class omero.util.populate_metadata.DatasetWrapper(value_resolver)

Bases: omero.util.populate_metadata.PDIWrapper

_load()
get_image_id_by_name(iname, dname=None)
class omero.util.populate_metadata.DeleteMapAnnotationContext(client, target_object, file=None, fileid=None, cfg=None, cfgid=None, attach=False, options=None)

Bases: omero.util.populate_metadata._QueryContext

Processor for deleting MapAnnotations in the BulkAnnotations namespace on these types: Image WellSample Well PlateAcquisition Plate Screen

_get_annotations_for_deletion(objtype, objids, anntype, nss, getlink=False)
_get_configured_namespaces()
_write_to_omero_batch(to_delete, loops=10, ms=500)
parse()
populate()
write_to_omero(batch_size=1000, loops=10, ms=500)
class omero.util.populate_metadata.HeaderResolver(target_object, headers, column_types=None)

Bases: object

Header resolver for known header names which is responsible for creating the column set for the OMERO.tables instance.

DEFAULT_COLUMN_SIZE = 1
_create_columns(klass)
columns_sanity_check(columns)
create_columns()
create_columns_dataset()
create_columns_plate()
create_columns_project()
create_columns_screen()
dataset_keys = {'image': <class 'omero.grid.ImageColumn'>, 'image_name': <class 'omero.grid.StringColumn'>}
static get_column_types(row)
static is_row_column_types(row)
plate_keys = {'column': <class 'omero.grid.LongColumn'>, 'field': <class 'omero.grid.ImageColumn'>, 'row': <class 'omero.grid.LongColumn'>, 'well': <class 'omero.grid.WellColumn'>, 'wellsample': <class 'omero.grid.ImageColumn'>}
project_keys = {'image': <class 'omero.grid.ImageColumn'>, 'image_name': <class 'omero.grid.StringColumn'>, 'dataset_name': <class 'omero.grid.StringColumn'>, 'dataset': <class 'omero.grid.DatasetColumn'>}
screen_keys = {'plate': <class 'omero.grid.PlateColumn'>, 'wellsample': <class 'omero.grid.ImageColumn'>, 'field': <class 'omero.grid.ImageColumn'>, 'column': <class 'omero.grid.LongColumn'>, 'well': <class 'omero.grid.WellColumn'>, 'row': <class 'omero.grid.LongColumn'>}
class omero.util.populate_metadata.ImageData(image)

Bases: object

Largely “mock” object which is intended to simulate the data returned by querying a Image but without the overhead of storing all the Ice fields.

exception omero.util.populate_metadata.MetadataError

Bases: exceptions.Exception

Raised by the metadata parsing context when an error condition is reached.

class omero.util.populate_metadata.PDIWrapper(value_resolver)

Bases: omero.util.populate_metadata.ValueWrapper

get_image_id_by_name(iname, dname=None)
class omero.util.populate_metadata.ParsingContext(client, target_object, file=None, fileid=None, cfg=None, cfgid=None, attach=False, column_types=None, options=None)

Bases: object

Generic parsing context for CSV files.

get_column_widths()
parse()
parse_from_handle(data)
populate(rows)
post_process()
write_to_omero(batch_size=1000, loops=10, ms=500)
class omero.util.populate_metadata.PlateData(plate)

Bases: object

Largely “mock” object which is intended to simulate the data returned by querying a Plate but without the overhead of storing all the Ice fields.

class omero.util.populate_metadata.PlateWrapper(value_resolver)

Bases: omero.util.populate_metadata.SPWWrapper

_load()
get_well_by_id(well_id, plate=None)
subselect(rows, names)

If we’re processing a plate but the bulk-annotations file contains a plate column then select rows for this plate only

class omero.util.populate_metadata.ProjectWrapper(value_resolver)

Bases: omero.util.populate_metadata.PDIWrapper

_load()
get_image_id_by_name(iname, dname=None)
class omero.util.populate_metadata.SPWWrapper(value_resolver)

Bases: omero.util.populate_metadata.ValueWrapper

get_well_by_id(well_id, plate=None)
parse_plate(plate, wells_by_location, wells_by_id, images_by_id)

Accepts PlateData instances

resolve_well(column, row, value)
class omero.util.populate_metadata.ScreenWrapper(value_resolver)

Bases: omero.util.populate_metadata.SPWWrapper

_load()
get_plate_name_by_id(plate)
get_well_by_id(well_id, plate=None)
resolve_plate(column, row, value)
class omero.util.populate_metadata.Skip

Bases: object

Instance to denote a row skip request.

class omero.util.populate_metadata.ValueResolver(client, target_object)

Bases: object

Value resolver for column types which is responsible for filling up non-metadata columns with their OMERO data model identifiers.

AS_ALPHA = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'ag', 'ah', 'ai', 'aj', 'ak', 'al', 'am', 'an', 'ao', 'ap', 'aq', 'ar', 'as', 'at', 'au', 'av', 'aw', 'ax', 'ay', 'az']
WELL_REGEX = <_sre.SRE_Pattern object at 0x31fa6c30>
get_image_id_by_name(iname, dname=None)
get_plate_name_by_id(plate)
get_well_name(well_id, plate=None)
resolve(column, value, row)
subselect(valuerows, names)
v = 122
class omero.util.populate_metadata.ValueWrapper(value_resolver)

Bases: object

subselect(rows, names)
class omero.util.populate_metadata.WellData(well)

Bases: object

Largely “mock” object which is intended to simulate the data returned by querying a Well but without the overhead of storing all the Ice fields.

class omero.util.populate_metadata.WellSampleData(well_sample)

Bases: object

Largely “mock” object which is intended to simulate the data returned by querying a WellSample but without the overhead of storing all the Ice fields.

class omero.util.populate_metadata._QueryContext(client)

Bases: object

Helper class container query methods

_batch(i, sz=1000)

Generate batches of size sz (by default 1000) from the input iterable i.

_grouped_batch(groups, sz=1000)

In some cases groups of objects must be kept together. This method attempts to return up to sz objects without breaking up groups. If a single group is greater than sz the whole group is returned. Callers are responsible for checking the size of the returned batch.

Parameters:groups – an iterable of lists/tuples of objects
Returns:a list of the next batch of objects, if a single group has more than sz elements it will be returned as a single over-sized batch
projection(q, ids, nss=None, batch_size=None)

Run a projection query designed to return scalars only :param q: The query to be projected, should contain either :ids

or :id as a parameter
Param:ids: Either a list of IDs to be passed as :ids parameter or a single scalar id to be passed as :id parameter in query
Nss:Optional, Either a list of namespaces to be passed as :nss parameter or a single string to be passed as :ns parameter in query
Batch_size:Optional batch_size (default: all) defining the number of IDs that will be queried at once. Methods that expect to have more than several thousand input IDs should consider an appropriate batch size. By default, however, no batch size is applied since this could change the interpretation of the query string (e.g. use of distinct).
omero.util.populate_metadata.get_config(session, cfg=None, cfgid=None)
omero.util.populate_metadata.parse_column_types(column_type_list)
omero.util.populate_metadata.parse_target_object(target_object)
omero.util.populate_metadata.usage(error)

Prints usage so that we don’t have to. :)

omero.util.populate_roi module

...

class omero.util.populate_roi.AbstractMeasurementCtx(analysis_ctx, service_factory, original_file_provider, original_file, result_files)

Bases: object

Abstract class which aggregates and represents all the results produced from a given measurement run. It also provides a scaffold for interacting with the OmeroTables infrastructure.

ROI_UPDATE_LIMIT = 1000
create_file_annotation(set_of_columns)

Creates a file annotation to represent a set of columns from our measurment.

get_name(set_of_columns=None)

Returns the name of the measurement, and a set of columns.

get_well_images(row, col)

Takes a row and a col index and returns a tuple of Well and image. Either might be None. Uses the first image found to find the Well and therefore must be loaded (image->wellSample->well)

image_from_original_file(original_file)

Returns the image from which an original file has originated.

parse()

Parses result files, returning a MeasurementParsingResult.

parse_and_populate()

Calls parse and populate, updating the OmeroTables instance backing our results and the OMERO database itself.

parse_and_populate_roi(columns)

Parses and populates ROI from column data in the OMERO database.

populate(columns)

Populates an OmeroTables instance backing our results and ROI linkages.

update_rois(rois, batches, batch_no)

Updates a set of ROI for a given batch updating the batches dictionary with the saved IDs.

update_table(columns)

Updates the OmeroTables instance backing our results.

class omero.util.populate_roi.AbstractPlateAnalysisCtx(images, original_files, original_file_image_map, plate_id, service_factory)

Bases: object

Abstract class which aggregates and represents all measurement runs made on a given Plate.

DEFAULT_ORIGINAL_FILE_PROVIDER

alias of DownloadingOriginalFileProvider

colrow_from_wellnumber(width, wellnumber)
get_measurement_count()

Returns the number of recognized measurement runs.

get_measurement_ctx(index)

Returns the measurement context for a given index.

get_result_file_count(measurement_index)

Return the number of result files associated with a measurement run.

guess_geometry(images)
image_from_wellnumber(wellnumber)
classmethod is_this_type(klass)

Concrete implementations are to return True if the class pertinent for the original files associated with the plate.

class omero.util.populate_roi.DownloadingOriginalFileProvider(service_factory)

Bases: object

Provides original file data by downloading it from an OMERO raw file store.

BUFFER_SIZE = 1048576
get_original_file_data(original_file)

Downloads an original file to a temporary file and returns an open file handle to that temporary file seeked to zero. The caller is responsible for closing the temporary file.

class omero.util.populate_roi.FlexMeasurementCtx(analysis_ctx, service_factory, original_file_provider, original_file, result_files)

Bases: omero.util.populate_roi.AbstractMeasurementCtx

Flex measurements are located deep within a ”.res” XML file container and contain no ROI.

AREA_XPATH = './/Areas/Area'
PARAMETER_XPATH = './/Wells/ResultParameters/Parameter'
RESULT_XPATH = './/Result'
WELL_XPATH = './/Wells/Well'
get_empty_columns(headers)

Retrieves a set of empty OmeroTables columns for the analysis results prefixed by a WellColumn to handle linked object indexes.

get_name(set_of_columns=None)
parse()
parse_and_populate_roi(columns)
populate(columns)
class omero.util.populate_roi.FlexPlateAnalysisCtx(images, original_files, original_file_image_map, plate_id, service_factory)

Bases: omero.util.populate_roi.AbstractPlateAnalysisCtx

Flex dataset concrete class implementation of an analysis context. Flex measurements are aggregated in a single ”.res” XML file and contain no ROI.

companion_format = 'Companion/Flex'
get_measurement_count()
get_measurement_ctx(index)
get_result_file_count(measurement_index)
classmethod is_this_type(klass, original_files)
class omero.util.populate_roi.InCellMeasurementCtx(analysis_ctx, service_factory, original_file_provider, original_file, result_files)

Bases: omero.util.populate_roi.AbstractMeasurementCtx

InCell Analyzer measurements are located deep within an XML file container.

CELLS_CG_EXPECTED = ['Cell: cgX', 'Cell: cgY']
CELLS_SOURCE = 'Cells'
NUCLEI_CG_EXPECTED = ['Nucleus: cgX', 'Nucleus: cgY']
NUCLEI_SOURCE = 'Nuclei'
ORGANELLES_SOURCE = 'Organelles'
check_sparse_data(columns)

Checks a set of columns for sparse data (one column shorter than the rest) and adds -1 where appropriate.

get_name(set_of_columns=None)
parse()
parse_and_populate_roi(columns_as_list)
populate(columns)
class omero.util.populate_roi.InCellPlateAnalysisCtx(images, original_files, original_file_image_map, plate_id, service_factory)

Bases: omero.util.populate_roi.AbstractPlateAnalysisCtx

InCell dataset concrete class implementation of an analysis context. InCell measurements are from InCell Analyzer and are aggregated in a single gargantuan (often larger than 100MB per plate) XML file.

companion_format = 'Companion/InCell'
get_measurement_count()
get_measurement_ctx(index)
get_result_file_count(measurement_index)
classmethod is_this_type(klass, original_files)
class omero.util.populate_roi.MIASMeasurementCtx(analysis_ctx, service_factory, original_file_provider, original_file, result_files)

Bases: omero.util.populate_roi.AbstractMeasurementCtx

MIAS measurements are a set of tab delimited text files per well. Each TSV file’s content is prefixed by the analysis parameters.

IMAGE_COL = 0
MNU_EXPECTED = ('Image', 'ROI', 'row', 'col', 'type')
NEO_EXPECTED = ('Image', 'ROI', 'Label', 'Row', 'Col', 'Nucleus Area', 'Cell Diam.', 'Cell Type', 'Mean Nucleus Intens.')
ROI_COL = 1
_parse_mnu_roi(columns)

Parses out ROI from OmeroTables columns for ‘MNU’ datasets.

_parse_neo_roi(columns)

Parses out ROI from OmeroTables columns for ‘NEO’ datasets.

get_empty_columns(n_columns)

Retrieves a set of empty OmeroTables columns for the analysis results prefixed by an ImageColumn and RoiColumn to handle these linked object indexes.

get_name(set_of_columns=None)
image_from_original_file(original_file)

Overriding the abstract implementation since the companion files are no longer attached to the images, but only to the plate for MIAS. Instead, we use the filename itself to find the image.

parse()
parse_and_populate_roi(columns)
populate(columns)

Query performed:

first_roi = columns[self.ROI_COL].values[0]
first_roi = self.query_service.findByQuery(
        'select roi from Roi as roi '                         'join fetch roi.annotationLinks as link '                         'join fetch link.child '                         'where roi.id = %d' % first_roi, None)
self.file_annotation = first_roi.copyAnnotationLinks()[0].child
class omero.util.populate_roi.MIASPlateAnalysisCtx(images, original_files, original_file_image_map, plate_id, service_factory)

Bases: omero.util.populate_roi.AbstractPlateAnalysisCtx

MIAS dataset concrete class implementation of an analysis context. MIAS measurements are aggregated based on a single “log” file. A result file is present for each stitched (of multiple fields) mosaic and contains the actual measured results and ROI.

_populate_log_and_detail_files()

Strips out erroneous files and collects the log and result original files based on regular expression matching.

_populate_measurements()

Result original files are only recognizable as part of a given measurement (declared by a log file) based upon their parsed date/time of completion as encoded in the filename. This method collects result original files and groups them by collective parsed date/time of completion.

companion_format = 'Companion/MIAS'
datetime_format = '%Y-%m-%d-%Hh%Mm%Ss'
detail_regex = <_sre.SRE_Pattern object at 0x1c59f270>
get_measurement_count()
get_measurement_ctx(index)
get_result_file_count(measurement_index)
classmethod is_this_type(klass, original_files)
log_regex = <_sre.SRE_Pattern object at 0x1c2b94d0>
exception omero.util.populate_roi.MeasurementError

Bases: exceptions.Exception

Raised by the analysis or measurement context when an error condition is reached.

class omero.util.populate_roi.MeasurementParsingResult(sets_of_columns=None)

Bases: object

Holds the results of a measurement parsing event.

append_columns(columns)

Adds a set of columns to the parsing result.

class omero.util.populate_roi.PlateAnalysisCtxFactory(service_factory)

Bases: object

The plate analysis context factory is responsible for detecting and returning a plate analysis context instance for a given plate.

find_filesets_for_plate(plateid)

OMERO5 support. See #12235

find_images_for_plate(plate_id)

Retrieves all the images associated with a given plate. Fetched are the Image’s WellSample, the WellSample’s Well, the annotation stack associated with the Image and each annotation’s linked original file.

gather_original_files(obj, original_files, original_file_obj_map)
get_analysis_ctx(plate_id)

Retrieves a plate analysis context for a given plate.

implementations = (<class 'omero.util.populate_roi.FlexPlateAnalysisCtx'>, <class 'omero.util.populate_roi.MIASPlateAnalysisCtx'>, <class 'omero.util.populate_roi.InCellPlateAnalysisCtx'>)
class omero.util.populate_roi.ThreadPool(num_threads)

Pool of threads consuming tasks from a queue

add_task(func, *args, **kargs)

Add a task to the queue

wait_completion()

Wait for completion of all the tasks in the queue

class omero.util.populate_roi.Worker(tasks)

Bases: threading.Thread

Thread executing tasks from a given tasks queue

run()
omero.util.populate_roi.get_thread_pool()
omero.util.populate_roi.usage(error)

Prints usage so that we don’t have to. :)

omero.util.pydict_text_io module

Read text-based dictionary file formats such as YAML and JSON

omero.util.pydict_text_io._format_from_name(filename)
omero.util.pydict_text_io.dump(data, formattype)

Convert a python object to a string in the requested format

data: A python object (most likely a dictionary) formattype: The output format

omero.util.pydict_text_io.get_format_filename(filename, filetype)
omero.util.pydict_text_io.get_format_originalfileid(originalfileid, filetype, session)
omero.util.pydict_text_io.get_supported_formats()

Return the supported formats

omero.util.pydict_text_io.load(fileobj, filetype=None, single=True, session=None)

Try and load a file in a format that is convertible to a Python dictionary

fileobj: Either a single json object string, file-path, or OriginalFile:ID single: If True file should only contain a single document, otherwise a

list of documents will always be returned. Multiple documents are not supported for JSON strings.

session: If fileobj is an OriginalFile:ID a valid session is required

omero.util.roi_handling_utils module

Utility methods for manipulating roi.

omero.util.roi_handling_utils.get_line_data(pixels, x1, y1, x2, y2, line_w=2, the_z=0, the_c=0, the_t=0)

Grabs pixel data covering the specified line, and rotates it horizontally so that x1,y1 is to the left, Returning a numpy 2d array. Used by Kymograph.py script. Uses PIL to handle rotating and interpolating the data. Converts to numpy to PIL and back (may change dtype.)

@param pixels: PixelsWrapper object @param x1, y1, x2, y2: Coordinates of line @param line_w: Width of the line we want @param the_z: Z index within pixels @param the_c: Channel index @param the_t: Time index

omero.util.roi_handling_utils.points_string_to_xy_list(string)

Method for converting the string returned from omero.model.ShapeI.getPoints() into list of (x,y) points e.g. “points[309,427, 366,503, 190,491]”

omero.util.script_utils module

Utility methods for dealing with scripts.

omero.util.script_utils.IdentityFn(commandArgs)
omero.util.script_utils.RGBToPIL(RGB)

Convert an RGB value to a PIL colour value. @param RGB the RGB value. @return See above.

omero.util.script_utils.addAnnotationToImage(updateService, image, annotation)

Add the annotation to an image. @param updateService The update service to create the annotation link. @param image The ImageI object that should be annotated. @param annotation The annotation object @return The new annotationlink object

omero.util.script_utils.arrayToCSV(data)

Convert the numpy array data to a csv file. @param data the Numpy Array @return The CSV string.

omero.util.script_utils.attachArrayToImage(updateService, image, file, nameSpace)

Attach an array, stored as a csv file to an image. Returns the annotation. @param updateService The updateService to create the annotation link. @param image The image to attach the data to. @param filename The name of the file. @param namespace The namespace of the file. @return

omero.util.script_utils.attachFileToParent(updateService, parent, originalFile, description=None, namespace=None)

Attaches the original file (file) to a Project, Dataset or Image (parent)

@param updateService: The update service @param parent: A ProjectI, DatasetI or ImageI to attach

the file to

@param originalFile: The OriginalFileI to attach @param description: Optional description for the file annotation.

String

@param namespace: Optional namespace for file annotataion. String @return: The saved and returned *AnnotationLinkI

(* = Project, Dataset or Image)
omero.util.script_utils.calcSha1(filename)
omero.util.script_utils.calcSha1FromData(data)
omero.util.script_utils.calc_sha1(filename)

Returns a hash of the file identified by filename

@param filename: pathName of the file @return: The hash of the file

omero.util.script_utils.convert_numpy_array(plane, min_max, type)

Converts the numpy plane to a PIL Image, converting data type if necessary. @param plane The plane to handle @param min_max the min and the max values for the plane @param type the data type to use for scaling

omero.util.script_utils.createFile(updateService, filename, mimetype=None, origFilePathName=None)

Creates an original file, saves it to the server and returns the result

@param queryService: The query service E.g. session.getQueryService() @param updateService: The update service E.g. session.getUpdateService() @param filename: The file path and name (or name if in same folder).

String
@param mimetype: The mimetype (string) or Format object representing
the file format

@param origFilePathName: Optional path/name for the original file @return: The saved OriginalFileI, as returned from the

server
omero.util.script_utils.createFileFromData(updateService, queryService, filename, data)

Create a file from the data of type format, setting sha1, .. @param updateService The updateService to create the annotation link. @param filename The name of the file. @param data The data to save. @param format The Format of the file. @return The newly created OriginalFile.

omero.util.script_utils.createLinkFileAnnotation(conn, localPath, parent, output='Output', parenttype='Image', mimetype=None, desc=None, ns=None, origFilePathAndName=None)

Uploads a local file to the server, as an Original File and attaches it to the parent (Project, Dataset or Image)

@param conn: The omero.gateway.BlitzGateway connection. @param parent: The ProjectI or DatasetI or ImageI to attach

file to
@param localPath: Full Name (and path) of the file location
to upload. String

@param mimetype: The original file mimetype. E.g. “PNG”. String @param description: Optional description for the file annotation.

String

@param namespace: Namespace to set for the original file @param @param origFilePathName: The /path/to/file/fileName.ext you want on the

server. If none, use output as name
@return: The originalFileLink child (FileAnnotationI)
and a log message
omero.util.script_utils.createNewImage(session, plane2Dlist, imageName, description, dataset=None)

Creates a new single-channel, single-timepoint image from the list of 2D numpy arrays in plane2Dlist with each numpy 2D plane becoming a Z-section.

@param session An OMERO service factory or equivalent
with getQueryService() etc.
@param plane2Dlist A list of numpy 2D arrays,
corresponding to Z-planes of new image.

@param imageName Name of new image @param description Description for the new image @param dataset If specified, put the image in this dataset.

omero.model.Dataset object

@return The new OMERO image: omero.model.ImageI

omero.util.script_utils.createPlaneDef(z, t)

Create the plane rendering def, for z,t @param Z the Z-Section @param T The T-Point. @return The RenderingDef Object.

omero.util.script_utils.create_file(update_service, filename, mimetype=None, orig_file_path_name=None)

Creates an original file, saves it to the server and returns the result

@param update_service: The update service e.g. session.getUpdateService() @param filename: The file path and name (or name if in same folder).

String
@param mimetype: The mimetype (string) or Format object representing
the file format

@param orig_file_path_name: Optional path/name for the original file @return: The saved OriginalFileI, as returned from the

server

Uploads a local file to the server, as an Original File and attaches it to the parent (Project, Dataset or Image)

@param conn: The omero.gateway.BlitzGateway connection. @param local_path: Full Name (and path) of the file location

to upload. String
@param parent: The ProjectI or DatasetI or ImageI to attach
file to

@param mimetype: The original file mimetype e.g. “PNG”. String @param description: Optional description for the file annotation.

String

@param namespace: Namespace to set for the original file @param orig_file_path_and_name: The /path/to/file/fileName.ext you want

on the server. If none, use output as name
@return: The originalFileLink child (FileAnnotationI)
and a log message
omero.util.script_utils.downloadFile(rawFileStore, originalFile, filePath=None)

Downloads an OriginalFile from the server.

@param rawFileStore: The Omero rawFileStore @param originalFile: The OriginalFileI @param filePath: Where to download the file.

If None, use originalFile.getName().getValue()
omero.util.script_utils.downloadPlane(rawPixelsStore, pixels, z, c, t)

Download the plane [z,c,t] for image pixels. Pixels must have pixelsType loaded. N.B. The rawPixelsStore must have already been initialised by setPixelsId() @param rawPixelsStore The rawPixelStore service to get the image. @param pixels The pixels of the image. @param z The Z-Section to retrieve. @param c The C-Section to retrieve. @param t The T-Section to retrieve. @return The Plane of the image for z, c, t

omero.util.script_utils.download_file(raw_file_store, original_file, file_path=None)

Downloads an OriginalFile from the server.

@param raw_file_store: The Omero rawFileStore @param original_file: The OriginalFileI @param file_path: Where to download the file.

If None, use original_file.getName().getValue()
omero.util.script_utils.download_plane(raw_pixels_store, pixels, z, c, t)

Download the plane [z, c, t] for image pixels. Pixels must have pixelsType loaded. N.B. The rawPixelsStore must have already been initialised by setPixelsId() @param raw_pixels_store The rawPixelStore service to get the image. @param pixels The pixels of the image. @param z The Z-Section to retrieve. @param c The channel to retrieve. @param t The timepoint to retrieve. @return The Plane of the image for z, c, t

omero.util.script_utils.drawLineOverlay(draw, x0, y0, x1, y1, colour='0xffffff')

Draw line on image. @param draw The PIL Draw class. @param x0 The x0-coord of line. @param y0 The y0-coord of line. @param x1 The x1-coord of line. @param y1 The y1-coord of line. @param colour The colour as a PIL colour fill in the line.

omero.util.script_utils.drawTextOverlay(draw, x, y, text, colour='0xffffff')

Draw test on image. @param draw The PIL Draw class. @param x The x-coord to draw. @param y The y-coord to draw. @param text The text to render. @param colour The colour as a PIL colour string to draw the text in.

omero.util.script_utils.findROIByImage(roiService, image, namespace)

Finds the ROI with the given namespace linked to the image. Returns a collection of ROIs. @param roiService The ROI service. @param image The image the ROIs are linked to . @param namespace The namespace of the ROI. @return see above.

omero.util.script_utils.getFormat(queryService, format)
omero.util.script_utils.getObjects(conn, params)

Get the objects specified by the script parameters. Assume the parameters contain the keys IDs and Data_Type

@param conn: The omero.gateway.BlitzGateway connection. @param params: The script parameters @return: The valid objects and a log message

omero.util.script_utils.getPlaneAsPackedInt(renderingEngine, z, t)

Get the rendered Image of the plane for the z, t with the default channels. @param renderingEngine The already instantiated renderEngine. @param z The Z-section. @param t The Timepoint.

omero.util.script_utils.getPlaneFromImage(imagePath, rgbIndex=None)

Reads a local image (E.g. single plane tiff) and returns it as a numpy 2D array.

@param imagePath Path to image.

omero.util.script_utils.getPlaneInfo(iQuery, pixelsId, asOrderedList=True)

Get the plane info for the pixels object returning it in order of z,t,c @param iQuery The query service. @param pixelsId The pixels for Id. @param asOrderedList @return list of planeInfoTimes or map[z:t:c:]

omero.util.script_utils.getROIFromImage(iROIService, imageId)

Get the ROI from the server for the image with the namespace @param iROIService The iROIService object @param imageId The imageId to retreive ROI from. @param namespace The namespace of the ROI. @return See above.

omero.util.script_utils.getRawFileStore(session, fileId)

Get the rawFileStore for the file with fileId @param fileId The fileId of the object to retrieve. @return The rawFileStore service.

omero.util.script_utils.getRawPixelsStore(session, pixelsId)

Get the rawPixelsStore for the Image with pixelsId @param pixelsId The pixelsId of the object to retrieve. @return The rawPixelsStore service.

omero.util.script_utils.getRenderingEngine(session, pixelsId)

Create the renderingEngine for the pixelsId. @param session The current session to create the renderingEngine from. @return The renderingEngine Service for the pixels.

omero.util.script_utils.get_objects(conn, params)

Get the objects specified by the script parameters. Assume the parameters contain the keys IDs and Data_Type

@param conn: The omero.gateway.BlitzGateway connection. @param params: The script parameters @return: The valid objects and a log message

omero.util.script_utils.numpy_save_as_image(plane, min_max, dtype, name)

Converts the numpy plane, converting data type if necessary and saves it as png, jpeg etc. @param plane The plane to handle @param min_max the min and the max values for the plane @param type the data type to use for scaling @param name the name of the image

omero.util.script_utils.numpy_to_image(plane, min_max, dtype)

Converts the numpy plane to a PIL Image, converting data type if necessary. @param plane The plane to handle @param min_max the min and the max values for the plane @param dtype the data type to use for scaling

omero.util.script_utils.parseInputs(client, session=None, processFn=<function IdentityFn at 0x1e171ed8>)

parse the inputs from the client object and map it to some other form, values may be transformed by function. @param client The client object @param session The current session (deprecated). @param processFn A function to transform data to some other form. @return Parsed inputs as defined by ProcessFn.

omero.util.script_utils.rangeToStr(range)

Map a range to a string of numbers @param range See above. @return See above.

omero.util.script_utils.readFileAsArray(rawFileService, iQuery, fileId, row, col, separator=' ')

Read an OriginalFile with id and column separator and return it as an array. @param rawFileService The RawFileService service to read the originalfile. @param iQuery The Query Service. @param fileId The id of the originalFile object. @param row The number of rows in the file. @param col The number of columns in the file. @param sep the column separator. @return The file as an NumPy array.

omero.util.script_utils.readFlimImageFile(rawPixelsStore, pixels)

Read the RawImageFlimFile with fileId and return it as an array [c, x, y] @param rawPixelsStore The rawPixelStore service to get the image. @param pixels The pixels of the image. @return The Contents of the image for z = 0, t = 0, all channels;

omero.util.script_utils.readFromOriginalFile(rawFileService, iQuery, fileId, maxBlockSize=10000)

Read the OriginalFile with fileId and return it as a string. @param rawFileService The RawFileService service to read the originalfile. @param iQuery The Query Service. @param fileId The id of the originalFile object. @param maxBlockSize The block size of each read. @return The OriginalFile object contents as a string

omero.util.script_utils.registerNamespace(iQuery, iUpdate, namespace, keywords)

Register a workflow with the server, if the workflow does not exist create it and returns it, otherwise it returns the already created workflow. @param iQuery The query service. @param iUpdate The update service. @param namespace The namespace of the workflow. @param keywords The keywords associated with the workflow. @return see above.

omero.util.script_utils.resetRenderingSettings(renderingEngine, pixelsId, cIndex, minValue, maxValue, rgba=None)

Simply resests the rendering settings for a pixel set, according to the min and max values The rendering engine does NOT have to be primed with pixelsId, as that is handled by this method.

@param renderingEngine The OMERO rendering engine @param pixelsId The Pixels ID @param minValue Minimum value of rendering window @param maxValue Maximum value of rendering window @param rgba Option to set the colour of the channel.

(r,g,b,a) tuple.
omero.util.script_utils.reset_rendering_settings(rendering_engine, pixels_id, c_index, min_value, max_value, rgba=None)

Simply resets the rendering settings for a pixel set, according to the min and max values The rendering engine does NOT have to be primed with pixels_id, as that is handled by this method.

@param rendering_engine The OMERO rendering engine @param pixels_id The Pixels ID @param c_index The channel index. @param min_value Minimum value of rendering window @param max_value Maximum value of rendering window @param rgba Option to set the color of the channel.

(r,g,b,a) tuple.
omero.util.script_utils.rgbToRGBInt(red, green, blue)

Convert an R,G,B value to an int. @param R the Red value. @param G the Green value. @param B the Blue value. @return See above.

omero.util.script_utils.rmdir_recursive(dir)
omero.util.script_utils.split_image(client, imageId, dir, unformattedImageName='tubulin_P037_T%05d_C%s_Z%d_S1.tif', dims=('T', 'C', 'Z'))

Splits the image into component planes, which are saved as local tiffs according to unformattedImageName e.g. myLocalDir/tubulin_P037_T%05d_C%s_Z%d_S1.tif which will be formatted according to dims e.g. (‘T’, ‘C’, ‘Z’) Channel will be formatted according to channel name, not index. @param client The client to use @param imageId The image’s ID @param dir Where to save the split images @param unformattedImageName The name to use @param dims The timepoint, channel, z-section to use

omero.util.script_utils.toCSV(list)

Convert a list to a Comma Separated Value string. @param list The list to convert. @return See above.

omero.util.script_utils.toList(csvString)

Convert a csv string to a list of strings @param csvString The CSV string to convert. @return See above.

omero.util.script_utils.uploadAndAttachFile(queryService, updateService, rawFileStore, parent, localName, mimetype, description=None, namespace=None, origFilePathName=None)

Uploads a local file to the server, as an Original File and attaches it to the parent (Project, Dataset or Image)

@param queryService: The query service @param updateService: The update service @param rawFileStore: The rawFileStore @param parent: The ProjectI or DatasetI or ImageI to attach

file to
@param localName: Full Name (and path) of the file location
to upload. String

@param mimetype: The original file mimetype. E.g. “PNG”. String @param description: Optional description for the file annotation.

String

@param namespace: Namespace to set for the original file @param origFilePathName: The /path/to/file/fileName.ext you want on the

server. If none, use output as name

@return: The originalFileLink child. (FileAnnotationI)

omero.util.script_utils.uploadArray(rawFileStore, updateService, queryService, image, filename, namespace, array)

Upload the data to the server, creating the OriginalFile Object and attaching it to the image. @param rawFileStore The rawFileStore used to create the file. @param updateService The updateService to create the annotation link. @param image The image to attach the data to. @param filename The name of the file. @param namespace The name space associated to the annotation. @param data The data to save. @return The newly created file.

omero.util.script_utils.uploadDirAsImages(sf, queryService, updateService, pixelsService, path, dataset=None)

Reads all the images in the directory specified by ‘path’ and uploads them to OMERO as a single multi-dimensional image, placed in the specified ‘dataset’ Uses regex to determine the Z, C, T position of each image by name, and therefore determines sizeZ, sizeC, sizeT of the new Image.

@param path the path to the directory containing images. @param dataset the OMERO dataset, if we want to put images somewhere.

omero.model.DatasetI
omero.util.script_utils.uploadFile(rawFileStore, originalFile, filePath=None)

Uploads an OriginalFile to the server

@param rawFileStore: The Omero rawFileStore @param originalFile: The OriginalFileI @param filePath: Where to find the file to upload.

If None, use originalFile.getName().getValue()
omero.util.script_utils.uploadPlane(rawPixelsStore, plane, z, c, t)

Upload the plane to the server attaching it to the current z,c,t of the already instantiated rawPixelStore. @param rawPixelsStore The rawPixelStore which is already pointing

to the data.

@param plane The data to upload @param z The Z-Section of the plane. @param c The C-Section of the plane. @param t The T-Section of the plane.

omero.util.script_utils.uploadPlaneByRow(rawPixelsStore, plane, z, c, t)

Upload the plane to the server one row at a time, attching it to the current z,c,t of the already instantiated rawPixelStore. @param rawPixelsStore The rawPixelStore which is already pointing

to the data.

@param plane The data to upload @param z The Z-Section of the plane. @param c The C-Section of the plane. @param t The T-Section of the plane.

omero.util.script_utils.upload_file(raw_file_store, original_file, file_path=None)

Uploads an OriginalFile to the server

@param raw_file_store: The Omero rawFileStore @param original_file: The OriginalFileI @param file_path: Where to find the file to upload.

If None, use original_file.getName().getValue()
omero.util.script_utils.upload_plane(raw_pixels_store, plane, z, c, t)

Upload the plane to the server attaching it to the current z,c,t of the already instantiated rawPixelStore. @param raw_pixels_store The rawPixelStore which is already pointing

to the data.

@param plane The data to upload @param z The Z-Section of the plane. @param c The C-Section of the plane. @param t The T-Section of the plane.

omero.util.script_utils.upload_plane_by_row(raw_pixels_store, plane, z, c, t)

Upload the plane to the server one row at a time, attaching it to the current z,c,t of the already instantiated rawPixelStore. @param raw_pixels_store The rawPixelStore which is already pointing

to the data.

@param plane The data to upload @param z The Z-Section of the plane. @param c The C-Section of the plane. @param t The T-Section of the plane.

omero.util.sessions module

Library for managing user sessions.

class omero.util.sessions.SessionsStore(dir=None)

Bases: object

The store is a file-based repository of user sessions. By default, stores use $HOME/omero/sessions as their repository path.

Use add() to add items to the repository

add(host, name, id, props, sudo=None)

Stores a file containing the properties at REPO/host/name/id

attach(server, name, sess, set_current=True)

Simple helper. Delegates to create() using the session as both the username and the password. This reproduces the logic of client.joinSession()

available(host, name)

Returns the path to property files which are stored. Internal accounting files are not returned.

clear(host=None, name=None, sess=None)

Walks through all sessions and calls killSession. Regardless of exceptions, it will remove the session files from the store.

conflicts(host, name, id, new_props, ignore_nulls=False, check_group=True)

Compares if the passed properties are compatible with with those for the host, name, id tuple

If ignore_nulls is True, then a null in new_props means matches anything.

contents()

Returns a map of maps with all the contents of the store. Internal accounting files are skipped.

count(host=None, name=None)

Returns the sum of all files visited by walk()

create(name, pasw, props, new=True, set_current=True, sudo=None)

Creates a new omero.client object, and returns: (cilent, session_id, timeToIdle, timeToLive)

exists(host, name, uuid)

Checks if the given file exists.

find_name_by_key(server, uuid)

Returns the name of a user for which the session key exists. This value is taken from the path rather than from the properties file since that value may have been overwritten. An exception is raised if there is more than one name since keys should be UUIDs. A None may be returned.

get(host, name, uuid)

Returns the properties stored in the given session file

get_current()
host_file()

Returns the path-object which stores the last active host

last_host()

Prints either the last saved host (see get_current()) or “localhost”

last_port()

Prints either the last saved port (see get_current()) or “4064”

non_dot(d)

Only returns the files (not directories) contained in d that don’t start with a dot

port_file()

Returns the path-object which stores the last active port

props(f)

Parses the path-object into properties

remove(host, name, uuid)

Removes the given session file from the store and removes the sess_file() if it is equal to the session we just removed.

report()

Simple dump utility

sess_file(host, user)

Returns the path-object which stores the last active session

set_current(host, name=None, uuid=None, props=None)

Sets the current session, user, and host files These are used as defaults by other methods.

user_file(host)

Returns the path-object which stores the last active user

walk(func, host=None, name=None, sess=None)

Applies func to all host, name, and session path-objects.

omero.util.temp_files module

OMERO Support for temporary files and directories

class omero.util.temp_files.TempFileManager(prefix='omero')

Bases: object

Creates temporary files and folders and makes a best effort to remove them on exit (or sooner). Typically only a single instance of this class will exist (“manager” variable in this module below)

access(dir)

Returns True if the current user can write to the given directory

clean_tempdir()

Deletes self.dir

clean_userdir()

Attempts to delete all directories under self.userdir other than the one owned by this process. If a directory is locked, it is skipped.

cleanup()

Releases self.lock and deletes self.dir. The lock is released first since on some platforms like Windows the lock file cannot be deleted even by the owner of the lock.

create(dir)

If the given directory doesn’t exist, creates it (with mode 0700) and returns True. Otherwise False.

create_path(prefix, suffix, folder=False, text=False, mode='r+')

Uses tempfile.mkdtemp and tempfile.mkstemp to create temporary folders and files, respectively, under self.dir

dir = None

Directory under which all temporary files and folders will be created. An attempt to remove a path not in this directory will lead to an exception.

gettempdir()

Returns the directory under which all temporary files and folders will be created.

lock = None

.lock file under self.dir which is used to prevent other TempFileManager instances (also in other languages) from cleaning up this directory.

mkstemp(prefix, suffix, dir, text=False)

Similar to tempfile.mkstemp name but immediately closes the file descriptor returned and passes back just the name. This prevents various Windows issues.

on_rmtree(func, name, exc)
pid()

Returns some representation of the current process’s id

remove_path(name)

If the given path is under self.dir, then it is deleted whether file or folder. Otherwise, an exception is thrown.

tmpdir()

Returns a platform-specific user-writable temporary directory

First, the value of “OMERO_TMPDIR” is attempted (if available), then user’s home directory, then the global temp director.

Typical errors for any of the possible temp locations are:
  • non-existence
  • inability to lock

See: http://trac.openmicroscopy.org.uk/ome/ticket/1653

userdir = None

User-accessible directory of the form $TMPDIR/omero_$USERNAME. If the given directory is not writable, an attempt is made to use an alternative

username()

Returns the current OS-user’s name

omero.util.temp_files.create_path(prefix='omero', suffix='.tmp', folder=False)

Uses the global TempFileManager to create a temporary file.

omero.util.temp_files.gettempdir()

Returns the dir value for the global TempFileManager.

omero.util.temp_files.manager = <omero.util.temp_files.TempFileManager object at 0x14115090>

Global TempFileManager instance for use by the current process and registered with the atexit module for cleaning up all created files on exit. Other instances can be created for specialized purposes.

omero.util.temp_files.remove_path(file)

Removes the file from the global TempFileManager. The file will be deleted if it still exists.

omero.util.text module

class omero.util.text.ALIGN
LEFT = '-'
RIGHT = ''
class omero.util.text.CSVStyle

Bases: omero.util.text.PlainStyle

NAME = 'csv'
get_rows(table)
class omero.util.text.Column(name, data, align='-', style=<omero.util.text.SQLStyle object at 0x4775e390>)

Bases: list

class omero.util.text.JSONStyle

Bases: omero.util.text.Style

NAME = 'json'
format(width, align)
get_rows(table)
class omero.util.text.PlainStyle

Bases: omero.util.text.Style

NAME = 'plain'
SEPARATOR = ','
_write_row(table, i)
format(width, align)
get_rows(table)
class omero.util.text.SQLStyle

Bases: omero.util.text.Style

NAME = 'sql'
SEPARATOR = '|'
format(width, align)
get_rows(table)
line(table)
status(table)
class omero.util.text.Style

Bases: object

NAME = 'unknown'
headers(table)
width(name, decoded_data)
class omero.util.text.StyleRegistry

Bases: dict

class omero.util.text.Table(*columns)
get_row(i=None)
get_rows()
page(offset, limit, total)
set_style(style)
class omero.util.text.TableBuilder(*headers)

Bases: object

OMERO-addition to make working with Tables easier

build()
col(name)

Add a new column and back fill spaces

cols(names)

Similar to col() but only adds unknown columns

get_col(name)

Return a column by header name.

page(offset, limit, total)
replace_col(name, col)

Replace a column by header name, it must be the same length.

replace_header(name, new_name)

Replace a header name with a new name.

row(*items, **by_name)
set_align(align)

Set column alignments using alignments string, one char for each column. ‘r’ for right-aligned columns, the default, anything else, is left-aligned. If the argument list in too short it will be padded with the default.

set_style(style)
sort(cols=[0], reverse=False)

Sort the results on a given column by transposing, sorting and then transposing.

omero.util.text.filesizeformat(bytes)

Formats the value like a ‘human-readable’ file size (i.e. 13 KB, 4.1 MB, 102 bytes, etc).

Copied largely from django.template.defaultfilters

omero.util.text.find_style(style, error_strategy=None)

Lookup method for well-known styles by name. None may be returned.

omero.util.text.list_styles()

List the styles that are known by find_style

omero.util.tiles module

Copyright 2011 Glencoe Software, Inc. All rights reserved. Use is subject to license terms supplied in LICENSE.txt

class omero.util.tiles.RPSTileData(loop, rps)

Bases: omero.util.tiles.TileData

close()
getTile(z, c, t, x, y, w, h)
setTile(buffer, z, c, t, x, y, w, h)
class omero.util.tiles.RPSTileLoop(session, pixels)

Bases: omero.util.tiles.TileLoop

createData()
forEachTile(tileWidth, tileHeight, iteration)

Iterates over every tile in a given Pixels object based on the over arching dimensions and a requested maximum tile width and height. :param tileWidth: <b>Maximum</b> width of the tile requested. The tile request itself will be smaller than the original tile width requested if <code>x + tileWidth > sizeX</code>. :param tileHeight: <b>Maximum</b> height of the tile requested. The tile request itself will be smaller if <code>y + tileHeight > sizeY</code>. :param iteration: Invoker to call for each tile. @return The total number of tiles iterated over.

getPixels()

After saving the binary data, the update event of the {@link Pixels} instance will be updated and therefore need to be reloaded. As a convenience the returned value is accessible here.

getSession()
setPixels(pixels)

Used by RPSTileData to set a reloaded Pixels instance for client use.

class omero.util.tiles.TileData

Bases: object

“Interface” which must be returned by concrete TileLoop implementations.

close()
getTile(z, c, t, x, y, w, h)
Parameters:
  • z – int
  • c – int
  • t – int
  • y – int
  • w – int
  • h – int
Returns:

byte[]

setTile(buffer, z, c, t, x, y, w, h)

buffer: byte[] :param z: int :param c: int :param t: int :param y: int :param w: int :param h: int

class omero.util.tiles.TileLoop

Bases: object

createData()

Subclasses must provide a fresh instance of {@link TileData}. The instance will be closed after the run of forEachTile.

Returns:TileData
forEachTile(sizeX, sizeY, sizeZ, sizeC, sizeT, tileWidth, tileHeight, iteration)

Iterates over every tile in a given Pixels object based on the over arching dimensions and a requested maximum tile width and height. :param sizeX: int :param sizeY: int :param sizeZ: int :param sizeC: int :param sizeT: int :param iteration: Invoker to call for each tile. :param pixel: Pixel instance :param tileWidth: <b>Maximum</b> width of the tile requested. The tile request itself will be smaller than the original tile width requested if <code>x + tileWidth > sizeX</code>. :param tileHeight: <b>Maximum</b> height of the tile requested. The tile request itself will be smaller if <code>y + tileHeight > sizeY</code>. :returns: The total number of tiles iterated over.

class omero.util.tiles.TileLoopIteration

Bases: object

“Interface” which must be passed to forEachTile

run(rps, z, c, t, x, y, tileWidth, tileHeight, tileCount)

omero.util.upgrade_check module

Copyright 2009 Glencoe Software, Inc. All rights reserved. Use is subject to license terms supplied in LICENSE.txt

class omero.util.upgrade_check.UpgradeCheck(agent, url='http://upgrade.openmicroscopy.org.uk/', version='5.3.3-ice35-b63', timeout=3.0)

Bases: object

Port of Java UpgradeCheck:

>>> from omero.util.upgrade_check import UpgradeCheck
>>> uc = UpgradeCheck("doctest")
>>> uc.run()
>>> uc.isUpgradeNeeded()
False
>>> uc.isExceptionThrown()
False
>>> uc = UpgradeCheck("doctest", version = "0.0.0")
>>> uc.run()
>>> uc.isUpgradeNeeded()
True
>>> uc.isExceptionThrown()
False
>>>
>>> uc = UpgradeCheck("doctest",
...     url = "http://some-completely-unknown-host.abcd/")
>>> uc.run()
>>> uc.isUpgradeNeeded()
False
>>> uc.isExceptionThrown()
True
DEFAULT_TIMEOUT = 3.0
_set(results, e)
getExceptionThrown()
getOSVersion()
getUpgradeUrl()
isExceptionThrown()
isUpgradeNeeded()
run()

If the {@link #url} has been set to null or the empty string, then no upgrade check will be performed (silently). If however the string is an invalid URL, a warning will be printed.

This method should <em>never</em> throw an exception.

Module contents

class omero.util.Dependency(key)

Bases: object

Centralized logic for declaring and logging a service dependency on a non-shipped library. This is called lazily from the run method of the application to give logging time to be initialized.

See #4566

check(logger)
get_version(target)

Get version method which returns a string representing. Should be overwritten by subclasses for packages/modules with no __version__ field.

class omero.util.Environment(*args)

Simple class for creating an executable environment

append(key, addition)

Manually adds a value to the environment string

set(key, value)

Manually sets a value in the target environment.

class omero.util.Resources(sleeptime=60, stop_event=None)

Container class for storing resources which should be cleaned up on close and periodically checked. Use stop_event.set() to stop the internal thread.

add(*args, **kwargs)
checkAll(copy)

While stop_event is unset, go through the copy of stuff and call the check method on each entry. Any that throws an exception or returns a False value will be returned in the remove list.

cleanup(*args, **kwargs)
copyStuff(*args, **kwargs)

Within a lock, copy the “stuff” list and reverse it. The list is reversed so that entries added later, which may depend on earlier added entries get a chance to be cleaned up first.

removeAll(*args, **kwargs)

Finally, within another lock, call the “cleanup” method on all the entries in remove, and remove them from the official stuff list. (If stop_event is set during execution, we return with the assumption that Resources.cleanup() will take care of them)

safeClean(m)
class omero.util.Servant(ctx, needs_session=False)

Bases: omero.util.SimpleServant

Abstract servant which can be used along with a slice2py generated dispatch class as the base type of high-level servants. These provide resource cleanup as per the omero.util.Server class.

By passing “needs_session = True” to this constructor, an internal session will be created and stored in ServerContext as well as registered with self.resources

cleanup()

Cleanups all resoures created by this servant. Calling cleanup multiple times should be safe.

class omero.util.Server(impl_class, adapter_name, identity, logdir='var/log', dependencies=())

Bases: Ice.Application

Basic server implementation which can be used for implementing a standalone python server which can be started from icegridnode.

The servant implementation MUST have a constructor which takes a single ServerContext argument AND have a cleanup() method

Logging is configured relative to the current directory to be in var/log by default.

Usage:

if __name__ == "__main__":
    app=Server(
        ServicesI, "ServicesAdapter", Ice.Identity("Services",""))
    sys.exit(app.main(sys.argv))

app.impl now points to an instance of ServicesI

cleanup()

Cleans up all resources that were created by this server. Primarily the one servant instance.

run(args)
waitOnStartup()
class omero.util.ServerContext(server_id, communicator, stop_event, on_newsession=None)

Bases: object

Context passed to all servants.

server_id, communicator, and stop_event will be constructed by the top-level Server instance.

A context instance may also be configured to hold on to an internal session (ServiceFactoryPrx) and keep it alive.

This instance obeys the Resources API and calls sf.keepAlive(None) on every check call, but does nothing on cleanup. The sf instance must be manually cleaned as the final operation of a servant.

(Note: cleanup of the server context indicates server shutdown, so should be infrequent)

add_servant(*args, **kwargs)
check()

Calls getSession() but always returns True. This keeps the context available in the resources for later uses, and tries to re-establish a connection in case Blitz goes down.

cleanup()

Does nothing. Context clean up must happen manually since later activities may want to reuse it. Servants using a server connection should cleanup the instance after Resources is cleaned up

getSession(*args, **kwargs)

Returns the ServiceFactoryPrx configured for the context if available. If the context was not configured for sessions, an ApiUsageException will be thrown: servants should know whether or not they were configured for sessions. See Servant(..., needs_session = True)

Otherwise, if there is no ServiceFactoryPrx, an attempt will be made to create one if recreate == True. If the value is None or non can be recreated, an InternalException will be thrown.

TODO : currently no arguments are provided for re-creating these, but also not in Servant.__init__

hasSession()
newSession()
class omero.util.SimpleServant(ctx)

Bases: object

Base servant initialization. Doesn’t create or try to cleanup a top-level Resources thread. This is useful for large numbers of servants. For servers and other singleton-like servants, see “Servant”

setProxy(prx)

Should be overwritten for post-initialization activities. The reason this method exists is that the implementation must be complete before registering it with the adapter.

class omero.util.StreamRedirect(logger)

Bases: object

Since all server components should exclusively using the logging module any output to stdout or stderr is caught and logged at “WARN”. This is useful, especially in the case of Windows, where stdout/stderr is eaten.

flush()
write(msg)
omero.util.add_grid_object(communicator, obj)
omero.util.configure_logging(logdir=None, logfile=None, loglevel=20, format='%(asctime)s %(levelname)-5.5s [%(name)40s] (%(threadName)-10s) %(message)s', filemode='a', maxBytes=500000000, backupCount=9, time_rollover=False)
omero.util.configure_server_logging(props)

Takes an Ice.Properties instance and configures logging

omero.util.create_admin_session(communicator)
omero.util.edit_path(path_or_obj, start_text)
omero.util.get_omero_userdir()

Returns the OMERO user directory

omero.util.get_user(default=None)

Returns the username. For most purposes, this value will be the same as getpass.getuser on *nix and win32api.GetUserName on Windows, but in some situations (when running without a terminal, etc) getuser may throw a KeyError. In which case, or if the username resolves to False, the default value be returned.

Any unexpected exceptions will be thrown.

See ticket:6307

omero.util.get_user_dir()
omero.util.internal_service_factory(communicator, user='root', group=None, retries=6, interval=10, client_uuid=None, stop_event=None)

Try to return a ServiceFactory from the grid.

Try a number of times then give up and raise the last exception returned. This method will only work internally to the grid, i.e. behind the Glacier2 firewall. It is intended for internal servers to be able to create sessions for accessing the database.

communicator := Ice.Communicator used to find the registry
user         := Username which should have a session created
group        := Group into which the session should be logged
retries      := Number of session creation retries before throwing
interval     := Seconds between retries
client_uuid  := Uuid of the client which should be used
omero.util.load_dotted_class(dotted_class)

Load a Python class of the form “pkg.mod.Class” via __import__ and return it. No ctor or similar is called.

omero.util.long_to_path(id, root='')

Converts a long to a path such that for all directiories only a 1000 files and a 1000 subdirectories will be returned.

This method duplicates the logic in ome.io.nio.AbstractFileSystemService.java:getPath()

omero.util.make_logname(self)

Generates a logname from the given instance using the module and name from its class

omero.util.tail_lines(filename, linesback=10, returnlist=0)

Does what “tail -10 filename” would have done Parameters:

filename file to read linesback Number of lines to read from end of file returnlist Return a list containing the lines instead of a string