Browse Source

resolves #106: implemented missing method and added tests

zolfa-add_slices_loading
Jim Rybarski 9 years ago
parent
commit
90ae0907de
3 changed files with 27 additions and 1 deletions
  1. +12
    -0
      functional_tests/FYLM141111001.py
  2. +14
    -0
      nd2reader/driver/v3.py
  3. +1
    -1
      nd2reader/interface.py

+ 12
- 0
functional_tests/FYLM141111001.py View File

@ -66,3 +66,15 @@ class FunctionalTests(unittest.TestCase):
def test_iteration_backwards(self):
images = [image for image in self.nd2[:10:-1]]
self.assertEqual(len(images), 10)
def test_get_image_by_attribute_ok(self):
image = self.nd2.get_image(4, 0, "GFP", 1)
self.assertIsNotNone(image)
image = self.nd2.get_image(4, 0, "", 0)
self.assertIsNotNone(image)
image = self.nd2.get_image(4, 0, "", 1)
self.assertIsNotNone(image)
def test_get_image_by_attribute_none(self):
image = self.nd2.get_image(4, 0, "GFP", 0)
self.assertIsNone(image)

+ 14
- 0
nd2reader/driver/v3.py View File

@ -101,3 +101,17 @@ class V3Driver(object):
if np.any(image_data):
return timestamp, Image(image_data)
raise NoImageError
def get_image_by_attributes(self, frame_number, field_of_view, channel_name, z_level, height, width):
image_group_number = self._calculate_image_group_number(frame_number, field_of_view, z_level)
try:
timestamp, raw_image_data = self._get_raw_image_data(image_group_number,
self._channel_offset[channel_name],
height,
width)
image = Image(raw_image_data)
image.add_params(timestamp, frame_number, field_of_view, channel_name, z_level)
except (TypeError, NoImageError):
return None
else:
return image

+ 1
- 1
nd2reader/interface.py View File

@ -159,7 +159,7 @@ class Nd2(object):
:rtype: nd2reader.model.Image()
"""
return self._driver.get_image_by_attributes(frame_number, field_of_view, channel_name, z_level)
return self._driver.get_image_by_attributes(frame_number, field_of_view, channel_name, z_level, self.height, self.width)
def close(self):
self._fh.close()

Loading…
Cancel
Save