From e7e2682949f40e77dc560ed0c3a44d1aee3ae8ab Mon Sep 17 00:00:00 2001 From: jim Date: Fri, 12 Dec 2014 16:16:58 -0600 Subject: [PATCH] added some properties to Image --- nd2reader/model/__init__.py | 11 ++++++++++- nd2reader/service/__init__.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/nd2reader/model/__init__.py b/nd2reader/model/__init__.py index 7c438b1..65b2185 100644 --- a/nd2reader/model/__init__.py +++ b/nd2reader/model/__init__.py @@ -71,10 +71,19 @@ class Image(object): """ return self._timestamp / 1000.0 + @property + def channel(self): + return self._channel + + @property + def z_level(self): + return self._z_level + @property def data(self): if self._data is None: - self._data = np.reshape(self._raw_data, (self._height, self._width)).astype(np.float64) + # The data is just a flat, 1-dimensional array. We convert it to a 2D array and cast the data points as 16-bit integers + self._data = np.reshape(self._raw_data, (self._height, self._width)).astype(np.int64).astype(np.uint16) return self._data @property diff --git a/nd2reader/service/__init__.py b/nd2reader/service/__init__.py index 74e5f53..5315c78 100644 --- a/nd2reader/service/__init__.py +++ b/nd2reader/service/__init__.py @@ -19,10 +19,18 @@ class BaseNd2(object): @property def height(self): + """ + :return: height of each image, in pixels + + """ return self._metadata['ImageAttributes']['SLxImageAttributes']['uiHeight'] @property def width(self): + """ + :return: width of each image, in pixels + + """ return self._metadata['ImageAttributes']['SLxImageAttributes']['uiWidth'] @property @@ -54,6 +62,13 @@ class BaseNd2(object): @property def timepoint_count(self): + """ + The number of images for a given field of view, channel, and z_level combination. + Effectively the number of frames. + + :rtype: int + + """ return self._image_count / self.field_of_view_count / self.z_level_count @property