From 0a16ce90034ec71b4539e5cac6af7c55fa55dca6 Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Wed, 18 Mar 2020 21:27:13 +0100 Subject: [PATCH] Fix error in loop handling --- docs | 2 +- nd2reader/common_raw_metadata.py | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/docs b/docs index 47a1165..f700c23 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 47a1165d5558515d6df67fb20b3032172de56279 +Subproject commit f700c239f8f9d7d1f99a3c10d9f67e2b3b8ef307 diff --git a/nd2reader/common_raw_metadata.py b/nd2reader/common_raw_metadata.py index c4205f6..422f521 100644 --- a/nd2reader/common_raw_metadata.py +++ b/nd2reader/common_raw_metadata.py @@ -40,20 +40,25 @@ def parse_roi_type(type_no): def get_loops_from_data(loop_data): - loops = [loop_data] - if six.b('uiPeriodCount') in loop_data and loop_data[six.b('uiPeriodCount')] > 0: - # special ND experiment - if six.b('pPeriod') not in loop_data: - return [] - - # take the first dictionary element, it contains all loop data - loops = loop_data[six.b('pPeriod')][list(loop_data[six.b('pPeriod')].keys())[0]] + # special ND experiment + if six.b('pPeriod') not in loop_data: + return [] - # exclude invalid periods - if six.b('pPeriodValid') in loop_data: - loops = [loops[i] for i in range(len(loops)) if loop_data[six.b('pPeriodValid')][i] == 1] - - return loops + if six.b('uiPeriodCount') in loop_data and loop_data[six.b('uiPeriodCount')] > 0: + loops = [] + for i, period in enumerate(loop_data[six.b('pPeriod')]): + # exclude invalid periods + if six.b('pPeriodValid') in loop_data: + try: + if loop_data[six.b('pPeriodValid')][i] == 1: + loops.append(loop_data[six.b('pPeriod')][period]) + except IndexError: + continue + else: + # we can't be sure, append all + loops.append(loop_data[six.b('pPeriod')][period]) + + return [loop_data] def guess_sampling_from_loops(duration, loop):