Package omero :: Package util :: Module script_utils
[hide private]
[frames] | no frames]

Module script_utils

source code

Functions [hide private]
 
drawTextOverlay(draw, x, y, text, colour='0xffffff')
Draw test on image.
source code
 
drawLineOverlay(draw, x0, y0, x1, y1, colour='0xffffff')
Draw line on image.
source code
 
rgbToRGBInt(red, green, blue)
Convert an R,G,B value to an int.
source code
 
RGBToPIL(RGB)
Convert an RGB value to a PIL colour value.
source code
 
rangeToStr(range)
Map a range to a string of numbers @param range See above.
source code
 
rmdir_recursive(dir) source code
 
calcSha1(filename)
Returns a hash of the file identified by filename
source code
 
calcSha1FromData(data)
Calculate the Sha1 Hash from a data array @param data The data array.
source code
 
getFormat(queryService, format) source code
 
createFile(updateService, filename, mimetype=None, origFilePathName=None)
Creates an original file, saves it to the server and returns the result
source code
 
uploadFile(rawFileStore, originalFile, filePath=None)
Uploads an OriginalFile to the server
source code
 
downloadFile(rawFileStore, originalFile, filePath=None)
Downloads an OriginalFile from the server.
source code
 
attachFileToParent(updateService, parent, originalFile, description=None, namespace=None)
Attaches the original file (file) to a Project, Dataset or Image (parent)
source code
 
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)
source code
 
addAnnotationToImage(updateService, image, annotation)
Add the annotation to an image.
source code
 
readFromOriginalFile(rawFileService, iQuery, fileId, maxBlockSize=10000)
Read the OriginalFile with fileId and return it as a string.
source code
 
readFileAsArray(rawFileService, iQuery, fileId, row, col, separator=' ')
Read an OriginalFile with id and column separator and return it as an array.
source code
 
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.
source code
 
downloadPlane(rawPixelsStore, pixels, z, c, t)
Download the plane [z,c,t] for image pixels.
source code
 
