- Improve speed of saving transformed images by parallelization.
- Remove piezoval. - cziread: make color optional.
This commit is contained in:
@@ -47,6 +47,16 @@ class ReaderNotFoundError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TransformTiff(IJTiffFile):
|
||||||
|
""" transform frames in a parallel process to speed up saving """
|
||||||
|
def __init__(self, image, *args, **kwargs):
|
||||||
|
self.image = image
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def compress_frame(self, frame):
|
||||||
|
return super().compress_frame(np.asarray(self.image(*frame)).astype(self.dtype))
|
||||||
|
|
||||||
|
|
||||||
class ImTransforms(Transforms):
|
class ImTransforms(Transforms):
|
||||||
""" Transforms class with methods to calculate channel transforms from bead files etc. """
|
""" Transforms class with methods to calculate channel transforms from bead files etc. """
|
||||||
|
|
||||||
@@ -675,60 +685,6 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin):
|
|||||||
def ndim(self):
|
def ndim(self):
|
||||||
return len(self.shape)
|
return len(self.shape)
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def piezoval(self):
|
|
||||||
""" gives the height of the piezo and focus motor, only available when CylLensGUI was used """
|
|
||||||
|
|
||||||
def upack(idx):
|
|
||||||
time = list()
|
|
||||||
val = list()
|
|
||||||
if len(idx) == 0:
|
|
||||||
return time, val
|
|
||||||
for i in idx:
|
|
||||||
time.append(int(re.search(r'\d+', n[i]).group(0)))
|
|
||||||
val.append(w[i])
|
|
||||||
return zip(*sorted(zip(time, val)))
|
|
||||||
|
|
||||||
# Maybe the values are stored in the metadata
|
|
||||||
n = self.metadata.search('LsmTag|Name')[0]
|
|
||||||
w = self.metadata.search('LsmTag')[0]
|
|
||||||
if n is not None:
|
|
||||||
# n = self.metadata['LsmTag|Name'][1:-1].split(', ')
|
|
||||||
# w = str2float(self.metadata['LsmTag'][1:-1].split(', '))
|
|
||||||
|
|
||||||
pidx = np.where([re.search(r'^Piezo\s\d+$', x) is not None for x in n])[0]
|
|
||||||
sidx = np.where([re.search(r'^Zstage\s\d+$', x) is not None for x in n])[0]
|
|
||||||
|
|
||||||
ptime, pval = upack(pidx)
|
|
||||||
stime, sval = upack(sidx)
|
|
||||||
|
|
||||||
# Or maybe in an extra '.pzl' file
|
|
||||||
else:
|
|
||||||
m = self.extrametadata
|
|
||||||
if m is not None and 'p' in m:
|
|
||||||
q = np.array(m['p'])
|
|
||||||
if not len(q.shape):
|
|
||||||
q = np.zeros((1, 3))
|
|
||||||
|
|
||||||
ptime = [int(i) for i in q[:, 0]]
|
|
||||||
pval = [float(i) for i in q[:, 1]]
|
|
||||||
sval = [float(i) for i in q[:, 2]]
|
|
||||||
|
|
||||||
else:
|
|
||||||
ptime = []
|
|
||||||
pval = []
|
|
||||||
sval = []
|
|
||||||
|
|
||||||
df = pandas.DataFrame(columns=['frame', 'piezoZ', 'stageZ'])
|
|
||||||
df['frame'] = ptime
|
|
||||||
df['piezoZ'] = pval
|
|
||||||
df['stageZ'] = np.array(sval) - np.array(pval) - \
|
|
||||||
self.metadata.re_search(r'AcquisitionModeSetup\|ReferenceZ', 0)[0] * 1e6
|
|
||||||
|
|
||||||
# remove duplicates
|
|
||||||
df = df[~df.duplicated('frame', 'last')]
|
|
||||||
return df
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
return np.prod(self.shape)
|
return np.prod(self.shape)
|
||||||
@@ -1051,6 +1007,10 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin):
|
|||||||
ome = pool.map(get_ome, (path,))[0]
|
ome = pool.map(get_ome, (path,))[0]
|
||||||
return ome
|
return ome
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def ome(self):
|
||||||
|
return self.get_ome(self.path)
|
||||||
|
|
||||||
def is_noise(self, volume=None):
|
def is_noise(self, volume=None):
|
||||||
""" True if volume only has noise """
|
""" True if volume only has noise """
|
||||||
if volume is None:
|
if volume is None:
|
||||||
@@ -1093,14 +1053,11 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin):
|
|||||||
n[i] = (n[i],)
|
n[i] = (n[i],)
|
||||||
|
|
||||||
shape = [len(i) for i in n]
|
shape = [len(i) for i in n]
|
||||||
at_least_one = False
|
with TransformTiff(self, fname.with_suffix('.tif'), shape, pixel_type,
|
||||||
with IJTiffFile(fname.with_suffix('.tif'), shape, pixel_type,
|
|
||||||
pxsize=self.pxsize_um, deltaz=self.deltaz_um, **kwargs) as tif:
|
pxsize=self.pxsize_um, deltaz=self.deltaz_um, **kwargs) as tif:
|
||||||
for i, m in tqdm(zip(product(*[range(s) for s in shape]), product(*n)),
|
for i, m in tqdm(zip(product(*[range(s) for s in shape]), product(*n)),
|
||||||
total=np.prod(shape), desc='Saving tiff', disable=not bar):
|
total=np.prod(shape), desc='Saving tiff', disable=not bar):
|
||||||
if np.any(self(*m)) or not at_least_one:
|
tif.save(m, *i)
|
||||||
tif.save(self(*m), *i)
|
|
||||||
at_least_one = True
|
|
||||||
|
|
||||||
def set_transform(self):
|
def set_transform(self):
|
||||||
# handle transforms
|
# handle transforms
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ class Reader(AbstractReader, ABC):
|
|||||||
id=f"Channel:{idx}",
|
id=f"Channel:{idx}",
|
||||||
name=channel.attrib["Name"],
|
name=channel.attrib["Name"],
|
||||||
acquisition_mode=text(channel.find("AcquisitionMode")),
|
acquisition_mode=text(channel.find("AcquisitionMode")),
|
||||||
color=model.Color(text(channels_ds[channel.attrib["Id"]].find("Color"))),
|
color=model.Color(text(channels_ds[channel.attrib["Id"]].find("Color"), 'white')),
|
||||||
detector_settings=model.DetectorSettings(
|
detector_settings=model.DetectorSettings(
|
||||||
id=detector.attrib["Id"].replace(" ", ""),
|
id=detector.attrib["Id"].replace(" ", ""),
|
||||||
binning=binning),
|
binning=binning),
|
||||||
@@ -381,7 +381,7 @@ class Reader(AbstractReader, ABC):
|
|||||||
id=f"Channel:{idx}",
|
id=f"Channel:{idx}",
|
||||||
name=channel.attrib["Name"],
|
name=channel.attrib["Name"],
|
||||||
acquisition_mode=text(channel.find("AcquisitionMode")),
|
acquisition_mode=text(channel.find("AcquisitionMode")),
|
||||||
color=model.Color(text(channels_ds[channel.attrib["Id"]].find("Color"))),
|
color=model.Color(text(channels_ds[channel.attrib["Id"]].find("Color"), 'white')),
|
||||||
detector_settings=model.DetectorSettings(id=detector.attrib["Id"], binning=binning),
|
detector_settings=model.DetectorSettings(id=detector.attrib["Id"], binning=binning),
|
||||||
# emission_wavelength=text(channel.find("EmissionWavelength")), # TODO: fix
|
# emission_wavelength=text(channel.find("EmissionWavelength")), # TODO: fix
|
||||||
excitation_wavelength=light_source_settings.wavelength,
|
excitation_wavelength=light_source_settings.wavelength,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "ndbioimage"
|
name = "ndbioimage"
|
||||||
version = "2023.10.0"
|
version = "2023.10.1"
|
||||||
description = "Bio image reading, metadata and some affine registration."
|
description = "Bio image reading, metadata and some affine registration."
|
||||||
authors = ["W. Pomp <w.pomp@nki.nl>"]
|
authors = ["W. Pomp <w.pomp@nki.nl>"]
|
||||||
license = "GPLv3"
|
license = "GPLv3"
|
||||||
|
|||||||
Reference in New Issue
Block a user