def setStrokeSettings(self, colour, width=1): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) self.strokeColour = rint(colour) self.strokeWidth = LengthI() self.strokeWidth.setValue(width) self.strokeWidth.setUnit(UnitsLength.POINT)
def populate_shape(o, set_unit_attributes=True): o.fillColor = rint(0xffffffff) o.fillRule = rstring('solid') o.fontFamily = rstring('cursive') if set_unit_attributes: o.fontSize = LengthI(12, UnitsLength.POINT) o.fontStyle = rstring('italic') o.locked = rbool(False) o.strokeColor = rint(0xffff0000) o.strokeDashArray = rstring('inherit') if SCHEMA_VERSION == '2015-01': o.visibility = rbool(True) o.strokeLineCap = rstring('round') if set_unit_attributes: o.strokeWidth = LengthI(4, UnitsLength.PIXEL) o.textValue = rstring('the_text') o.theC = rint(1) o.theT = rint(2) o.theZ = rint(3) t = identity_transform() if SCHEMA_VERSION == '2015-01': o.transform = t.svg_transform else: o.transform = t return o
def make_well_sample(x_pos=None, y_pos=None): ws = WellSampleI() image = itest.new_image(name=itest.uuid()) ws.image = image if x_pos is not None: ws.posX = LengthI(x_pos, UnitsLength.REFERENCEFRAME) if y_pos is not None: ws.posY = LengthI(y_pos, UnitsLength.REFERENCEFRAME) return ws
def emissionWave_channel(image_channel_factory): channels = list() emission_waves = (LengthI(123.0, 'NANOMETER'), LengthI(456.0, 'NANOMETER')) for emission_wave in emission_waves: channel = ChannelI() lchannel = LogicalChannelI() lchannel.emissionWave = emission_wave channel.logicalChannel = lchannel channels.append(channel) return image_channel_factory(channels)
def screen_with_plates(screen): for plate_id in range(5, 7): o = PlateI() o.id = rlong(plate_id) o.name = rstring('plate_name_%d' % plate_id) o.description = rstring('plate_description_%d' % plate_id) o.columnNamingConvention = rstring('number') o.rowNamingConvention = rstring('letter') o.columns = rint(12) o.rows = rint(8) o.defaultSample = rint(0) o.externalIdentifier = rstring('external_identifier_%d' % plate_id) o.status = rstring('status_%d' % plate_id) o.wellOriginX = LengthI(0.1, UnitsLength.REFERENCEFRAME) o.wellOriginY = LengthI(1.1, UnitsLength.REFERENCEFRAME) screen.linkPlate(o) for well_id in range(7, 9): well = WellI() well.id = rlong(well_id) well.column = rint(2) well.row = rint(1) well.externalDescription = \ rstring('external_description_%d' % well_id) well.externalIdentifier = \ rstring('external_identifier_%d' % well_id) well.type = rstring('the_type') well.alpha = rint(0) well.red = rint(255) well.green = rint(0) well.blue = rint(0) well.status = rstring('the_status') o.addWell(well) plateacquisition = PlateAcquisitionI() plateacquisition.id = rlong(well_id) plateacquisition.name = rstring( 'plateacquisition_name_%d' % well_id) plateacquisition.description = rstring( 'plateacquisition_description_%d' % well_id) plateacquisition.maximumFieldCount = rint(1) plateacquisition.startTime = rtime(1L) plateacquisition.endTime = rtime(2L) for wellsample_id in range(9, 11): wellsample = WellSampleI() wellsample.setPlateAcquisition(plateacquisition) wellsample.id = rlong(wellsample_id) wellsample.posX = LengthI(1.0, UnitsLength.REFERENCEFRAME) wellsample.posY = LengthI(2.0, UnitsLength.REFERENCEFRAME) wellsample.timepoint = rtime(1L) wellsample.image = create_image(1L) well.addWellSample(wellsample) return screen
def addRoi(self, request, imageid): img = self.getImage0(imageid) if img is None: return None data = json.loads(request.body) shapes = data['shapes'] x = y = l = z = t = -1 for s in shapes: for k in s: val = s[k] if k == "x": x = int(val) elif k == "y": y = int(val) elif k == "width": l = int(val) elif k == "theZ": z = int(val) elif k == "theT": t = int(val) elif k == "fillColorAsInt": fill = int(val) elif k == "strokeColorAsInt": stroke = int(val) elif k == "strokeWidth": strokeWidth = int(val) if (x < 0 or y < 0 or z < 0 or t < 0 or l <= 0): return None updateService = self._connection.getUpdateService() roi = RoiI() roi.setImage(img._obj) rect = RectangleI() rect.x = rdouble(x) rect.y = rdouble(y) rect.width = rdouble(l) rect.height = rdouble(l) rect.theZ = rint(z) rect.theT = rint(t) rect.setFillColor(rint(fill)) strokeLen = LengthI() strokeLen.setValue(strokeWidth) strokeLen.setUnit(UnitsLength.PIXEL) rect.setStrokeWidth(strokeLen) rect.setStrokeColor(rint(stroke)) roi.addShape(rect) if (updateService.saveAndReturnObject(roi) is None): return None return self.get_rois(imageid)
def __init__(self): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) self.WHITE = 16777215 self.BLACK = 0 self.GREY = 11184810 self.strokeColour = rint(self.GREY) self.strokeWidth = LengthI() self.strokeWidth.setValue(1) self.strokeWidth.setUnit(UnitsLength.POINT) self.strokeDashArray = rstring('') self.fillColour = rint(self.GREY) self.fillRule = rstring('')
def create_plate_wells(self, user1, rows, cols, plateacquisitions=1): """Return Plate with Wells.""" updateService = get_update_service(user1) plate = PlateI() plate.name = rstring('plate') plate = updateService.saveAndReturnObject(plate) # PlateAcquisitions for plate plate_acqs = [] for p in range(plateacquisitions): plate_acq = PlateAcquisitionI() plate_acq.name = rstring('plateacquisition_%s' % p) plate_acq.description = rstring('plateacquisition_description') plate_acq.maximumFieldCount = rint(3) plate_acq.startTime = rtime(1) plate_acq.endTime = rtime(2) plate_acq.plate = PlateI(plate.id.val, False) plate_acq = updateService.saveAndReturnObject(plate_acq) plate_acqs.append(plate_acq) # Create Wells for plate ref_frame = UnitsLength.REFERENCEFRAME for row in range(rows): for col in range(cols): # create Well well = WellI() well.column = rint(col) well.row = rint(row) well.plate = PlateI(plate.id.val, False) # Only wells in first Column have well-samples etc. if col == 0: # Have 3 images/well-samples per plateacquisition # (if no plateacquisitions, create 3 well-samples without) for p in range(max(1, plateacquisitions)): for i in range(3): image = self.create_test_image( size_x=5, size_y=5, session=user1[0].getSession()) ws = WellSampleI() ws.image = ImageI(image.id, False) ws.well = well ws.posX = LengthI(i * 10, ref_frame) ws.posY = LengthI(i, ref_frame) if p < len(plate_acqs): ws.setPlateAcquisition( PlateAcquisitionI(plate_acqs[p].id.val, False)) well.addWellSample(ws) updateService.saveObject(well) return plate
def __init__(self): self.WHITE = 16777215 self.BLACK = 0 self.GREY = 11184810 self.strokeColour = rint(self.GREY) self.strokeWidth = LengthI() self.strokeWidth.setValue(1) self.strokeWidth.setUnit(UnitsLength.POINT) self.strokeDashArray = rstring('') self.strokeDashOffset = rint(0) self.strokeLineCap = rstring('') self.strokeLineJoin = rstring('') self.strokeMiterLimit = rint(0) self.fillColour = rint(self.GREY) self.fillRule = rstring('')
def populate_shape(o): o.fillColor = rint(0xffffffff) o.fillRule = rstring('solid') o.fontFamily = rstring('cursive') o.fontSize = LengthI(12, UnitsLength.POINT) o.fontStyle = rstring('italic') o.locked = rbool(False) o.strokeColor = rint(0xffff0000) o.strokeDashArray = rstring('inherit') o.strokeLineCap = rstring('round') o.strokeWidth = LengthI(4, UnitsLength.PIXEL) o.textValue = rstring('the_text') o.theC = rint(1) o.theT = rint(2) o.theZ = rint(3) o.visibility = rbool(True) return o
def _set_shape_properties(shape, name=None, fill_color=(10, 10, 10, 255), stroke_color=(255, 255, 255, 255), stroke_width=1, ): if name: shape.setTextValue(rtypes.rstring(name)) shape.setFillColor(rtypes.rint(_rgba_to_int(*fill_color))) shape.setStrokeColor(rtypes.rint(_rgba_to_int(*stroke_color))) shape.setStrokeWidth(LengthI(stroke_width, enums.UnitsLength.PIXEL))
def shapes(self): """Create a bunch of unsaved Shapes.""" rect = RectangleI() rect.x = rdouble(10) rect.y = rdouble(20) rect.width = rdouble(30) rect.height = rdouble(40) # Only save theT, not theZ rect.theT = rint(0) rect.textValue = rstring("test-Rectangle") rect.fillColor = rint(rgba_to_int(255, 255, 255, 255)) rect.strokeColor = rint(rgba_to_int(255, 255, 0, 255)) # ellipse without saving theZ & theT ellipse = EllipseI() ellipse.x = rdouble(33) ellipse.y = rdouble(44) ellipse.radiusX = rdouble(55) ellipse.radiusY = rdouble(66) ellipse.textValue = rstring("test-Ellipse") line = LineI() line.x1 = rdouble(200) line.x2 = rdouble(300) line.y1 = rdouble(400) line.y2 = rdouble(500) line.textValue = rstring("test-Line") point = PointI() point.x = rdouble(1) point.y = rdouble(1) point.theZ = rint(1) point.theT = rint(1) point.textValue = rstring("test-Point") polygon = PolygonI() polygon.theZ = rint(5) polygon.theT = rint(5) polygon.fillColor = rint(rgba_to_int(255, 0, 255, 50)) polygon.strokeColor = rint(rgba_to_int(255, 255, 0)) polygon.strokeWidth = LengthI(10, UnitsLength.PIXEL) points = "10,20, 50,150, 200,200, 250,75" polygon.points = rstring(points) mask = MaskI() mask.setTheC(rint(0)) mask.setTheZ(rint(0)) mask.setTheT(rint(0)) mask.setX(rdouble(100)) mask.setY(rdouble(100)) mask.setWidth(rdouble(500)) mask.setHeight(rdouble(500)) mask.setTextValue(rstring("test-Mask")) mask.setBytes(None) return [rect, ellipse, line, point, polygon, mask]
def run_processing(conn, script_params): message = "" image_ids = script_params['IDs'] for image in conn.getObjects("Image", image_ids): if not image: message = 'Could not find specified image' return message print 'size z:', image.getSizeZ() physical_z = None if (image.getSizeZ() > 1.0): try: physical_z = script_params['Z_Pixel_Size'] except: message = 'Looks like you have a z-stack - you should set a non-zero value for Z_Pixel_Size' return message physical_x = script_params['X_Pixel_Size'] physical_y = script_params['Y_Pixel_Size'] if (physical_x == 0.0) or (physical_y == 0.0): message = 'You should set a non-zero pixel size for both X and Y' return message # Get the BlitzGateway wrapped pixels and unwrap it pixelsWrapper = image.getPrimaryPixels() pixels = pixelsWrapper._obj # Update and save print "units", UnitsLength lx = LengthI(physical_x, UnitsLength.MICROMETER) ly = LengthI(physical_y, UnitsLength.MICROMETER) pixels.setPhysicalSizeX(lx) pixels.setPhysicalSizeY(ly) if physical_z: lz = LengthI(physical_z, UnitsLength.MICROMETER) pixels.setPhysicalSizeZ(lz) conn.getUpdateService().saveObject(pixels) message += 'Successfully set pixel size on image %s' % image.getName() return message
def get_length_units(): # Create a dict we can use for scalebar unit conversions unit_symbols = {} for name in LengthI.SYMBOLS.keys(): if name in ("PIXEL", "REFERENCEFRAME"): continue klass = getattr(UnitsLength, name) unit = LengthI(1, klass) to_microns = LengthI(unit, UnitsLength.MICROMETER) unit_symbols[name] = { 'symbol': unit.getSymbol(), 'microns': to_microns.getValue() } return unit_symbols
def shapes(self): """Create a bunch of unsaved Shapes.""" rect = RectangleI() rect.x = rdouble(10) rect.y = rdouble(20) rect.width = rdouble(30) rect.height = rdouble(40) rect.textValue = rstring("test-Rectangle") rect.fillColor = rint(rgba_to_int(255, 255, 255, 255)) rect.strokeColor = rint(rgba_to_int(255, 255, 0, 255)) ellipse = EllipseI() ellipse.x = rdouble(33) ellipse.y = rdouble(44) ellipse.radiusX = rdouble(55) ellipse.radiusY = rdouble(66) ellipse.textValue = rstring("test-Ellipse") line = LineI() line.x1 = rdouble(20) line.x2 = rdouble(30) line.y1 = rdouble(40) line.y2 = rdouble(50) line.textValue = rstring("test-Line") point = PointI() point.x = rdouble(50) point.y = rdouble(50) point.textValue = rstring("test-Point") polygon = PolygonI() polygon.fillColor = rint(rgba_to_int(255, 0, 255, 50)) polygon.strokeColor = rint(rgba_to_int(255, 255, 0)) polygon.strokeWidth = LengthI(10, UnitsLength.PIXEL) points = "10,20, 50,150, 100,100, 150,75" polygon.points = rstring(points) polyline = PolylineI() polyline.points = rstring(points) return [rect, ellipse, line, point, polygon, polyline]
def process_data(conn,image,file_type,ann_id,locs,nm_per_pixel,sr_pix_size,starts,stops,sizeT): """ Run the processing and upload the resultant image @param conn: Blitzgateway connection @param image: we need to get the image where the localisation data is attached --> this should be the raw timelapse data @param file_type: the type of dataset we are dealing with (see FILE_TYPES global) @param ann_id: the annotation id of the localisations file @param coords: the coords being histogrammed @param nm_per_pixel: the size of the pixel in the original image in nm (1 for Zeiss data which is already in nm) @param sr_pix_size: the pixel size we want in the new image in nm @param frames: the column in the dataset where we will find the first frame assignment @param starts: a list of starting indices for the time-lapse @param stops: a list of stopping indices for the time-lapse @param sizeT: the number of frames in the time-lapse """ #set parameters imageName = image.getName() name,ext = os.path.splitext(imageName) if 'ome' in name: name = name.split('.')[0] new_name = name + '_sr_timelapse_histogram.ome' + ext else: new_name = name + '_sr_timelapse_histogram' + ext parentDataset = image.getParent() parentProject = parentDataset.getParent() updateService = conn.getUpdateService() frame_width = image.getSizeX() frame_height = image.getSizeY() frame = file_type['frame'] print 'frame',frame sizeZ = 1 if 'zeiss2chan2D' in file_type: sizeC = 2 else: sizeC = 1 #calculate histogram rangex = frame_width * nm_per_pixel binsx = rangex / sr_pix_size rangey = frame_height * nm_per_pixel binsy = rangey / sr_pix_size hist_frames = [] for c in range(sizeC): locs_df = locs[c] for t in range(sizeT): coords_in_frames = locs_df[(locs_df['time'] >= starts[t]) & (locs_df['time']<= stops[t])] hist = calc_hist(coords_in_frames,file_type,binsy,binsx,rangey,rangex) hist_frames.append(hist) def plane_gen(): for z in range(sizeZ): for c in range(sizeC): for t in range(sizeT): plane = hist_frames[t] yield plane description = "Created from image:\n Name: %s\n Annotation ID: %d\n Frame indices:\n Start:%s\n Stop:%s"\ % (imageName, ann_id, str(starts), str(stops)) newImg = conn.createImageFromNumpySeq( plane_gen(), new_name, sizeZ=sizeZ, sizeC=sizeC, sizeT=sizeT, description=description) # reload the image (also reloads pixels) image = conn.getObject("Image", newImg.getId()) # Get the BlitzGateway wrapped pixels and unwrap it pixelsWrapper = image.getPrimaryPixels() pixels = pixelsWrapper._obj # Update and save pixSize = LengthI(float(sr_pix_size) / 1000, UnitsLength.MICROMETER) pixels.setPhysicalSizeX( pixSize ) pixels.setPhysicalSizeY( pixSize ) updateService.saveObject(pixels) if newImg: iid = newImg.getId() print "New Image Id = %s" % iid # put new images in existing dataset dataset = None if parentDataset is not None and parentDataset.canLink(): parentDataset = parentDataset._obj else: parentDataset = None parentProject = None # don't add Dataset to parent. if parentDataset is None: link = None print "No dataset created or found for new images."\ " Images will be orphans." else: dsLink = omero.model.DatasetImageLinkI() dsLink.parent = omero.model.DatasetI( parentDataset.id.val, False) dsLink.child = omero.model.ImageI(iid, False) updateService.saveObject(dsLink) if parentProject and parentProject.canLink(): # and put it in the current project projectLink = omero.model.ProjectDatasetLinkI() projectLink.parent = omero.model.ProjectI( parentProject.getId(), False) projectLink.child = omero.model.DatasetI( dataset.id.val, False) updateService.saveAndReturnObject(projectLink) message = 'Super resolution histogram successfully created' else: message = 'Something went wrong, could not make super resolution histogram' return message
def setStrokeSettings(self, colour, width=1): self.strokeColour = rint(colour) self.strokeWidth = LengthI() self.strokeWidth.setValue(width) self.strokeWidth.setUnit(UnitsLength.POINT)
def test_logical_channel(self): name = u'₩€_name_$$' ill_val = u'πλζ.test.ζ' fluor = u'GFP-₹₹' binning_value = u'Φωλ' ph_size = 1.11 ph_units = UnitsLength.MICROMETER ex_wave = 3.34 ex_units = UnitsLength.ANGSTROM version = 123 zoom = 100 gain = 1010.23 di_model = u'Model_ 123_àÅÉ' obj = LogicalChannelI() obj.name = rstring(name) obj.pinHoleSize = LengthI(ph_size, ph_units) illumination = IlluminationI() illumination.value = rstring(ill_val) obj.illumination = illumination obj.excitationWave = LengthI(ex_wave, ex_units) obj.setFluor(rstring(fluor)) ds = DetectorSettingsI() ds.version = rint(version) ds.gain = rdouble(gain) ds.zoom = rdouble(zoom) binning = BinningI() binning.value = rstring(binning_value) ds.binning = binning obj.detectorSettings = ds dichroic = DichroicI() dichroic.model = rstring(di_model) light_path = LightPathI() light_path.dichroic = dichroic obj.lightPath = light_path class MockChannel(LogicalChannelWrapper): def __loadedHotSwap__(self): # Don't need to load data for getLightPath() pass channel = MockChannel(None, obj) assert channel.getName() == name.encode('utf8') assert channel.name == name assert channel.getPinHoleSize().getValue() == ph_size assert channel.getPinHoleSize().getUnit() == ph_units assert channel.getPinHoleSize().getSymbol() == 'µm' # Illumination is an enumeration assert channel.getIllumination().getValue() == ill_val.encode('utf8') assert channel.getExcitationWave().getValue() == ex_wave assert channel.getExcitationWave().getUnit() == ex_units assert channel.getExcitationWave().getSymbol() == 'Å' assert channel.getFluor() == fluor assert channel.fluor == fluor d_settings = channel.getDetectorSettings() assert d_settings.getVersion() == version assert d_settings.version == version assert d_settings.getGain() == gain assert d_settings.gain == gain assert d_settings.getZoom() == zoom assert d_settings.getBinning().getValue() == binning_value assert d_settings.getBinning().value == binning_value assert channel.getLightPath().getDichroic().getModel() == di_model
def create_image(image_id, with_pixels=False): image_format = FormatI(1L) image_format.value = rstring('PNG') image = ImageI() image.id = rlong(image_id) image.acquisitionDate = rtime(1L) image.archived = rbool(False) image.description = rstring('image_description_%d' % image_id) image.name = rstring('image_name_%d' % image_id) image.partial = rbool(False) image.series = rint(0) image.format = image_format if not with_pixels: return image dimension_order = DimensionOrderI(1L) dimension_order.value = rstring('XYZCT') pixels_type = PixelsTypeI(1L) pixels_type.value = 'bit' pixels = PixelsI(1L) pixels.methodology = rstring('methodology') pixels.physicalSizeX = LengthI(1.0, UnitsLength.MICROMETER) pixels.physicalSizeY = LengthI(2.0, UnitsLength.MICROMETER) pixels.physicalSizeZ = LengthI(3.0, UnitsLength.MICROMETER) pixels.sha1 = rstring('61ee8b5601a84d5154387578466c8998848ba089') pixels.significantBits = rint(16) pixels.sizeX = rint(1) pixels.sizeY = rint(2) pixels.sizeZ = rint(3) pixels.sizeC = rint(4) pixels.sizeT = rint(5) pixels.timeIncrement = TimeI(1.0, UnitsTime.MILLISECOND) pixels.waveIncrement = rdouble(2.0) pixels.waveStart = rint(1) pixels.dimensionOrder = dimension_order pixels.pixelsType = pixels_type image.addPixels(pixels) contrast_method = ContrastMethodI(8L) contrast_method.value = rstring('Fluorescence') illumination = IlluminationI(1L) illumination.value = rstring('Transmitted') acquisition_mode = AcquisitionModeI(1L) acquisition_mode.value = rstring('WideField') photometric_interpretation = PhotometricInterpretationI(1L) photometric_interpretation.value = rstring('RGB') channel_1 = ChannelI(1L) channel_1.alpha = rint(255) channel_1.blue = rint(0) channel_1.green = rint(255) channel_1.red = rint(0) channel_1.lookupTable = rstring('rainbow') logical_channel_1 = LogicalChannelI(1L) logical_channel_1.emissionWave = LengthI(509.0, UnitsLength.NANOMETER) logical_channel_1.excitationWave = LengthI(488.0, UnitsLength.NANOMETER) logical_channel_1.fluor = rstring('GFP') logical_channel_1.name = rstring('GFP/488') logical_channel_1.ndFilter = rdouble(1.0) logical_channel_1.pinHoleSize = LengthI(1.0, UnitsLength.NANOMETER) logical_channel_1.pockelCellSetting = rint(0) logical_channel_1.samplesPerPixel = rint(2) logical_channel_1.contrastMethod = contrast_method logical_channel_1.illumination = illumination logical_channel_1.mode = acquisition_mode logical_channel_1.photometricInterpretation = photometric_interpretation channel_1.logicalChannel = logical_channel_1 channel_2 = ChannelI(2L) channel_2.alpha = rint(255) channel_2.blue = rint(255) channel_2.green = rint(0) channel_2.red = rint(0) channel_2.lookupTable = rstring('rainbow') logical_channel_2 = LogicalChannelI(2L) logical_channel_2.emissionWave = LengthI(470.0, UnitsLength.NANOMETER) logical_channel_2.excitationWave = LengthI(405.0, UnitsLength.NANOMETER) logical_channel_2.fluor = rstring('DAPI') logical_channel_2.name = rstring('DAPI/405') logical_channel_2.ndFilter = rdouble(1.0) logical_channel_2.pinHoleSize = LengthI(2.0, UnitsLength.NANOMETER) logical_channel_2.pockelCellSetting = rint(0) logical_channel_2.samplesPerPixel = rint(2) logical_channel_2.contrastMethod = contrast_method logical_channel_2.illumination = illumination logical_channel_2.mode = acquisition_mode logical_channel_2.photometricInterpretation = photometric_interpretation channel_2.logicalChannel = logical_channel_2 pixels.addChannel(channel_1) pixels.addChannel(channel_2) return image
class ShapeSettingsData(object): ## # Initialises the default values of the ShapeSettings. # Stroke has default colour of darkGrey # StrokeWidth defaults to 1 # def __init__(self): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) self.WHITE = 16777215 self.BLACK = 0 self.GREY = 11184810 self.strokeColour = rint(self.GREY) self.strokeWidth = LengthI() self.strokeWidth.setValue(1) self.strokeWidth.setUnit(UnitsLength.POINT) self.strokeDashArray = rstring('') self.fillColour = rint(self.GREY) self.fillRule = rstring('') ## # Applies the settings in the ShapeSettingsData to the ROITypeI # @param shape the omero.model.ROITypeI that these settings will # be applied to # def setROIShapeSettings(self, shape): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) shape.setStrokeColor(self.strokeColour) shape.setStrokeWidth(self.strokeWidth) shape.setStrokeDashArray(self.strokeDashArray) shape.setFillColor(self.fillColour) shape.setFillRule(self.fillRule) ## # Set the Stroke settings of the ShapeSettings. # @param colour The colour of the stroke. # @param width The stroke width. # def setStrokeSettings(self, colour, width=1): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) self.strokeColour = rint(colour) self.strokeWidth = LengthI() self.strokeWidth.setValue(width) self.strokeWidth.setUnit(UnitsLength.POINT) ### # Set the Fill Settings for the ShapeSettings. # @param colour The fill colour of the shape. def setFillSettings(self, colour): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) self.fillColour = rstring(colour) ## # Get the stroke settings as the tuple (strokeColour, strokeWidth). # @return See above. # def getStrokeSettings(self): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) return (self.strokeColour.getValue(), self.strokeWidth.getValue()) ## # Get the fill setting as a tuple of (fillColour) # @return See above. # def getFillSettings(self): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) return (self.fillColour.getValue()) ## # Get the tuple ((stokeColor, strokeWidth), (fillColour)). # @return see above. # def getSettings(self): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) return (self.getStrokeSettings(), self.getFillSettings()) ## # Set the current shapeSettings from the ROI roi. # @param roi see above. # def getShapeSettingsFromROI(self, roi): warnings.warn("This module is deprecated as of OMERO 5.3.0", DeprecationWarning) self.strokeColour = roi.getStrokeColor() self.strokeWidth = roi.getStrokeWidth() self.strokeDashArray = roi.getStrokeDashArray() self.fillColour = roi.getFillColor() self.fillRule = roi.getFillRule()
class ShapeSettingsData: ## # Initialises the default values of the ShapeSettings. # Stroke has default colour of darkGrey # StrokeWidth defaults to 1 # def __init__(self): self.WHITE = 16777215 self.BLACK = 0 self.GREY = 11184810 self.strokeColour = rint(self.GREY) self.strokeWidth = LengthI() self.strokeWidth.setValue(1) self.strokeWidth.setUnit(UnitsLength.POINT) self.strokeDashArray = rstring('') self.strokeDashOffset = rint(0) self.strokeLineCap = rstring('') self.strokeLineJoin = rstring('') self.strokeMiterLimit = rint(0) self.fillColour = rint(self.GREY) self.fillRule = rstring('') ## # Applies the settings in the ShapeSettingsData to the ROITypeI # @param shape the omero.model.ROITypeI that these settings will # be applied to # def setROIShapeSettings(self, shape): shape.setStrokeColor(self.strokeColour) shape.setStrokeWidth(self.strokeWidth) shape.setStrokeDashArray(self.strokeDashArray) shape.setStrokeDashOffset(self.strokeDashOffset) shape.setStrokeLineCap(self.strokeLineCap) shape.setStrokeLineJoin(self.strokeLineJoin) shape.setStrokeMiterLimit(self.strokeMiterLimit) shape.setFillColor(self.fillColour) shape.setFillRule(self.fillRule) ## # Set the Stroke settings of the ShapeSettings. # @param colour The colour of the stroke. # @param width The stroke width. # def setStrokeSettings(self, colour, width=1): self.strokeColour = rint(colour) self.strokeWidth = LengthI() self.strokeWidth.setValue(width) self.strokeWidth.setUnit(UnitsLength.POINT) ### # Set the Fill Settings for the ShapeSettings. # @param colour The fill colour of the shape. def setFillSettings(self, colour): self.fillColour = rstring(colour) ## # Get the stroke settings as the tuple (strokeColour, strokeWidth). # @return See above. # def getStrokeSettings(self): return (self.strokeColour.getValue(), self.strokeWidth.getValue()) ## # Get the fill setting as a tuple of (fillColour) # @return See above. # def getFillSettings(self): return (self.fillColour.getValue()) ## # Get the tuple ((stokeColor, strokeWidth), (fillColour)). # @return see above. # def getSettings(self): return (self.getStrokeSettings(), self.getFillSettings()) ## # Set the current shapeSettings from the ROI roi. # @param roi see above. # def getShapeSettingsFromROI(self, roi): self.strokeColour = roi.getStrokeColor() self.strokeWidth = roi.getStrokeWidth() self.strokeDashArray = roi.getStrokeDashArray() self.strokeDashOffset = roi.getStrokeDashOffset() self.strokeLineCap = roi.getStrokeLineCap() self.strokeLineJoin = roi.getStrokeLineJoin() self.strokeMiterLimit = roi.getStrokeMiterLimit() self.fillColour = roi.getFillColor() self.fillRule = roi.getFillRule()
def process_data(conn, image, file_type, file_id, locs, sr_pix_size, srz_pix_size, z_range, nm_per_pixel): """ Run the processing and upload the resultant image @param conn: Blitzgateway connection @param image: we need to get the image where the localisation data is attached --> this should be the raw timelapse data @param file_type: the type of dataset we are dealing with (see FILE_TYPES global) @param file_id: the annotation id of the localisations file @param coords: the coords being histogrammed @param sr_pix_size: the pixel size we want in the new image in nm @param z_range: z range covered in one z-plane (4um for Zeiss 3D) @param nm_per_pixel: the size of the pixel in the original image in nm (1 for Zeiss data which is already in nm) """ imageName = image.getName() name, ext = os.path.splitext(imageName) if 'ome' in name: name = name.split('.')[0] new_name = name + '_sr_histogram.ome' + ext sizeZ = image.getSizeT() else: new_name = name + '_sr_histogram' + ext sizeZ = image.getSizeZ() parentDataset = image.getParent() parentProject = parentDataset.getParent() updateService = conn.getUpdateService() frame_width = image.getSizeX() print 'frame_width', frame_width frame_height = image.getSizeY() print 'frame_height', frame_height stepZ = nm_per_pixel[2] print 'sizeZ,stepZ', sizeZ, stepZ if 'zeiss2chan2D' in file_type: sizeC = 2 else: sizeC = 1 sizeT = 1 rangex = frame_width * nm_per_pixel[0] binsx = rangex / sr_pix_size rangey = frame_height * nm_per_pixel[1] binsy = rangey / sr_pix_size rangez = float(z_range) + (sizeZ - 1) * stepZ print 'rangez', rangez binsz = int(math.ceil(rangez / srz_pix_size)) print 'sizeC,binsy,binsx,binsz', sizeC, binsy, binsx, binsz hist_data = numpy.zeros((sizeC, binsy, binsx, binsz)) for c in range(sizeC): hist = calc_hist(locs[c], file_type, binsy, binsx, binsz, rangey, rangex, rangez) hist_data[c, :, :, :] = hist def plane_gen(): for z in range(binsz): for c in range(sizeC): for t in range(sizeT): plane = hist_data[c, :, :, z] yield plane description = "Created from image:\n Name: %s\n File ID: %d" % ( imageName, file_id) newImg = conn.createImageFromNumpySeq(plane_gen(), new_name, sizeZ=binsz, sizeC=sizeC, sizeT=sizeT, description=description) # reload the image (also reloads pixels) image = conn.getObject("Image", newImg.getId()) # Get the BlitzGateway wrapped pixels and unwrap it pixelsWrapper = image.getPrimaryPixels() pixels = pixelsWrapper._obj # Update and save pixSize = LengthI(float(sr_pix_size) / 1000, UnitsLength.MICROMETER) pixSizeZ = LengthI(float(srz_pix_size) / 1000, UnitsLength.MICROMETER) pixels.setPhysicalSizeX(pixSize) pixels.setPhysicalSizeY(pixSize) pixels.setPhysicalSizeZ(pixSize) updateService.saveObject(pixels) if newImg: iid = newImg.getId() print "New Image Id = %s" % iid # put new images in existing dataset dataset = None if parentDataset is not None and parentDataset.canLink(): parentDataset = parentDataset._obj else: parentDataset = None parentProject = None # don't add Dataset to parent. if parentDataset is None: link = None print "No dataset created or found for new images."\ " Images will be orphans." else: dsLink = omero.model.DatasetImageLinkI() dsLink.parent = omero.model.DatasetI(parentDataset.id.val, False) dsLink.child = omero.model.ImageI(iid, False) updateService.saveObject(dsLink) if parentProject and parentProject.canLink(): # and put it in the current project projectLink = omero.model.ProjectDatasetLinkI() projectLink.parent = omero.model.ProjectI( parentProject.getId(), False) projectLink.child = omero.model.DatasetI(dataset.id.val, False) updateService.saveAndReturnObject(projectLink) message = 'Super resolution histogram successfully created' else: message = 'Something went wrong, could not make super resolution histogram' return message