getPlaneFromImage(imagePath, rgbIndex=None)
Reads a local image (E.g.
source code
 
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.
source code
 
uploadCecogObjectDetails(updateService, imageId, filePath)
Parses a single line of cecog output and saves as a roi.
source code
 
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.
source code
 
createFileFromData(updateService, queryService, filename, data)
Create a file from the data of type format, setting sha1, ..
source code
 
attachArrayToImage(updateService, image, file, nameSpace)
Attach an array, stored as a csv file to an image.
source code
 
uploadArray(rawFileStore, updateService, queryService, image, filename, namespace, array)
Upload the data to the server, creating the OriginalFile Object and attaching it to the image.
source code
 
arrayToCSV(data)
Convert the numpy array data to a csv file.
source code
 
uploadPlane(rawPixelsStore, plane, z, c, t)
Upload the plane to the server attching it to the current z,c,t of the already instantiated rawPixelStore.
source code
 
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.
source code
 
getRenderingEngine(session, pixelsId)
Create the renderingEngine for the pixelsId.
source code
 
createPlaneDef(z, t)
Create the plane rendering def, for z,t @param Z the Z-Section @param T The T-Point.
source code
 
getPlaneAsPackedInt(renderingEngine, z, t)
Get the rendered Image of the plane for the z, t with the default channels.
source code
 
getRawPixelsStore(session, pixelsId)
Get the rawPixelsStore for the Image with pixelsId @param pixelsId The pixelsId of the object to retrieve.
source code
 
getRawFileStore(session, fileId)
Get the rawFileStore for the file with fileId @param fileId The fileId of the object to retrieve.
source code
 
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.
source code
 
IdentityFn(commandArgs) source code
 
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.
source code
 
createNewImage(pixelsService, rawPixelStore, renderingEngine, pixelsType, gateway, 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.
source code
 
parseInputs(client, session, processFn=IdentityFn)
parse the inputs from the client object and map it to some other form, values may be transformed by function.
source code
 
getROIFromImage(iROIService, imageId, namespace=None)
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.
source code
 
toCSV(list)
Convert a list to a Comma Separated Value string.
source code
 
toList(csvString)
Convert a csv string to a list of strings @param csvString The CSV string to convert.
source code
 
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.
source code
 
findROIByImage(roiService, image, namespace)
Finds the ROI with the given namespace linked to the image.
source code
Variables [hide private]
  hash_sha1 = sha.new
  COLOURS = {'Red':(255, 0, 0, 255), 'Green':(0, 255, 0, 255), '...
  EXTRA_COLOURS = {'Violet':(238, 133, 238, 255), 'Indigo':(79, ...
  CSV_NS = 'text/csv'
  CSV_FORMAT = 'text/csv'
  SU_LOG = logging.getLogger("omero.util.script_utils")

Imports: logging, getopt, sys, os, subprocess, numpy, omero, omero_Constants_ice, pixelstypetopython, EllipseData, RectData, MaskData, WorkflowData, ROIData, hashlib, sha


Function Details [hide private]

drawTextOverlay(draw, x, y, text, colour='0xffffff')

source code 

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.

drawLineOverlay(draw, x0, y0, x1, y1, colour='0xffffff')

source code 

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 string to draw the text in.

rgbToRGBInt(red, green, blue)

source code 

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.

RGBToPIL(RGB)

source code 

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

rangeToStr(range)

source code 

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

calcSha1(filename)

source code 

Returns a hash of the file identified by filename

Parameters:
  • filename - pathName of the file
Returns:
The hash of the file

calcSha1FromData(data)

source code 

Calculate the Sha1 Hash from a data array @param data The data array. @return The Hash

createFile(updateService, filename, mimetype=None, origFilePathName=None)

source code 

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

Parameters:
  • queryService - The query service E.g. session.getQueryService()
  • updateService - The update service E.g. session.getUpdateService()
  • filename - The file path and name (or name if in same folder). String
  • mimetype - The mimetype (string) or Format object representing the file format
  • origFilePathName - Optional path/name for the original file
Returns:
The saved OriginalFileI, as returned from the server

uploadFile(rawFileStore, originalFile, filePath=None)

source code 

Uploads an OriginalFile to the server

Parameters:
  • rawFileStore - The Omero rawFileStore
  • originalFile - The OriginalFileI
  • filePath - Where to find the file to upload. If None, use originalFile.getName().getValue()

downloadFile(rawFileStore, originalFile, filePath=None)

source code 

Downloads an OriginalFile from the server.

Parameters:
  • rawFileStore - The Omero rawFileStore
  • originalFile - The OriginalFileI
  • filePath - Where to download the file. If None, use originalFile.getName().getValue()

attachFileToParent(updateService, parent, originalFile, description=None, namespace=None)

source code 

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

Parameters:
  • updateService - The update service
  • parent - A ProjectI, DatasetI or ImageI to attach the file to
  • originalFile - The OriginalFileI to attach
  • description - Optional description for the file annotation. String
  • namespace - Optional namespace for file annotataion. String
Returns:
The saved and returned *AnnotationLinkI (* = Project, Dataset or Image)

uploadAndAttachFile(queryService, updateService, rawFileStore, parent, localName, mimetype, description=None, namespace=None, origFilePathName=None)

source code 

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

Parameters:
  • queryService - The query service
  • updateService - The update service
  • rawFileStore - The rawFileStore
  • parent - The ProjectI or DatasetI or ImageI to attach file to
  • localName - Full Name (and path) of the file location to upload. String
  • mimetype - The original file mimetype. E.g. "PNG". String
  • description - Optional description for the file annotation. String
  • namespace - Namespace to set for the original file
  • origFilePathName - The /path/to/file/fileName.ext you want on the server. If none, use output as name
Returns:
The originalFileLink child. (FileAnnotationI)

addAnnotationToImage(updateService, image, annotation)

source code 

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

readFromOriginalFile(rawFileService, iQuery, fileId, maxBlockSize=10000)

source code 

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

readFileAsArray(rawFileService, iQuery, fileId, row, col, separator=' ')

source code 

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.

readFlimImageFile(rawPixelsStore, pixels)

source code 

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;

downloadPlane(rawPixelsStore, pixels, z, c, t)

source code 

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

getPlaneFromImage(imagePath, rgbIndex=None)

source code 

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

@param imagePath Path to image.

uploadDirAsImages(sf, queryService, updateService, pixelsService, path, dataset=None)

source code 

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

uploadCecogObjectDetails(updateService, imageId, filePath)

source code 

Parses a single line of cecog output and saves as a roi.

Adds a Rectangle (particle) to the current OMERO image, at point x, y. Uses the self.image (OMERO image) and self.updateService

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

source code 

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 rawPixelsStore The rawPixelStore @param queryService @param c The C-Section to retrieve. @param t The T-Section to retrieve. @param imageName the local location to save the image.

createFileFromData(updateService, queryService, filename, data)

source code 

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.

attachArrayToImage(updateService, image, file, nameSpace)

source code 

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

uploadArray(rawFileStore, updateService, queryService, image, filename, namespace, array)

source code 

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.

arrayToCSV(data)

source code 

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

uploadPlane(rawPixelsStore, plane, z, c, t)

source code 

Upload the plane to the server 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.

uploadPlaneByRow(rawPixelsStore, plane, z, c, t)

source code 

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.

getRenderingEngine(session, pixelsId)

source code 

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

createPlaneDef(z, t)

source code 

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

getPlaneAsPackedInt(renderingEngine, z, t)

source code 

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.

getRawPixelsStore(session, pixelsId)

source code 

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

getRawFileStore(session, fileId)

source code 

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

getPlaneInfo(iQuery, pixelsId, asOrderedList=True)

source code 

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

resetRenderingSettings(renderingEngine, pixelsId, cIndex, minValue, maxValue, rgba=None)

source code 

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.

createNewImage(pixelsService, rawPixelStore, renderingEngine, pixelsType, gateway, plane2Dlist, imageName, description, dataset=None)

source code 

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 pixelsService The OMERO pixelsService @param rawPixelStore The OMERO rawPixelsStore @param renderingEngine The OMERO renderingEngine

Parameters:
  • pixelsType, The, pixelsType, object, omero - :model::PixelsType @param gateway The OMERO gateway service @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

parseInputs(client, session, processFn=IdentityFn)

source code 

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. @param processFn A function to transform data to some other form. @return Parsed inputs as defined by ProcessFn.

getROIFromImage(iROIService, imageId, namespace=None)

source code 

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.

toCSV(list)

source code 

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

toList(csvString)

source code 

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

registerNamespace(iQuery, iUpdate, namespace, keywords)

source code 

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.

findROIByImage(roiService, image, namespace)

source code 

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.


Variables Details [hide private]

COLOURS

Value:
{'Red':(255, 0, 0, 255), 'Green':(0, 255, 0, 255), 'Blue':(0, 0, 255, \
255), 'Yellow':(255, 255, 0, 255), 'White':(255, 255, 255, 255),}

EXTRA_COLOURS

Value:
{'Violet':(238, 133, 238, 255), 'Indigo':(79, 6, 132, 255), 'Black':(0\
, 0, 0, 255), 'Orange':(254, 200, 6, 255), 'Gray':(130, 130, 130, 255)\
,}