def extract(self, extractors, merge_events=True): timeline = Timeline() for ext in extractors: events = ext.apply(self) for ev in events: timeline.add_event(ev, merge=merge_events) return timeline
def extract(self, extractors): timeline = Timeline() audio_exts, text_exts = [], [] for ext in extractors: if ext.target.__name__ == 'AudioStim': audio_exts.append(ext) elif ext.target.__name__ == 'ComplexTextStim': text_exts.append(ext) audio_tl = super(TranscribedAudioStim, self).extract(audio_exts) timeline.merge(audio_tl) text_tl = self.transcription.extract(text_exts) timeline.merge(text_tl) return timeline
def extract(self, extractors, merge_events=True, **kwargs): period = 1. / self.fps timeline = Timeline(period=period) for ext in extractors: # For VideoExtractors, pass the entire stim if ext.target.__name__ == self.__class__.__name__: events = ext.apply(self, **kwargs) for ev in events: timeline.add_event(ev, merge=merge_events) # Otherwise, for images, loop over frames else: c = 0 for frame in self: if frame.data is not None: event = Event(onset=c * period) event.add_value(ext.apply(frame)) timeline.add_event(event, merge=merge_events) c += 1 return timeline
def test_dummy_code_timeline(self): data = [{'A': 12.0, 'B': 'abc'}, { 'A': 7, 'B': 'def'}, { 'C': 40 }] events = [Event(values=[Value(None, None, x)], duration=1) for x in data] tl = Timeline(events=events, period=1) self.assertEqual(tl.to_df().shape, (5, 4)) tl_dummy = tl.dummy_code() self.assertEqual(tl_dummy.to_df().shape, (7, 4)) tl = Timeline(events=events, period=1) tl_dummy = tl.dummy_code(string_only=False) self.assertEqual(tl_dummy.to_df().shape, (9, 4))
def extract(self, extractors): timeline = Timeline() audio_exts, text_exts = [], [] for ext in extractors: if ext.target.__name__ in ['AudioStim', 'TranscribedAudioStim']: audio_exts.append(ext) elif ext.target.__name__ == 'ComplexTextStim': text_exts.append(ext) audio_tl = super(TranscribedAudioStim, self).extract(audio_exts) timeline.merge(audio_tl) text_tl = self.transcription.extract(text_exts) timeline.merge(text_tl) return timeline
def extract(self, extractors, merge_events=True): timeline = Timeline() # Extractors can either take ComplexTextStim input, in which case we # pass the current instance, or TextStim input, in which case we loop # over all elements. for ext in extractors: if ext.target.__name__ == self.__class__.__name__: events = ext.apply(self) for ev in events: timeline.add_event(ev, merge=merge_events) else: for elem in self.elements: # If no onset is available, index with order onset = elem.onset or elem.order event = Event(onset=onset, values=[ext.apply(elem)]) timeline.add_event(event, merge=merge_events) return timeline