diff --git a/Dockerfile b/Dockerfile index 0209f2a..8f656a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu +FROM ubuntu:15.04 MAINTAINER Jim Rybarski RUN mkdir -p /var/nds2 @@ -15,6 +15,3 @@ COPY . /opt/nd2reader WORKDIR /opt/nd2reader RUN python setup.py install RUN python3 setup.py install -WORKDIR /var/nd2s - -CMD /usr/bin/python3.4 \ No newline at end of file diff --git a/Makefile b/Makefile index 89b185e..87b2d38 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,7 @@ py2shell: py3shell: docker run --rm -v ~/Documents/nd2s:/var/nd2s -it jimrybarski/nd2reader python3.4 + +test: build + docker run --rm -it jimrybarski/nd2reader python3.4 /opt/nd2reader/tests.py + diff --git a/nd2reader/__init__.py b/nd2reader/__init__.py index aa0d14f..f3f5d7b 100644 --- a/nd2reader/__init__.py +++ b/nd2reader/__init__.py @@ -123,16 +123,6 @@ class Nd2(Nd2Parser): """ return self.metadata[six.b('ImageAttributes')][six.b('SLxImageAttributes')][six.b('uiWidth')] - def _calculate_field_of_view(self, frame_number): - images_per_cycle = len(self.z_levels) * len(self.channels) - return int((frame_number - (frame_number % images_per_cycle)) / images_per_cycle) % len(self.fields_of_view) - - def _calculate_channel(self, frame_number): - return self._channels[frame_number % len(self.channels)] - - def _calculate_z_level(self, frame_number): - return self.z_levels[int(((frame_number - (frame_number % len(self.channels))) / len(self.channels)) % len(self.z_levels))] - def get_image(self, time_index, field_of_view, channel_name, z_level): """ Returns an Image if data exists for the given parameters, otherwise returns None. In general, you should avoid diff --git a/nd2reader/parser.py b/nd2reader/parser.py index 34acc24..f5bbda5 100644 --- a/nd2reader/parser.py +++ b/nd2reader/parser.py @@ -128,6 +128,16 @@ class Nd2Parser(object): self._z_levels = self._parse_dimension_text(r""".*?Z\((\d+)\).*?""") return self._z_levels + def _calculate_field_of_view(self, frame_number): + images_per_cycle = len(self.z_levels) * len(self.channels) + return int((frame_number - (frame_number % images_per_cycle)) / images_per_cycle) % len(self.fields_of_view) + + def _calculate_channel(self, frame_number): + return self._channels[frame_number % len(self.channels)] + + def _calculate_z_level(self, frame_number): + return self.z_levels[int(((frame_number - (frame_number % len(self.channels))) / len(self.channels)) % len(self.z_levels))] + @property def _file_handle(self): if self._fh is None: diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..531c513 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,19 @@ +from nd2reader.parser import Nd2Parser +import unittest + + +class MockNd2Parser(object): + def __init__(self, channels, fields_of_view, z_levels): + self.channels = channels + self.fields_of_view = fields_of_view + self.z_levels = z_levels + + +class TestNd2Parser(unittest.TestCase): + def test_calculate_field_of_view_simple(self): + """ With a single field of view, the field of view should always be the same number (0). """ + nd2 = MockNd2Parser([''], [0], [0]) + for frame_number in range(1000): + result = Nd2Parser._calculate_field_of_view(nd2, frame_number) + self.assertEqual(result, 0) +