Browse Source

#39: getting individual images works, however, z_level and field of view are wrong

master
Jim Rybarski 10 years ago
parent
commit
c9d3a82930
2 changed files with 18 additions and 29 deletions
  1. +14
    -14
      nd2reader/__init__.py
  2. +4
    -15
      nd2reader/parser.py

+ 14
- 14
nd2reader/__init__.py View File

@ -18,10 +18,10 @@ class Nd2(Nd2Parser):
return "\n".join(["<ND2 %s>" % self._filename,
"Created: %s" % self._absolute_start.strftime("%Y-%m-%d %H:%M:%S"),
"Image size: %sx%s (HxW)" % (self.height, self.width),
"Image cycles: %s" % self._time_index_count,
"Channels: %s" % ", ".join(["'%s'" % str(channel) for channel in self._channels]),
"Fields of View: %s" % self._field_of_view_count,
"Z-Levels: %s" % self._z_level_count
"Image cycles: %s" % len(self.time_indexes),
"Channels: %s" % ", ".join(["'%s'" % str(channel) for channel in self.channels]),
"Fields of View: %s" % len(self.fields_of_view),
"Z-Levels: %s" % len(self.z_levels)
])
def __len__(self):
@ -60,8 +60,8 @@ class Nd2(Nd2Parser):
"""
for i in range(self._image_count):
for fov in range(self._field_of_view_count):
for z_level in range(self._z_level_count):
for fov in self._fields_of_view:
for z_level in self._z_levels:
for channel_name in self._channels:
image = self.get_image(i, fov, channel_name, z_level)
if image is not None:
@ -70,12 +70,12 @@ class Nd2(Nd2Parser):
def __getitem__(self, item):
if isinstance(item, int):
try:
channel_offset = item % self._channel_count
channel_offset = item % len(self.channels)
fov = self._calculate_field_of_view(item)
channel = self._calculate_channel(item)
z_level = self._calculate_z_level(item)
item -= channel_offset
item /= self._channel_count
item /= len(self.channels)
timestamp, raw_image_data = self._get_raw_image_data(item, channel_offset)
image = Image(timestamp, raw_image_data, fov, channel, z_level, self.height, self.width)
except TypeError:
@ -84,13 +84,13 @@ class Nd2(Nd2Parser):
return image
def _calculate_field_of_view(self, frame_number):
return (frame_number - (frame_number % (len(self.channels) + len(self.z_levels))) % len(self.fields_of_view)
return (frame_number - (frame_number % (len(self.channels) + len(self.z_levels)))) % len(self.fields_of_view)
def _calculate_channel(self, frame_number):
return self._channels[frame_number % self._channel_count]
return self._channels[frame_number % len(self.channels)]
def _calculate_z_level(self, frame_number):
return self._z_levels[]
return self.z_levels[frame_number % len(self.channels) % len(self.fields_of_view)]
@property
def image_sets(self):
@ -103,11 +103,11 @@ class Nd2(Nd2Parser):
:return: model.ImageSet()
"""
for time_index in range(self._time_index_count):
for time_index in self._time_indexes:
image_set = ImageSet()
for fov in range(self._field_of_view_count):
for fov in self._fields_of_view:
for channel_name in self._channels:
for z_level in range(self._z_level_count):
for z_level in self._z_levels:
image = self.get_image(time_index, fov, channel_name, z_level)
if image is not None:
image_set.add(image)


+ 4
- 15
nd2reader/parser.py View File

@ -95,8 +95,6 @@ class Nd2Parser(object):
break
else:
raise ValueError("Could not parse metadata dimensions!")
if six.PY3:
return self._dimension_text.decode("utf8")
return self._dimension_text
@property
@ -183,20 +181,11 @@ class Nd2Parser(object):
count = int(re.match(pattern, self._dimensions).group(1))
except AttributeError:
return [0]
except TypeError:
count = int(re.match(pattern, self._dimensions.decode("utf8")).group(1))
return list(range(count))
else:
return range(count)
@property
def channel_count(self):
"""
The number of different channels used, including bright field.
:rtype: int
"""
if self._channel_count is None:
self._channel_count = self._parse_dimension_text(r""".*?λ\((\d+)\).*?""")
return self._channel_count
return list(range(count))
@property
def fields_of_view(self):


Loading…
Cancel
Save