Browse Source

Merge pull request #134 from jimrybarski/133-index-error

fixes #133. The index assigned to images produced by `select` was wrong.
feature/load_slices
Jim Rybarski 9 years ago
parent
commit
ad9cdcd2ad
3 changed files with 17 additions and 9 deletions
  1. +5
    -0
      functional_tests/FYLM141111001.py
  2. +7
    -3
      nd2reader/driver/v3.py
  3. +5
    -6
      nd2reader/interface.py

+ 5
- 0
functional_tests/FYLM141111001.py View File

@ -133,8 +133,13 @@ class FunctionalTests(unittest.TestCase):
filter_images.append(image)
if len(filter_images) == len(manual_images):
break
self.assertEqual(len(manual_images), len(filter_images))
self.assertGreater(len(manual_images), 0)
for a, b in zip(manual_images, filter_images):
self.assertTrue(np.array_equal(a, b))
self.assertEqual(a.index, b.index)
self.assertEqual(a.field_of_view, b.field_of_view)
self.assertEqual(a.channel, b.channel)
def test_filter_order_all(self):
# If we select every possible image using select(), we should just get every image in order


+ 7
- 3
nd2reader/driver/v3.py View File

@ -24,6 +24,12 @@ class V3Driver(object):
self._label_map = label_map
self._file_handle = file_handle
def calculate_image_properties(self, index):
field_of_view = self._calculate_field_of_view(index)
channel = self._calculate_channel(index)
z_level = self._calculate_z_level(index)
return field_of_view, channel, z_level
def get_image(self, index):
"""
Creates an Image object and adds its metadata, based on the index (which is simply the order in which the image was acquired). May return None if the ND2 contains
@ -35,10 +41,8 @@ class V3Driver(object):
:rtype: Image or None
"""
field_of_view, channel, z_level = self.calculate_image_properties(index)
channel_offset = index % len(self._metadata.channels)
field_of_view = self._calculate_field_of_view(index)
channel = self._calculate_channel(index)
z_level = self._calculate_z_level(index)
image_group_number = int(index / len(self._metadata.channels))
frame_number = self._calculate_frame_number(image_group_number, field_of_view, z_level)
try:


+ 5
- 6
nd2reader/interface.py View File

@ -77,12 +77,11 @@ class Nd2(object):
z_levels = self._to_list(z_levels, self.z_levels)
for frame in self.frames:
for f in fields_of_view:
for z in z_levels:
for c in channels:
image = self.get_image(frame, f, c, z)
if image is not None:
yield image
field_of_view, channel, z_level = self._parser.driver.calculate_image_properties(frame)
if field_of_view in fields_of_view and channel in channels and z_level in z_levels:
image = self._parser.driver.get_image(frame)
if image is not None:
yield image
@property
def height(self):


Loading…
Cancel
Save