Browse Source

Merge pull request #93 from jimrybarski/90-attribute-error

resolves #90
master
Jim Rybarski 9 years ago
parent
commit
438bd32337
3 changed files with 16 additions and 5 deletions
  1. +7
    -2
      nd2reader/interface.py
  2. +6
    -1
      nd2reader/model/metadata.py
  3. +3
    -2
      nd2reader/parser/v3.py

+ 7
- 2
nd2reader/interface.py View File

@ -36,7 +36,7 @@ class Nd2(object):
:rtype: int
"""
return self._driver.total_images_per_channel * len(self.channels)
return self._metadata.total_images_per_channel * len(self.channels)
def __getitem__(self, item):
"""
@ -56,7 +56,12 @@ class Nd2(object):
"""
if isinstance(item, int):
return self._driver.get_image(item)
try:
image = self._driver.get_image(item)
except KeyError:
raise IndexError
else:
return image
elif isinstance(item, slice):
return self._slice(item.start, item.stop, item.step)
raise IndexError


+ 6
- 1
nd2reader/model/metadata.py View File

@ -1,6 +1,6 @@
class Metadata(object):
""" A simple container for ND2 metadata. """
def __init__(self, height, width, channels, date, fields_of_view, frames, z_levels):
def __init__(self, height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel):
self._height = height
self._width = width
self._channels = channels
@ -8,6 +8,7 @@ class Metadata(object):
self._fields_of_view = fields_of_view
self._frames = frames
self._z_levels = z_levels
self._total_images_per_channel = total_images_per_channel
@property
def height(self):
@ -70,3 +71,7 @@ class Metadata(object):
"""
return self._z_levels
@property
def total_images_per_channel(self):
return self._total_images_per_channel

+ 3
- 2
nd2reader/parser/v3.py View File

@ -52,7 +52,8 @@ class V3Parser(BaseParser):
fields_of_view = self._parse_fields_of_view(metadata_dict)
frames = self._parse_frames(metadata_dict)
z_levels = self._parse_z_levels(metadata_dict)
self._metadata = Metadata(height, width, channels, date, fields_of_view, frames, z_levels)
total_images_per_channel = self._parse_total_images_per_channel(metadata_dict)
self._metadata = Metadata(height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel)
def _parse_date(self, metadata_dict):
"""
@ -122,7 +123,7 @@ class V3Parser(BaseParser):
:rtype: list
"""
return self._parse_dimension(r""".*?T'\((\d+)\).*?""", metadata_dict)
return self._parse_dimension(r""".*?T'?\((\d+)\).*?""", metadata_dict)
def _parse_z_levels(self, metadata_dict):
"""


Loading…
Cancel
Save