def pix(self, x=10, y=10, z=10, c=3, t=50, client=None): """ Creates an int8 pixel of the given size in the database. No data is written. """ image = self.new_image() pixels = PixelsI() pixels.sizeX = rint(x) pixels.sizeY = rint(y) pixels.sizeZ = rint(z) pixels.sizeC = rint(c) pixels.sizeT = rint(t) pixels.sha1 = rstring("") pixels.pixelsType = PixelsTypeI() pixels.pixelsType.value = rstring("int8") pixels.dimensionOrder = DimensionOrderI() pixels.dimensionOrder.value = rstring("XYZCT") image.addPixels(pixels) if client is None: client = self.client update = client.sf.getUpdateService() image = update.saveAndReturnObject(image) pixels = image.getPrimaryPixels() return pixels
def test_simple_marshal_tiled(self, wrapped_image): image = wrapped_image._obj pixels = PixelsI() pixels.sizeX = rint(65) pixels.sizeY = rint(65) image.addPixels(pixels) data = wrapped_image.simpleMarshal(xtra={'tiled': True}) self.assert_data(data) assert data['tiled'] is True
def create_image(image_index): image = ImageI() image.name = rstring('%s_%d' % (uuid(), image_index)) image.acquisitionDate = rtime(0) pixels = PixelsI() pixels.sha1 = rstring('') pixels.sizeX = rint(1) pixels.sizeY = rint(1) pixels.sizeZ = rint(1) pixels.sizeC = rint(1) pixels.sizeT = rint(1) pixels.dimensionOrder = DimensionOrderI(1L, False) # XYZCT pixels.pixelsType = PixelsTypeI(1L, False) # bit image.addPixels(pixels) return image
def testTiles(self): from omero.model import PixelsI from omero.sys import ParametersI from omero.util.tiles import RPSTileLoop from omero.util.tiles import TileLoopIteration from numpy import fromfunction sizeX = 4096 sizeY = 4096 sizeZ = 1 sizeC = 1 sizeT = 1 tileWidth = 1024 tileHeight = 1024 imageName = "testStitchBig4K-1Ktiles" description = None tile_max = float(255) pixelsService = self.client.sf.getPixelsService() queryService = self.client.sf.getQueryService() query = "from PixelsType as p where p.value='int8'" pixelsType = queryService.findByQuery(query, None) channelList = range(sizeC) iId = pixelsService.createImage(sizeX, sizeY, sizeZ, sizeT, channelList, pixelsType, imageName, description) image = queryService.findByQuery( "select i from Image i join fetch i.pixels where i.id = :id", ParametersI().addId(iId)) pid = image.getPrimaryPixels().getId().getValue() def f(x, y): """ create some fake pixel data tile (2D numpy array) """ return (x * y) / (1 + x + y) def mktile(w, h): tile = fromfunction(f, (w, h)) tile = tile.astype(int) tile[tile > tile_max] = tile_max return list(tile.flatten()) tile = fromfunction(f, (tileWidth, tileHeight)).astype(int) tile_min = float(tile.min()) tile_max = min(tile_max, float(tile.max())) class Iteration(TileLoopIteration): def run(self, data, z, c, t, x, y, tileWidth, tileHeight, tileCount): tile2d = mktile(tileWidth, tileHeight) data.setTile(tile2d, z, c, t, x, y, tileWidth, tileHeight) loop = RPSTileLoop(self.client.sf, PixelsI(pid, False)) loop.forEachTile(256, 256, Iteration()) c = 0 pixelsService.setChannelGlobalMinMax(pid, c, tile_min, tile_max)
def import_pyramid_pre_fs(self, tmpdir): name = "test&sizeX=4000&sizeY=4000.fake" fakefile = tmpdir.join(name) fakefile.write('') pixels = self.import_image(filename=str(fakefile), skip="checksum")[0] id = long(float(pixels)) # wait for the pyramid to be generated self.wait_for_pyramid(id) query_service = self.client.sf.getQueryService() pixels_service = self.client.sf.getPixelsService() orig_pix = query_service.findByQuery( "select p from Pixels p where p.id = :id", ParametersI().addId(id)) orig_fs = query_service.findByQuery( "select f from Image i join i.fileset f where i.id = :id", ParametersI().addId(orig_pix.image.id.val)) try: new_img = pixels_service.copyAndResizeImage( orig_pix.image.id.val, rint(4000), rint(4000), rint(1), rint(1), [0], None, True).val pix_id = unwrap( query_service.projection( "select p.id from Image i join i.pixels p where i.id = :id", ParametersI().addId(new_img)))[0][0] # This won't work but it but we then have a pyramid without fileset self.copyPixels(orig_pix, PixelsI(pix_id, False)) except omero.InternalException: print "Cannot copy pixels for image %s" % orig_pix.image.id.val finally: self.delete([orig_fs]) return pix_id
def create_image(image_index): image = ImageI() image.name = rstring("%s_%d" % (uuid(), image_index)) image.acquisitionDate = rtime(0) pixels = PixelsI() pixels.sha1 = rstring("") pixels.sizeX = rint(1) pixels.sizeY = rint(1) pixels.sizeZ = rint(1) pixels.sizeC = rint(1) pixels.sizeT = rint(1) pixels.dimensionOrder = DimensionOrderI(1L, False) # XYZCT pixels.pixelsType = PixelsTypeI(1L, False) # bit image.addPixels(pixels) return image
def duplicateMIF(self, orig_img): """ Use copyAndResizeImage to create a "synthetic" image (one without a fileset) """ new_img = self.pixels.copyAndResizeImage( orig_img.id.val, rint(16), rint(16), rint(1), rint(1), [0], None, True).val pix_id = unwrap(self.query.projection( "select p.id from Image i join i.pixels p where i.id = :id", ParametersI().addId(new_img)))[0][0] new_img = ImageI(new_img, False) new_pix = PixelsI(pix_id, False) return new_img, new_pix
def run(password, target, host, port): for i in range(1, 51): username = "******" % i print(username) conn = BlitzGateway(username, password, host=host, port=port) try: conn.connect() params = omero.sys.ParametersI() params.addString('username', username) query = "from Dataset where name='%s' \ AND details.owner.omeName=:username" % target query_service = conn.getQueryService() datasets = query_service.findAllByQuery(query, params, conn.SERVICE_OPTS) if len(datasets) == 0: print("No datasets with name %s found" % target) continue dataset_id = datasets[0].getId().getValue() print('dataset', dataset_id) params2 = omero.sys.ParametersI() params2.addId(dataset_id) query = "select l.child.id from DatasetImageLink l \ where l.parent.id = :id" images = query_service.projection(query, params2, conn.SERVICE_OPTS) for k in range(0, len(images)): image_id = images[k][0].getValue() delta_t = 300 image = conn.getObject("Image", image_id) params = omero.sys.ParametersI() params.addLong('pid', image.getPixelsId()) query = "from PlaneInfo as Info where \ Info.theZ=0 and Info.theC=0 and pixels.id=:pid" info_list = query_service.findAllByQuery( query, params, conn.SERVICE_OPTS) print('info_list', len(info_list)) if len(info_list) == 0: print("Creating info...", image.getSizeT()) info_list = [] for t_index in range(image.getSizeT()): print(' t', t_index) info = PlaneInfoI() info.theT = rint(t_index) info.theZ = rint(0) info.theC = rint(0) info.pixels = PixelsI(image.getPixelsId(), False) dt = t_index * delta_t info.deltaT = TimeI(dt, UnitsTime.SECOND) info_list.append(info) else: for info in info_list: unwrap_t = unwrap(info.theT) unwrap_z = unwrap(info.theZ) print('theT %s, theZ %s' % (unwrap_t, unwrap_z)) t_index = info.theT.getValue() dt = t_index * delta_t info.deltaT = TimeI(dt, UnitsTime.SECOND) print("Saving info_list", len(info_list)) conn.getUpdateService().saveArray(info_list) except Exception as exc: print("Error when setting the timestamps: %s" % str(exc)) finally: conn.close()
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
def create_image_from_tiles(conn, source, image_name, description, box, tile_size): pixels_service = conn.getPixelsService() query_service = conn.getQueryService() xbox, ybox, wbox, hbox, z1box, z2box, t1box, t2box = box size_x = wbox size_y = hbox size_z = source.getSizeZ() size_t = source.getSizeT() size_c = source.getSizeC() tile_width = tile_size tile_height = tile_size primary_pixels = source.getPrimaryPixels() def create_image(): query = "from PixelsType as p where p.value='uint8'" pixels_type = query_service.findByQuery(query, None) channel_list = range(size_c) # bytesPerPixel = pixelsType.bitSize.val / 8 iid = pixels_service.createImage( size_x, size_y, size_z, size_t, channel_list, pixels_type, image_name, description, conn.SERVICE_OPTS) return conn.getObject("Image", iid) # Make a list of all the tiles we're going to need. # This is the SAME ORDER that RPSTileLoop will ask for them. zct_tile_list = [] for t in range(0, size_t): for c in range(0, size_c): for z in range(0, size_z): for tile_offset_y in range( 0, ((size_y + tile_height - 1) / tile_height)): for tile_offset_x in range( 0, ((size_x + tile_width - 1) / tile_width)): x = tile_offset_x * tile_width y = tile_offset_y * tile_height w = tile_width if (w + x > size_x): w = size_x - x h = tile_height if (h + y > size_y): h = size_y - y tile_xywh = (xbox + x, ybox + y, w, h) zct_tile_list.append((z, c, t, tile_xywh)) # This is a generator that will return tiles in the sequence above # getTiles() only opens 1 rawPixelsStore for all the tiles # whereas getTile() opens and closes a rawPixelsStore for each tile. tile_gen = primary_pixels.getTiles(zct_tile_list) def next_tile(): return tile_gen.next() class Iteration(TileLoopIteration): def run(self, data, z, c, t, x, y, tile_width, tile_height, tile_count): tile2d = next_tile() data.setTile(tile2d, z, c, t, x, y, tile_width, tile_height) new_image = create_image() pid = new_image.getPixelsId() loop = RPSTileLoop(conn.c.sf, PixelsI(pid, False)) loop.forEachTile(tile_width, tile_height, Iteration()) for the_c in range(size_c): pixels_service.setChannelGlobalMinMax(pid, the_c, float(0), float(255), conn.SERVICE_OPTS) return new_image
def create_image(image_id, with_pixels=False): image_format = FormatI(1) image_format.value = rstring('PNG') image = ImageI() image.id = rlong(image_id) image.acquisitionDate = rtime(1) 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(1) dimension_order.value = rstring('XYZCT') pixels_type = PixelsTypeI(1) pixels_type.value = 'bit' pixels = PixelsI(1) 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(8) contrast_method.value = rstring('Fluorescence') illumination = IlluminationI(1) illumination.value = rstring('Transmitted') acquisition_mode = AcquisitionModeI(1) acquisition_mode.value = rstring('WideField') photometric_interpretation = PhotometricInterpretationI(1) photometric_interpretation.value = rstring('RGB') channel_1 = ChannelI(1) channel_1.alpha = rint(255) channel_1.blue = rint(255) channel_1.green = rint(255) channel_1.red = rint(255) channel_1.lookupTable = rstring('rainbow') logical_channel_1 = LogicalChannelI(1) 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(2) channel_2.alpha = rint(255) channel_2.blue = rint(255) channel_2.green = rint(0) channel_2.red = rint(255) channel_2.lookupTable = rstring('rainbow') logical_channel_2 = LogicalChannelI(2) 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