Browse Source

Do not add 'z' to sizes of the reader if there is only one plane, as seems to be the PIMS convention

feature/load_slices
Ruben Verweij 8 years ago
parent
commit
45674ff241
2 changed files with 10 additions and 3 deletions
  1. +9
    -2
      nd2reader/reader.py
  2. +1
    -1
      tests/test_reader.py

+ 9
- 2
nd2reader/reader.py View File

@ -68,7 +68,11 @@ class ND2Reader(FramesSequenceND):
""" """
frames = None frames = None
for c in range(len(self.metadata["channels"])): for c in range(len(self.metadata["channels"])):
frame = self.get_frame_2D(c, i, self.default_coords['z'])
try:
z = self.default_coords['z']
except KeyError:
z = 0
frame = self.get_frame_2D(c, i, z)
if frames is None: if frames is None:
frames = Frame([frame]) frames = Frame([frame])
else: else:
@ -129,7 +133,10 @@ class ND2Reader(FramesSequenceND):
self._init_axis('y', self._get_metadata_property("height", default=0)) self._init_axis('y', self._get_metadata_property("height", default=0))
self._init_axis('c', len(self._get_metadata_property("channels", default=[]))) self._init_axis('c', len(self._get_metadata_property("channels", default=[])))
self._init_axis('t', len(self._get_metadata_property("frames", default=[]))) self._init_axis('t', len(self._get_metadata_property("frames", default=[])))
self._init_axis('z', len(self._get_metadata_property("z_levels", default=[])))
z_levels = len(self._get_metadata_property("z_levels", default=[]))
if z_levels > 1:
self._init_axis('z', z_levels)
# provide the default # provide the default
self.iter_axes = 't' self.iter_axes = 't'


+ 1
- 1
tests/test_reader.py View File

@ -25,7 +25,7 @@ class TestReader(unittest.TestCase):
self.assertEqual(reader.pixel_type, np.float64) self.assertEqual(reader.pixel_type, np.float64)
self.assertEqual(reader.sizes['x'], 0) self.assertEqual(reader.sizes['x'], 0)
self.assertEqual(reader.sizes['y'], 0) self.assertEqual(reader.sizes['y'], 0)
self.assertEqual(reader.sizes['z'], 1)
self.assertFalse('z' in reader.sizes)
self.assertEqual(reader.sizes['c'], 0) self.assertEqual(reader.sizes['c'], 0)
self.assertEqual(reader.sizes['t'], 0) self.assertEqual(reader.sizes['t'], 0)


Loading…
Cancel
Save