- bugfix: reading wrong frame in some cases when opened with custom axes argument

- some more try except in czi metadata reading
- bugfix: Pos pattern in seqread
This commit is contained in:
Wim Pomp
2025-01-24 15:53:51 +01:00
parent 00abb8a684
commit c34b52cb55
6 changed files with 41 additions and 25 deletions

View File

@@ -1200,6 +1200,7 @@ class AbstractReader(Imread, metaclass=ABCMeta):
image = self.ome.images[self.series if len(self.ome.images) > 1 else 0]
pixels = image.pixels
self.shape = pixels.size_y, pixels.size_x, pixels.size_c, pixels.size_z, pixels.size_t
self.base_shape = Shape((pixels.size_y, pixels.size_x, pixels.size_c, pixels.size_z, pixels.size_t), 'yxczt')
self.dtype = pixels.type.value if dtype is None else dtype
self.pxsize = pixels.physical_size_x_quantity
try:

View File

@@ -184,7 +184,7 @@ class Reader(AbstractReader, ABC):
return OmeParse.get_ome(self.reader, self.filedict)
def __frame__(self, c: int = 0, z: int = 0, t: int = 0) -> np.ndarray:
f = np.zeros(self.base.shape['yx'], self.dtype)
f = np.zeros(self.base_shape['yx'], self.dtype)
if (c, z, t) in self.filedict:
directory_entries = self.filedict[c, z, t]
x_min = min([f.start[f.axes.index('X')] for f in directory_entries])
@@ -340,11 +340,14 @@ class OmeParse:
if self.version == '1.0':
for idx, tube_lens in enumerate({self.text(track_setup.find('TubeLensPosition'))
for track_setup in self.multi_track_setup}):
try:
nominal_magnification = float(re.findall(r'\d+[,.]\d*', tube_lens)[0].replace(',', '.'))
except Exception: # noqa
nominal_magnification = 1.0
self.ome.instruments[0].objectives.append(
model.Objective(id=f'Objective:Tubelens:{idx}', model=tube_lens,
nominal_magnification=float(
re.findall(r'\d+[,.]\d*', tube_lens)[0].replace(',', '.'))
))
nominal_magnification=nominal_magnification))
elif self.version in ('1.1', '1.2'):
for tubelens in self.instrument.find('TubeLenses'):
try:
@@ -362,6 +365,7 @@ class OmeParse:
def get_light_sources(self) -> None:
if self.version == '1.0':
for light_source in self.def_list(self.instrument.find('LightSources')):
try:
if light_source.find('LightSourceType').find('Laser') is not None:
self.ome.instruments[0].lasers.append(
model.Laser(
@@ -370,14 +374,19 @@ class OmeParse:
power=float(self.text(light_source.find('Power'))),
wavelength=float(
self.text(light_source.find('LightSourceType').find('Laser').find('Wavelength')))))
except AttributeError:
pass
elif self.version in ('1.1', '1.2'):
for light_source in self.def_list(self.instrument.find('LightSources')):
try:
if light_source.find('LightSourceType').find('Laser') is not None:
self.ome.instruments[0].lasers.append(
model.Laser(
id=f"LightSource:{light_source.attrib['Id']}",
power=float(self.text(light_source.find('Power'))),
wavelength=float(light_source.attrib['Id'][-3:])))
except AttributeError:
pass
def get_filters(self) -> None:
if self.version == '1.0':

View File

@@ -26,7 +26,7 @@ class Reader(AbstractReader, ABC):
def __frame__(self, c, z, t): # Override this, return the frame at c, z, t
self.reader.filehandle.seek(self.offset + t * self.count)
return np.reshape(unpack(self.fmt, self.reader.filehandle.read(self.count)), self.shape['yx'])
return np.reshape(unpack(self.fmt, self.reader.filehandle.read(self.count)), self.base_shape['yx'])
def open(self):
warn(f'File {self.path.name} is probably damaged, opening with fijiread.')

View File

@@ -114,9 +114,15 @@ class Reader(AbstractReader, ABC):
return ome
def open(self):
pat = re.compile(r'(?:\d+-)?Pos.*', re.IGNORECASE)
if pat.match(self.path.name) is None:
path = sorted(file for file in self.path.iterdir() if pat.match(file.name))[self.series]
# /some_path/Pos4: path = /some_path, series = 4
# /some_path/5-Pos_001_005: path = /some_path/5-Pos_001_005, series = 0
if re.match(r'(?:\d+-)?Pos.*', self.path.name, re.IGNORECASE) is None:
pat = re.compile(rf'^(?:\d+-)?Pos{self.series}$', re.IGNORECASE)
files = sorted(file for file in self.path.iterdir() if pat.match(file.name))
if len(files):
path = files[0]
else:
raise FileNotFoundError(self.path / pat.pattern)
else:
path = self.path

View File

@@ -80,6 +80,6 @@ class Reader(AbstractReader, ABC):
def __frame__(self, c, z, t):
if self.p_ndim == 3:
return np.transpose(self.reader.asarray(z + t * self.base.shape['z']), self.p_transpose)[c]
return np.transpose(self.reader.asarray(z + t * self.base_shape['z']), self.p_transpose)[c]
else:
return self.reader.asarray(c + z * self.base.shape['c'] + t * self.base.shape['c'] * self.base.shape['z'])
return self.reader.asarray(c + z * self.base_shape['c'] + t * self.base_shape['c'] * self.base_shape['z'])

View File

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