Browse Source

Fix #4

zolfa-add_slices_loading
Ruben Verweij 7 years ago
parent
commit
731a05214a
3 changed files with 28 additions and 5 deletions
  1. +23
    -2
      nd2reader/raw_metadata.py
  2. +4
    -2
      nd2reader/reader.py
  3. +1
    -1
      tests/test_reader.py

+ 23
- 2
nd2reader/raw_metadata.py View File

@ -377,12 +377,14 @@ class RawMetadata(object):
for loop in loops:
# duration of this loop
duration = get_from_dict_if_exists('dDuration', loop) or 0
interval = self._determine_sampling_interval(duration, loop)
# if duration is not saved, infer it
duration = self.get_duration_from_interval_and_loops(duration, interval, loop)
# uiLoopType == 6 is a stimulation loop
is_stimulation = get_from_dict_if_exists('uiLoopType', loop) == 6
interval = self._determine_sampling_interval(duration, loop)
parsed_loop = {
'start': time_offset,
'duration': duration,
@ -397,6 +399,25 @@ class RawMetadata(object):
return parsed_loops
def get_duration_from_interval_and_loops(self, duration, interval, loop):
"""Infers the duration of the loop from the number of measurements and the interval
Args:
duration: loop duration in milliseconds
duration: measurement interval in milliseconds
loop: loop dictionary
Returns:
float: the loop duration in milliseconds
"""
if duration == 0 and interval > 0:
number_of_loops = get_from_dict_if_exists('uiCount', loop)
number_of_loops = number_of_loops if number_of_loops is not None and number_of_loops > 0 else 1
duration = interval * number_of_loops
return duration
@staticmethod
def _determine_sampling_interval(duration, loop):
"""Determines the loop sampling interval in milliseconds


+ 4
- 2
nd2reader/reader.py View File

@ -196,6 +196,8 @@ class ND2Reader(FramesSequenceND):
(timesteps, np.arange(current_time, current_time + loop['duration'], loop['sampling_interval'])))
current_time += loop['duration']
# if experiment did not finish, number of timesteps is wrong. Take correct amount of leading timesteps.
self._timesteps = timesteps[:self.metadata['num_frames']]
if len(timesteps) > 0:
# if experiment did not finish, number of timesteps is wrong. Take correct amount of leading timesteps.
self._timesteps = timesteps[:self.metadata['num_frames']]
return self._timesteps

+ 1
- 1
tests/test_reader.py View File

@ -40,4 +40,4 @@ class TestReader(unittest.TestCase):
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), [])
self.assertEquals(timesteps, None)

Loading…
Cancel
Save