- transforms bugfixes

This commit is contained in:
Wim Pomp
2023-10-12 14:55:37 +02:00
parent 96ab3174d7
commit 7797f38a59
5 changed files with 18 additions and 7 deletions

View File

@@ -40,6 +40,7 @@ except (Exception,):
ureg.default_format = '~P'
set_application_registry(ureg)
warnings.filterwarnings('ignore', 'Reference to unknown ID')
class ReaderNotFoundError(Exception):
@@ -51,7 +52,7 @@ class ImTransforms(Transforms):
def __init__(self, path, cyllens, file=None, transforms=None):
super().__init__()
self.cyllens = cyllens
self.cyllens = tuple(cyllens)
if transforms is None:
# TODO: check this
if re.search(r'^Pos\d+', path.name):
@@ -106,7 +107,7 @@ class ImTransforms(Transforms):
files = (Path(files),)
elif isinstance(files, Path):
files = (files,)
return files
return tuple(files)
except (Exception,):
return ()
@@ -1375,6 +1376,13 @@ class AbstractReader(Imread, metaclass=ABCMeta):
else:
self.immersionN = 1
p = re.compile(r'(\d+):(\d+)$')
try:
self.track, self.detector = zip(*[[int(i) for i in p.findall(find(
self.ome.images[0].pixels.channels, id=f'Channel:{c}').detector_settings.id)[0]]
for c in range(self.shape['c'])])
except Exception:
pass
def main():
parser = ArgumentParser(description='Display info and save as tif')

View File

@@ -182,7 +182,7 @@ class Reader(AbstractReader, ABC):
ome.images[0].pixels.channels.append(
model.Channel(
id=f"Channel:0:{idx}",
id=f"Channel:{idx}",
name=channel.attrib["Name"],
acquisition_mode=text(channel.find("AcquisitionMode")),
color=model.Color(text(channels_ds[channel.attrib["Id"]].find("Color"))),
@@ -378,12 +378,12 @@ class Reader(AbstractReader, ABC):
ome.images[0].pixels.channels.append(
model.Channel(
id=f"Channel:0:{idx}",
id=f"Channel:{idx}",
name=channel.attrib["Name"],
acquisition_mode=text(channel.find("AcquisitionMode")),
color=model.Color(text(channels_ds[channel.attrib["Id"]].find("Color"))),
detector_settings=model.DetectorSettings(id=detector.attrib["Id"], binning=binning),
emission_wavelength=text(channel.find("EmissionWavelength")),
# emission_wavelength=text(channel.find("EmissionWavelength")), # TODO: fix
excitation_wavelength=light_source_settings.wavelength,
filter_set_ref=model.FilterSetRef(id=ome.instruments[0].filter_sets[filterset_idx].id),
illumination_type=text(channel.find("IlluminationType")),

View File

@@ -15,7 +15,7 @@ def lazy_property(function, field, *arg_fields):
def lazy(self):
if self.__dict__.get(field) is None:
self.__dict__[field] = function(*[getattr(self, arg_field) for arg_field in arg_fields])
self.__fields_set__.add(field)
self.model_fields_set.add(field)
return self.__dict__[field]
return property(lazy)

View File

@@ -66,6 +66,9 @@ class Transforms(dict):
def __setstate__(self, state):
self.__dict__.update(state)
def __hash__(self):
return hash(frozenset((*self.__dict__.items(), *self.items())))
def save(self, file):
with open(file.with_suffix(".yml"), 'w') as f:
yaml.safe_dump(self.asdict(), f, default_flow_style=None)

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "ndbioimage"
version = "2023.9.0"
version = "2023.10.0"
description = "Bio image reading, metadata and some affine registration."
authors = ["W. Pomp <w.pomp@nki.nl>"]
license = "GPLv3"