- Transforms cast_image fix.

- Prevent invalid value in log in is_noise.
- Fix bug when no bead_files found.
- Deal with some more czi files.
This commit is contained in:
Wim Pomp
2023-12-04 17:14:12 +01:00
parent a6457ea497
commit 5508de14f8
4 changed files with 37 additions and 21 deletions

View File

@@ -828,7 +828,7 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin, ABC):
volume = self volume = self
fft = np.fft.fftn(volume) fft = np.fft.fftn(volume)
corr = np.fft.fftshift(np.fft.ifftn(fft * fft.conj()).real / np.sum(volume ** 2)) corr = np.fft.fftshift(np.fft.ifftn(fft * fft.conj()).real / np.sum(volume ** 2))
return -np.log(1 - corr[tuple([0] * corr.ndim)]) > 5 return 1 - corr[tuple([0] * corr.ndim)] < 0.0067
@staticmethod @staticmethod
def kill_vm(): def kill_vm():
@@ -882,13 +882,16 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin, ABC):
if file is None: if file is None:
file = Path(view.path.parent) / 'transform.yml' file = Path(view.path.parent) / 'transform.yml'
if not bead_files: if not bead_files:
bead_files = Transforms.get_bead_files(view.path.parent) try:
bead_files = Transforms.get_bead_files(view.path.parent)
except Exception:
if not file.exists():
raise Exception('No transform file and no bead file found.')
bead_files = ()
if channels: if channels:
try: try:
view.transform = Transforms.from_file(file, T=drift) view.transform = Transforms.from_file(file, T=drift)
# for key in view.channel_names:
# if
except Exception: # noqa except Exception: # noqa
view.transform = Transforms().with_beads(view.cyllens, bead_files) view.transform = Transforms().with_beads(view.cyllens, bead_files)
if drift: if drift:

View File

@@ -98,11 +98,17 @@ class Reader(AbstractReader, ABC):
nominal_magnification=float(text(objective.find("NominalMagnification"))))) nominal_magnification=float(text(objective.find("NominalMagnification")))))
for tubelens in instrument.find("TubeLenses"): for tubelens in instrument.find("TubeLenses"):
try:
nominal_magnification = float(re.findall(r'\d+(?:[,.]\d*)?',
tubelens.attrib["Name"])[0].replace(',', '.'))
except Exception:
nominal_magnification = 1.0
ome.instruments[0].objectives.append( ome.instruments[0].objectives.append(
model.Objective( model.Objective(
id=f'Objective:{tubelens.attrib["Id"]}', id=f'Objective:{tubelens.attrib["Id"]}',
model=tubelens.attrib["Name"], model=tubelens.attrib["Name"],
nominal_magnification=1.0)) # TODO: nominal_magnification nominal_magnification=nominal_magnification))
for light_source in def_list(instrument.find("LightSources")): for light_source in def_list(instrument.find("LightSources")):
if light_source.find("LightSourceType").find("Laser") is not None: if light_source.find("LightSourceType").find("Laser") is not None:
@@ -126,8 +132,11 @@ class Reader(AbstractReader, ABC):
if pixel_type.startswith("Gray"): if pixel_type.startswith("Gray"):
pixel_type = "uint" + pixel_type[4:] pixel_type = "uint" + pixel_type[4:]
objective_settings = image.find("ObjectiveSettings") objective_settings = image.find("ObjectiveSettings")
scenes = image.find("Dimensions").find("S").find("Scenes") try: # TODO
center_position = [float(pos) for pos in text(scenes[0].find("CenterPosition")).split(',')] scenes = image.find("Dimensions").find("S").find("Scenes")
center_position = [float(pos) for pos in text(scenes[0].find("CenterPosition")).split(',')]
except AttributeError:
center_position = [0, 0]
um = model.UnitsLength.MICROMETER um = model.UnitsLength.MICROMETER
nm = model.UnitsLength.NANOMETER nm = model.UnitsLength.NANOMETER
@@ -174,31 +183,35 @@ class Reader(AbstractReader, ABC):
light_sources_settings = channel.find("LightSourcesSettings") light_sources_settings = channel.find("LightSourcesSettings")
# no space in ome for multiple lightsources simultaneously # no space in ome for multiple lightsources simultaneously
light_source_settings = light_sources_settings[0] if light_sources_settings is not None:
light_source_settings = model.LightSourceSettings( light_source_settings = light_sources_settings[0]
id="LightSource:" + "_".join([light_source_settings.find("LightSource").attrib["Id"] light_source_settings = model.LightSourceSettings(
for light_source_settings in light_sources_settings]), id="LightSource:" + "_".join([light_source_settings.find("LightSource").attrib["Id"]
attenuation=float(text(light_source_settings.find("Attenuation"))), for light_source_settings in light_sources_settings]),
wavelength=float(text(light_source_settings.find("Wavelength"))), attenuation=float(text(light_source_settings.find("Attenuation"))),
wavelength_unit=nm) wavelength=float(text(light_source_settings.find("Wavelength"))),
wavelength_unit=nm)
else:
light_source_settings = None
ome.images[0].pixels.channels.append( ome.images[0].pixels.channels.append(
model.Channel( model.Channel(
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")).replace('SingleMoleculeLocalisation',
'SingleMoleculeImaging'),
color=model.Color(text(channels_ds[channel.attrib["Id"]].find("Color"), 'white')), 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),
emission_wavelength=text(channel.find("EmissionWavelength")), emission_wavelength=i if (i := text(channel.find("EmissionWavelength"))) != '0' else '100',
excitation_wavelength=text(channel.find("ExcitationWavelength")), excitation_wavelength=text(channel.find("ExcitationWavelength")),
# filter_set_ref=model.FilterSetRef(id=ome.instruments[0].filter_sets[filterset_idx].id), # filter_set_ref=model.FilterSetRef(id=ome.instruments[0].filter_sets[filterset_idx].id),
illumination_type=text(channel.find("IlluminationType")), illumination_type=text(channel.find("IlluminationType")),
light_source_settings=light_source_settings, light_source_settings=light_source_settings,
samples_per_pixel=int(text(laser_scan_info.find("Averaging"))))) samples_per_pixel=int(text(laser_scan_info.find("Averaging"), "1"))))
exposure_times = [float(text(channel.find("LaserScanInfo").find("FrameTime"))) for channel in exposure_times = [float(text(channel.find("LaserScanInfo").find("FrameTime"), "100")) for channel in
channels_im.values()] channels_im.values()]
delta_ts = attachments['TimeStamps'].data() delta_ts = attachments['TimeStamps'].data()
for t, z, c in product(range(size_t), range(size_z), range(size_c)): for t, z, c in product(range(size_t), range(size_z), range(size_c)):

View File

@@ -345,8 +345,8 @@ class Transform:
@staticmethod @staticmethod
def cast_image(im): def cast_image(im):
if isinstance(im, sitk.Image): if not isinstance(im, sitk.Image):
im = sitk.GetImageFromArray(im) im = sitk.GetImageFromArray(np.asarray(im))
return im return im
@staticmethod @staticmethod

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "ndbioimage" name = "ndbioimage"
version = "2023.11.1" version = "2023.12.0"
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"