Browse Source

#42 fixed dockerfile and makefile, got one passing test

feature/load_slices
jim 10 years ago
parent
commit
07e2297aaf
5 changed files with 34 additions and 14 deletions
  1. +1
    -4
      Dockerfile
  2. +4
    -0
      Makefile
  3. +0
    -10
      nd2reader/__init__.py
  4. +10
    -0
      nd2reader/parser.py
  5. +19
    -0
      tests/__init__.py

+ 1
- 4
Dockerfile View File

@ -1,4 +1,4 @@
FROM ubuntu
FROM ubuntu:15.04
MAINTAINER Jim Rybarski <jim@rybarski.com>
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

+ 4
- 0
Makefile View File

@ -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

+ 0
- 10
nd2reader/__init__.py View File

@ -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


+ 10
- 0
nd2reader/parser.py View File

@ -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:


+ 19
- 0
tests/__init__.py View File

@ -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)

Loading…
Cancel
Save