|
@ -4,6 +4,7 @@ import numpy as np |
|
|
from nd2reader.artificial import ArtificialND2 |
|
|
from nd2reader.artificial import ArtificialND2 |
|
|
from nd2reader.exceptions import EmptyFileError |
|
|
from nd2reader.exceptions import EmptyFileError |
|
|
from nd2reader.reader import ND2Reader |
|
|
from nd2reader.reader import ND2Reader |
|
|
|
|
|
from nd2reader.parser import Parser |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestReader(unittest.TestCase): |
|
|
class TestReader(unittest.TestCase): |
|
@ -12,20 +13,31 @@ class TestReader(unittest.TestCase): |
|
|
|
|
|
|
|
|
def test_init_and_init_axes(self): |
|
|
def test_init_and_init_axes(self): |
|
|
with ArtificialND2('test_data/test_nd2_reader.nd2') as artificial: |
|
|
with ArtificialND2('test_data/test_nd2_reader.nd2') as artificial: |
|
|
reader = ND2Reader('test_data/test_nd2_reader.nd2') |
|
|
|
|
|
|
|
|
with ND2Reader('test_data/test_nd2_reader.nd2') as reader: |
|
|
|
|
|
attributes = artificial.data['image_attributes']['SLxImageAttributes'] |
|
|
|
|
|
self.assertEqual(reader.metadata['width'], attributes['uiWidth']) |
|
|
|
|
|
self.assertEqual(reader.metadata['height'], attributes['uiHeight']) |
|
|
|
|
|
|
|
|
attributes = artificial.data['image_attributes']['SLxImageAttributes'] |
|
|
|
|
|
self.assertEqual(reader.metadata['width'], attributes['uiWidth']) |
|
|
|
|
|
self.assertEqual(reader.metadata['height'], attributes['uiHeight']) |
|
|
|
|
|
|
|
|
self.assertEqual(reader.metadata['width'], reader.sizes['x']) |
|
|
|
|
|
self.assertEqual(reader.metadata['height'], reader.sizes['y']) |
|
|
|
|
|
|
|
|
self.assertEqual(reader.metadata['width'], reader.sizes['x']) |
|
|
|
|
|
self.assertEqual(reader.metadata['height'], reader.sizes['y']) |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(reader._dtype, np.float64) |
|
|
|
|
|
self.assertEqual(reader.iter_axes, ['t']) |
|
|
|
|
|
|
|
|
self.assertEqual(reader.pixel_type, np.float64) |
|
|
|
|
|
self.assertEqual(reader.iter_axes, ['t']) |
|
|
|
|
|
|
|
|
def test_init_empty_file(self): |
|
|
def test_init_empty_file(self): |
|
|
with ArtificialND2('test_data/empty.nd2', skip_blocks=['label_map_marker']): |
|
|
with ArtificialND2('test_data/empty.nd2', skip_blocks=['label_map_marker']): |
|
|
with self.assertRaises(EmptyFileError) as exception: |
|
|
with self.assertRaises(EmptyFileError) as exception: |
|
|
ND2Reader('test_data/empty.nd2') |
|
|
|
|
|
|
|
|
with ND2Reader('test_data/empty.nd2'): |
|
|
|
|
|
pass |
|
|
self.assertEqual(str(exception.exception), "No axes were found for this .nd2 file.") |
|
|
self.assertEqual(str(exception.exception), "No axes were found for this .nd2 file.") |
|
|
|
|
|
|
|
|
|
|
|
def test_get_parser(self): |
|
|
|
|
|
with ArtificialND2('test_data/test_nd2_reader.nd2') as _: |
|
|
|
|
|
with ND2Reader('test_data/test_nd2_reader.nd2') as reader: |
|
|
|
|
|
self.assertIsInstance(reader.parser, Parser) |
|
|
|
|
|
|
|
|
|
|
|
def test_get_timesteps(self): |
|
|
|
|
|
with ArtificialND2('test_data/test_nd2_reader.nd2') as _: |
|
|
|
|
|
with ND2Reader('test_data/test_nd2_reader.nd2') as reader: |
|
|
|
|
|
timesteps = reader.timesteps |
|
|
|
|
|
self.assertEquals(list(timesteps), []) |