Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def Pixels(self):
"""The OME/Image/Pixels element.
Example:
>>> md = bioformats.omexml.OMEXML(xml)
>>> pixels = omemetadata.image(i).Pixels
>>> channel_count = pixels.SizeC
>>> stack_count = pixels.SizeZ
>>> timepoint_count = pixels.SizeT
"""
return OMEXML.Pixels(self.node.find(qn(self.ns['ome'], "Pixels")))
def __getitem__(self, key):
plates = self.root.findall(qn(self.ns['spw'], "Plate"))
if isinstance(key, slice):
return [OMEXML.Plate(plate) for plate in plates[key]]
return OMEXML.Plate(plates[key])
def set_channel_count(self, value):
assert value >= 0
channel_count = self.channel_count
if channel_count > value:
channels = self.node.findall(qn(self.ns['ome'], "Channel"))
for channel in channels[value:]:
self.node.remove(channel)
else:
for _ in range(channel_count, value):
new_channel = OMEXML.Channel(
ElementTree.SubElement(self.node, qn(self.ns['ome'], "Channel")))
new_channel.ID = str(uuid.uuid4())
new_channel.Name = new_channel.ID
new_channel.SamplesPerPixel = 1
def get_Sample(self):
return OMEXML.WellSampleDucktype(self.node)
def __iter__(self):
"""Return the standard name for all wells on the plate
for instance, 'B03' for a well with Row=1, Column=2 for a plate
with the standard row and column naming convention
"""
all_wells = self.plate_node.findall(qn(self.ns['spw'], "Well"))
well = OMEXML.Well(None)
for w in all_wells:
well.node = w
yield self.plate.get_well_name(well)
def get_Well(self):
'''The well dictionary / list'''
return OMEXML.WellsDucktype(self)
Well = property(get_Well)
def _lazy_init_metadata(self) -> omexml.OMEXML:
with TiffFile(self._file) as tiff:
if self._metadata is None and tiff.is_ome:
description = tiff.pages[0].description.strip()
if not (
description.startswith("")
):
raise ValueError(
f"Description does not conform to OME specification: "
f"{description[:100]}"
)
self._metadata = omexml.OMEXML(description)
return self._metadata
def Plane(self, index=0):
"""Get the indexed plane from the Pixels element"""
plane = self.node.findall(qn(self.ns['ome'], "Plane"))[index]
return OMEXML.Plane(plane)
... writer.save(image)
Using the context manager to close the write once done.
>>> image2 = numpy.ndarray([5, 486, 210])
... with ome_tiff_writer.OmeTiffWriter("file2.ome.tif") as writer2:
... writer2.save(image2)
Convert a CZI file into OME-Tiff
>>> reader = cziReader.CziReader("file3.czi")
... with ome_tiff_writer.OmeTiffWriter("file3.ome.tif") as writer3:
... writer.save(reader.load())
"""
self.file_path = file_path
self.omeMetadata = omexml.OMEXML()
self.silent_pass = False
if os.path.isfile(self.file_path):
if overwrite_file:
os.remove(self.file_path)
elif overwrite_file is None:
raise IOError(
"File {} exists but user has chosen not to overwrite it".format(
self.file_path
)
)
elif overwrite_file is False:
self.silent_pass = True