Browse Source

Use _register_get_frame functions

master
Ruben Verweij 6 years ago
parent
commit
1d43617c55
2 changed files with 29 additions and 17 deletions
  1. +5
    -0
      nd2reader/parser.py
  2. +24
    -17
      nd2reader/reader.py

+ 5
- 0
nd2reader/parser.py View File

@ -92,6 +92,11 @@ class Parser(object):
Frame: the requested image
"""
frame_number = 0 if frame_number is None else frame_number
field_of_view = 0 if field_of_view is None else field_of_view
channel = 0 if channel is None else channel
z_level = 0 if z_level is None else z_level
image_group_number = self._calculate_image_group_number(frame_number, field_of_view, z_level)
try:
timestamp, raw_image_data = self._get_raw_image_data(image_group_number, channel,


+ 24
- 17
nd2reader/reader.py View File

@ -52,24 +52,22 @@ class ND2Reader(FramesSequenceND):
except KeyError:
return 0
def get_frame_2D(self, c=0, t=0, z=0, x=0, y=0, v=0):
"""Gets a given frame using the parser
def get_frame_vczyx(self, v=None, c=None, t=None, z=None, x=None, y=None):
x = self.metadata["width"] if x <= 0 else x
y = self.metadata["height"] if y <= 0 else y
Args:
x: The x-index (pims expects this)
y: The y-index (pims expects this)
c: The color channel number
t: The frame number
z: The z stack number
v: The field of view index
result = []
for v in self._get_possible_coords('v', v):
for c in self._get_possible_coords('c', c):
for z in self._get_possible_coords('z', z):
result.append(self._parser.get_image_by_attributes(t, v, c, z, y, x))
Returns:
numpy.ndarray: The requested frame
return np.squeeze(np.array(result, dtype=self._dtype))
"""
x = self.metadata["width"] if x <= 0 else x
y = self.metadata["height"] if y <= 0 else y
return self._parser.get_image_by_attributes(t, v, c, z, y, x)
def _get_possible_coords(self, dim, default):
if dim in self.sizes:
return [default] if default is not None else range(self.sizes[dim])
return [None]
@property
def parser(self):
@ -158,6 +156,17 @@ class ND2Reader(FramesSequenceND):
# provide the default
self.iter_axes = self._guess_default_iter_axis()
self._register_get_frame(self.get_frame_vczyx, 'vczyx')
self._register_get_frame(self.get_frame_vczyx, 'vzyx')
self._register_get_frame(self.get_frame_vczyx, 'vcyx')
self._register_get_frame(self.get_frame_vczyx, 'vyx')
self._register_get_frame(self.get_frame_vczyx, 'czyx')
self._register_get_frame(self.get_frame_vczyx, 'cyx')
self._register_get_frame(self.get_frame_vczyx, 'zyx')
self._register_get_frame(self.get_frame_vczyx, 'yx')
def _init_axis_if_exists(self, axis, size, min_size=1):
if size >= min_size:
self._init_axis(axis, size)
@ -196,5 +205,3 @@ class ND2Reader(FramesSequenceND):
self._timesteps = np.array(list(self._parser._raw_metadata.acquisition_times), dtype=np.float) * 1000.0
return self._timesteps

Loading…
Cancel
Save