Browse Source

added image events to parser

Gregor Lichtner 6 years ago
parent
commit
4efd9a2ea4
3 changed files with 67 additions and 0 deletions
  1. +10
    -0
      nd2reader/label_map.py
  2. +45
    -0
      nd2reader/raw_metadata.py
  3. +12
    -0
      nd2reader/reader.py

+ 10
- 0
nd2reader/label_map.py View File

@ -43,6 +43,16 @@ class LabelMap(object):
"""
return self._get_location(six.b("ImageMetadataLV!"))
@property
def image_events(self):
"""Get the location of the image events
Returns:
int: The location of the image events
"""
return self._get_location(six.b("ImageEventsLV!"))
@property
def image_metadata_sequence(self):
"""Get the location of the image metadata sequence. There is always only one of these, even though it has a pipe


+ 45
- 0
nd2reader/raw_metadata.py View File

@ -54,6 +54,7 @@ class RawMetadata(object):
self._parse_roi_metadata()
self._parse_experiment_metadata()
self._parse_events()
return self._metadata_parsed
@ -373,6 +374,38 @@ class RawMetadata(object):
return duration
def _parse_events(self):
"""Extract events
"""
event_names = {
10: 'Experiment Resumed',
14: 'Experiment Paused for Refocusing',
44: 'No Acquisition Phase Start',
45: 'No Acquisition Phase End'
}
self._metadata_parsed['events'] = []
events = read_metadata(read_chunk(self._fh, self._label_map.image_events), 1)
if events is None or six.b('RLxExperimentRecord') not in events:
return
events = events[six.b('RLxExperimentRecord')][six.b('pEvents')][six.b('')]
for event in events:
event_info = {
'index': event[six.b('I')],
'time': event[six.b('T')],
'type': event[six.b('M')],
}
if event_info['type'] in event_names.keys():
event_info['name'] = event_names[event_info['type']]
self._metadata_parsed['events'].append(event_info)
@property
def image_text_info(self):
@ -554,3 +587,15 @@ class RawMetadata(object):
"""
if self._label_map.image_metadata:
return read_metadata(read_chunk(self._fh, self._label_map.image_metadata), 1)
@property
def image_events(self):
"""Image events
Returns:
dict: Image events
"""
if self._label_map.image_metadata:
for event in self._metadata_parsed["events"]:
yield event

+ 12
- 0
nd2reader/reader.py View File

@ -102,6 +102,16 @@ class ND2Reader(FramesSequenceND):
return self.get_timesteps()
return self._timesteps
@property
def events(self):
"""Get the events of the experiment
Returns:
iterator of events as dict
"""
return self._get_metadata_property("events")
@property
def frame_rate(self):
"""The (average) frame rate
@ -186,3 +196,5 @@ class ND2Reader(FramesSequenceND):
self._timesteps = np.array(list(self._parser._raw_metadata.acquisition_times), dtype=np.float) * 1000.0
return self._timesteps

Loading…
Cancel
Save