Browse Source

Bug fixes by testing different .nd2 files

zolfa-add_slices_loading
Ruben Verweij 8 years ago
parent
commit
9d2188aa47
3 changed files with 31 additions and 8 deletions
  1. +24
    -1
      nd2reader/common.py
  2. +7
    -6
      nd2reader/raw_metadata.py
  3. +0
    -1
      tests/test_data/.gitignore

+ 24
- 1
nd2reader/common.py View File

@ -196,7 +196,10 @@ def parse_date(text_info):
except (TypeError, ValueError):
absolute_start = None
return absolute_start
if absolute_start is not None:
return absolute_start
return None
def _parse_metadata_item(data, cursor_position):
@ -309,3 +312,23 @@ def _add_to_metadata(metadata, name, value):
metadata[name].append(value)
return metadata
def get_from_dict_if_exists(key, dictionary, convert_key_to_binary=True):
"""
Get the entry from the dictionary if it exists
Args:
key: key to lookup
dictionary: dictionary to look in
convert_key_to_binary: convert the key from string to binary if true
Returns:
the value of dictionary[key] or None
"""
if convert_key_to_binary:
key = six.b(key)
if not key in dictionary:
return None
return dictionary[key]

+ 7
- 6
nd2reader/raw_metadata.py View File

@ -1,5 +1,5 @@
import re
from nd2reader.common import read_chunk, read_array, read_metadata, parse_date
from nd2reader.common import read_chunk, read_array, read_metadata, parse_date, get_from_dict_if_exists
import xmltodict
import six
import numpy as np
@ -189,6 +189,9 @@ class RawMetadata(object):
raw_roi_data = self.roi_metadata[six.b('RoiMetadata_v1')]
if not six.b('m_vectGlobal_Size') in raw_roi_data:
return
number_of_rois = raw_roi_data[six.b('m_vectGlobal_Size')]
roi_objects = []
@ -333,15 +336,13 @@ class RawMetadata(object):
for loop in loops:
# duration of this loop
duration = loop[six.b('dDuration')]
duration = get_from_dict_if_exists('dDuration', loop) or 0
# uiLoopType == 6 is a stimulation loop
is_stimulation = False
if six.b('uiLoopType') in loop:
is_stimulation = loop[six.b('uiLoopType')] == 6
is_stimulation = get_from_dict_if_exists('uiLoopType', loop) == 6
# sampling interval in ms
interval = loop[six.b('dAvgPeriodDiff')]
interval = get_from_dict_if_exists('dAvgPeriodDiff', loop)
parsed_loop = {
'start': time_offset,


+ 0
- 1
tests/test_data/.gitignore View File

@ -1 +0,0 @@
*.nd2

Loading…
Cancel
Save