Browse Source

Add unit tests for opening files and axis sizes

zolfa-add_slices_loading
Ruben Verweij 8 years ago
parent
commit
8f513fde74
4 changed files with 45 additions and 4 deletions
  1. +3
    -4
      nd2reader/reader.py
  2. BIN
      tests/test_data/data001.nd2
  3. BIN
      tests/test_data/data002.nd2
  4. +42
    -0
      tests/test_reader.py

+ 3
- 4
nd2reader/reader.py View File

@ -6,7 +6,6 @@ class ND2Reader(FramesSequenceND):
""" """
PIMS wrapper for the ND2 parser PIMS wrapper for the ND2 parser
""" """
def __init__(self, filename): def __init__(self, filename):
self.filename = filename self.filename = filename
@ -45,7 +44,8 @@ class ND2Reader(FramesSequenceND):
:param i: :param i:
:return: :return:
""" """
return self._parser.get_image(i)
c_name = self.metadata["channels"][0]
return self._parser.get_image_by_attributes(i, 0, c_name, 0, self.metadata["height"], self.metadata["width"])
def get_frame_2D(self, c, t, z): def get_frame_2D(self, c, t, z):
""" """
@ -56,8 +56,7 @@ class ND2Reader(FramesSequenceND):
:return: :return:
""" """
c_name = self.metadata["channels"][c] c_name = self.metadata["channels"][c]
return self._parser.get_image_by_attributes(t, 0, c_name, z, self.metadata["width"], self.metadata["height"])
return self._parser.get_image_by_attributes(t, 0, c_name, z, self.metadata["height"], self.metadata["width"])
@property @property
def pixel_type(self): def pixel_type(self):


BIN
tests/test_data/data001.nd2 View File


BIN
tests/test_data/data002.nd2 View File


+ 42
- 0
tests/test_reader.py View File

@ -0,0 +1,42 @@
import unittest
from nd2reader.reader import ND2Reader
class TestReader(unittest.TestCase):
def setUp(self):
self.files = [
'./test_data/data001.nd2',
'./test_data/data002.nd2'
]
def test_sizes_data_001(self):
with ND2Reader(self.files[0]) as reader:
self.assertEqual(reader.sizes['x'], 128)
self.assertEqual(reader.sizes['y'], 128)
self.assertEqual(reader.sizes['t'], 982)
self.assertEqual(reader.sizes['c'], 1)
self.assertEqual(reader.sizes['z'], 1)
def test_frame_size_data_001(self):
with ND2Reader(self.files[0]) as reader:
frame = reader[13]
self.assertEqual(frame.shape[0], 128)
self.assertEqual(frame.shape[1], 128)
def test_sizes_data_002(self):
with ND2Reader(self.files[1]) as reader:
self.assertEqual(reader.sizes['x'], 512)
self.assertEqual(reader.sizes['y'], 256)
self.assertEqual(reader.sizes['t'], 78)
self.assertEqual(reader.sizes['c'], 1)
self.assertEqual(reader.sizes['z'], 1)
def test_frame_size_data_002(self):
with ND2Reader(self.files[1]) as reader:
frame = reader[13]
self.assertEqual(frame.shape[1], 512)
self.assertEqual(frame.shape[0], 256)

Loading…
Cancel
Save