Browse Source

Add a third method to determine the loop sampling interval

zolfa-add_slices_loading
Ruben Verweij 8 years ago
parent
commit
39eada0948
1 changed files with 24 additions and 5 deletions
  1. +24
    -5
      nd2reader/raw_metadata.py

+ 24
- 5
nd2reader/raw_metadata.py View File

@ -349,11 +349,7 @@ class RawMetadata(object):
# uiLoopType == 6 is a stimulation loop
is_stimulation = get_from_dict_if_exists('uiLoopType', loop) == 6
# sampling interval in ms
interval = get_from_dict_if_exists('dPeriod', loop)
if interval is None or interval <= 0:
interval = get_from_dict_if_exists('dAvgPeriodDiff', loop)
interval = self._determine_sampling_interval(duration, loop)
parsed_loop = {
'start': time_offset,
@ -369,6 +365,29 @@ class RawMetadata(object):
return parsed_loops
@staticmethod
def _determine_sampling_interval(duration, loop):
"""Determines the loop sampling interval in milliseconds
Args:
duration: loop duration in milliseconds
loop: loop dictionary
Returns:
float: the sampling interval in milliseconds
"""
interval = get_from_dict_if_exists('dPeriod', loop)
if interval is None or interval <= 0:
# Use a fallback if it is still not found
interval = get_from_dict_if_exists('dAvgPeriodDiff', loop)
if interval is None or interval <= 0:
# In some cases, both keys are not saved. Then try to calculate it.
number_of_loops = get_from_dict_if_exists('uiCount', loop)
number_of_loops = number_of_loops if number_of_loops > 0 else 1
interval = duration / number_of_loops
return interval
@property
def image_text_info(self):
"""Textual image information


Loading…
Cancel
Save