From b7bc95424854402f9bbe31968046e2138bf0b40e Mon Sep 17 00:00:00 2001 From: Jim Rybarski Date: Tue, 27 Jan 2015 22:07:32 -0600 Subject: [PATCH] Fixed bug where ND2s having only one channel couldn't be opened --- nd2reader/service/__init__.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/nd2reader/service/__init__.py b/nd2reader/service/__init__.py index e03b068..c0785b9 100644 --- a/nd2reader/service/__init__.py +++ b/nd2reader/service/__init__.py @@ -156,12 +156,22 @@ class Nd2Reader(object): """ pattern = r""".*?T'\((\d+)\).*?""" - return int(re.match(pattern, self._dimensions).group(1)) + try: + count = int(re.match(pattern, self._dimensions).group(1)) + except AttributeError: + return 1 + else: + return count @property def z_level_count(self): pattern = r""".*?Z\((\d+)\).*?""" - return int(re.match(pattern, self._dimensions).group(1)) + try: + count = int(re.match(pattern, self._dimensions).group(1)) + except AttributeError: + return 1 + else: + return count @property def field_of_view_count(self): @@ -173,12 +183,22 @@ class Nd2Reader(object): """ pattern = r""".*?XY\((\d+)\).*?""" - return int(re.match(pattern, self._dimensions).group(1)) + try: + count = int(re.match(pattern, self._dimensions).group(1)) + except AttributeError: + return 1 + else: + return count @property def channel_count(self): pattern = r""".*?λ\((\d+)\).*?""" - return int(re.match(pattern, self._dimensions).group(1)) + try: + count = int(re.match(pattern, self._dimensions).group(1)) + except AttributeError: + return 1 + else: + return count def get_raw_image_data(self, image_set_number, channel_offset): chunk = self._label_map["ImageDataSeq|%d!" % image_set_number]