Browse Source

Handle gap frames with np.nan-filled array and issue warning about it.

zolfa-add_slices_loading
unknown 5 years ago
parent
commit
43dbc61412
1 changed files with 9 additions and 7 deletions
  1. +9
    -7
      nd2reader/parser.py

+ 9
- 7
nd2reader/parser.py View File

@ -3,6 +3,7 @@ import struct
import array import array
import six import six
import warnings
from pims.base_frames import Frame from pims.base_frames import Frame
import numpy as np import numpy as np
@ -72,7 +73,7 @@ class Parser(object):
try: try:
timestamp, image = self._get_raw_image_data(image_group_number, channel_offset, self.metadata["height"], timestamp, image = self._get_raw_image_data(image_group_number, channel_offset, self.metadata["height"],
self.metadata["width"]) self.metadata["width"])
except (TypeError, NoImageError):
except (TypeError):
return Frame([], frame_no=frame_number, metadata=self._get_frame_metadata()) return Frame([], frame_no=frame_number, metadata=self._get_frame_metadata())
else: else:
return image return image
@ -101,7 +102,7 @@ class Parser(object):
try: try:
timestamp, raw_image_data = self._get_raw_image_data(image_group_number, channel, timestamp, raw_image_data = self._get_raw_image_data(image_group_number, channel,
height, width) height, width)
except (TypeError, NoImageError):
except (TypeError):
return Frame([], frame_no=frame_number, metadata=self._get_frame_metadata()) return Frame([], frame_no=frame_number, metadata=self._get_frame_metadata())
else: else:
return raw_image_data return raw_image_data
@ -283,11 +284,12 @@ class Parser(object):
if np.any(image_data): if np.any(image_data):
return timestamp, Frame(image_data, metadata=self._get_frame_metadata()) return timestamp, Frame(image_data, metadata=self._get_frame_metadata())
# If a blank "gap" image is encountered, generate an empty frame (black image) of corresponding height and width to avoid
# errors with ND2-files with missing frames.
else:
empty_frame = np.zeros([height, width])
return timestamp, Frame(empty_frame, metadata=self._get_frame_metadata())
# If a blank "gap" image is encountered, generate an array of corresponding height and width to avoid
# errors with ND2-files with missing frames. Array is filled with nan to reflect that data is missing.
else:
empty_frame = np.full((height, width), np.nan)
warnings.warn('ND2 file contains gap frames which are represented by np.nan-filled arrays')
return timestamp, Frame(empty_frame, metadata=self._get_frame_metadata())
def _get_frame_metadata(self): def _get_frame_metadata(self):
"""Get the metadata for one frame """Get the metadata for one frame


Loading…
Cancel
Save