Browse Source

Small fixes

zolfa-add_slices_loading
Ruben Verweij 8 years ago
parent
commit
a716471131
2 changed files with 17 additions and 16 deletions
  1. +6
    -7
      nd2reader/parser.py
  2. +11
    -9
      nd2reader/reader.py

+ 6
- 7
nd2reader/parser.py View File

@ -67,10 +67,9 @@ class Parser(object):
try:
timestamp, image = self._get_raw_image_data(image_group_number, channel_offset, self.metadata["height"],
self.metadata["width"])
except NoImageError:
return None
except (TypeError, NoImageError):
return Frame([], frame_no=frame_number, metadata=self._get_frame_metadata())
else:
image.add_params(index, timestamp, frame_number, field_of_view, channel, z_level)
return image
def get_image_by_attributes(self, frame_number, field_of_view, channel_name, z_level, height, width):
@ -90,11 +89,10 @@ class Parser(object):
try:
timestamp, raw_image_data = self._get_raw_image_data(image_group_number, self._channel_offset[channel_name],
height, width)
image = Frame(raw_image_data, frame_no=frame_number, metadata=self._get_frame_metadata())
except (TypeError, NoImageError):
return None
return Frame([], frame_no=frame_number, metadata=self._get_frame_metadata())
else:
return image
return raw_image_data
def get_dtype_from_metadata(self):
"""
@ -255,7 +253,8 @@ class Parser(object):
# other cycle to reduce phototoxicity, but NIS Elements still allocated memory as if we were going to take
# them every cycle.
if np.any(image_data):
return timestamp, Frame(image_data)
return timestamp, Frame(image_data, metadata=self._get_frame_metadata())
raise NoImageError
def _get_frame_metadata(self):


+ 11
- 9
nd2reader/reader.py View File

@ -1,5 +1,4 @@
from pims import FramesSequenceND, Frame
from nd2reader.exceptions import NoImageError
from pims import FramesSequenceND
from nd2reader.parser import Parser
@ -40,6 +39,14 @@ class ND2Reader(FramesSequenceND):
if self._fh is not None:
self._fh.close()
def get_frame(self, i):
"""
Return one frame
:param i:
:return:
"""
return self._parser.get_image(i)
def get_frame_2D(self, c, t, z):
"""
Gets a given frame using the parser
@ -49,13 +56,8 @@ class ND2Reader(FramesSequenceND):
:return:
"""
c_name = self.metadata["channels"][c]
try:
image = self._parser.get_image_by_attributes(t, 0, c_name, z, self.metadata["width"],
self.metadata["height"])
except (TypeError, NoImageError):
return Frame([])
else:
return image
return self._parser.get_image_by_attributes(t, 0, c_name, z, self.metadata["width"], self.metadata["height"])
@property
def pixel_type(self):


Loading…
Cancel
Save