def test__add_epoch(self): starts = Event(times=[0.5, 10.0, 25.2] * pq.s) starts.annotate(event_type='trial start') starts.array_annotate(trial_id=[1, 2, 3]) stops = Event(times=[5.5, 14.9, 30.1] * pq.s) stops.annotate(event_type='trial stop') stops.array_annotate(trial_id=[1, 2, 3]) seg = Segment() seg.events = [starts, stops] # test cutting with one event only ep_starts = add_epoch(seg, starts, pre=-300 * pq.ms, post=250 * pq.ms) assert_neo_object_is_compliant(ep_starts) assert_same_annotations(ep_starts, starts) assert_arrays_almost_equal(ep_starts.times, starts.times - 300 * pq.ms, 1e-12) assert_arrays_almost_equal( ep_starts.durations, (550 * pq.ms).rescale(ep_starts.durations.units) * np.ones( (len(starts))), 1e-12) # test cutting with two events ep_trials = add_epoch(seg, starts, stops) assert_neo_object_is_compliant(ep_trials) assert_same_annotations(ep_trials, starts) assert_arrays_almost_equal(ep_trials.times, starts.times, 1e-12) assert_arrays_almost_equal(ep_trials.durations, stops - starts, 1e-12)
def test__add_epoch(self): proxy_event = EventProxy(rawio=self.reader, event_channel_index=0, block_index=0, seg_index=0) loaded_event = proxy_event.load() regular_event = Event(times=loaded_event.times - 1 * loaded_event.units) loaded_event.annotate(nix_name='neo.event.0') regular_event.annotate(nix_name='neo.event.1') seg = Segment() seg.events = [regular_event, proxy_event] # test cutting with two events one of which is a proxy epoch = add_epoch(seg, regular_event, proxy_event) assert_neo_object_is_compliant(epoch) exp_annos = { k: v for k, v in regular_event.annotations.items() if k != 'nix_name' } self.assertDictEqual(epoch.annotations, exp_annos) assert_arrays_almost_equal(epoch.times, regular_event.times, 1e-12) assert_arrays_almost_equal( epoch.durations, np.ones(regular_event.shape) * loaded_event.units, 1e-12)
def test__add_epoch(self): proxy_event = EventProxy(rawio=self.reader, event_channel_index=0, block_index=0, seg_index=0) loaded_event = proxy_event.load() regular_event = Event(times=loaded_event.times - 1 * loaded_event.units) seg = Segment() seg.events = [regular_event, proxy_event] # test cutting with two events one of which is a proxy epoch = add_epoch(seg, regular_event, proxy_event) assert_neo_object_is_compliant(epoch) assert_same_annotations(epoch, regular_event) assert_arrays_almost_equal(epoch.times, regular_event.times, 1e-12) assert_arrays_almost_equal(epoch.durations, np.ones(regular_event.shape) * loaded_event.units, 1e-12)
if len(val): transformed_anasig.annotations[key] = val[channel_idx] anasig.segment.analogsignals.append(transformed_anasig) seg.create_relationship() trigger_event = 'target_02_on' trigger_events = utils.get_events(container=seg, name='DecodedEvents', labels=trigger_event, in_successful_trial=True, # trial_protocol=trial_protocol )[0] epoch = utils.add_epoch( seg, event1=trigger_events, event2=None, pre=pre, post=post, attach_result=False, name='analysis_epochs') target_02_on_segs = utils.cut_segment_by_epoch( seg=seg, epoch=epoch, reset_time=True) target_02_on_block = neo.Block(name='Block with target_02_on trigger as segments') target_02_on_block.segments = target_02_on_segs target_02_on_block.create_relationship() for attempt in target_02_on_block.segments: attempt = plotting_utils.define_hand_movement_events(attempt, onset_and_offset=False) attempt = plotting_utils.define_eye_movement_events(attempt, onset_and_offset=False)