From 90ae0907de2b2497330f1f30fd765c007e981a58 Mon Sep 17 00:00:00 2001 From: Jim Rybarski Date: Tue, 27 Oct 2015 09:09:49 -0500 Subject: [PATCH] resolves #106: implemented missing method and added tests --- functional_tests/FYLM141111001.py | 12 ++++++++++++ nd2reader/driver/v3.py | 14 ++++++++++++++ nd2reader/interface.py | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/functional_tests/FYLM141111001.py b/functional_tests/FYLM141111001.py index 05764c6..178f875 100644 --- a/functional_tests/FYLM141111001.py +++ b/functional_tests/FYLM141111001.py @@ -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) diff --git a/nd2reader/driver/v3.py b/nd2reader/driver/v3.py index 89270c6..fc17694 100644 --- a/nd2reader/driver/v3.py +++ b/nd2reader/driver/v3.py @@ -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 diff --git a/nd2reader/interface.py b/nd2reader/interface.py index 997bfc1..ebc58c2 100644 --- a/nd2reader/interface.py +++ b/nd2reader/interface.py @@ -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()