Skip to content

Commit d38be87

Browse files
author
sprenger
committed
[utils] do not copy nix_name annotation to different object types
1 parent 33729b5 commit d38be87

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

neo/test/utils/test_misc.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ def test__get_epochs(self):
281281

282282
def test__add_epoch(self):
283283
starts = Event(times=[0.5, 10.0, 25.2] * pq.s)
284-
starts.annotate(event_type='trial start')
284+
starts.annotate(event_type='trial start', nix_name='neo.event.0')
285285
starts.array_annotate(trial_id=[1, 2, 3])
286286

287287
stops = Event(times=[5.5, 14.9, 30.1] * pq.s)
288-
stops.annotate(event_type='trial stop')
288+
stops.annotate(event_type='trial stop', nix_name='neo.event.1')
289289
stops.array_annotate(trial_id=[1, 2, 3])
290290

291291
seg = Segment()
@@ -295,7 +295,7 @@ def test__add_epoch(self):
295295
ep_starts = add_epoch(seg, starts, pre=-300 * pq.ms, post=250 * pq.ms)
296296

297297
assert_neo_object_is_compliant(ep_starts)
298-
assert_same_annotations(ep_starts, starts)
298+
self.assertDictEqual(ep_starts.annotations, {'event_type': 'trial start'})
299299
assert_arrays_almost_equal(ep_starts.times, starts.times - 300 * pq.ms, 1e-12)
300300
assert_arrays_almost_equal(ep_starts.durations,
301301
(550 * pq.ms).rescale(ep_starts.durations.units)
@@ -305,7 +305,7 @@ def test__add_epoch(self):
305305
ep_trials = add_epoch(seg, starts, stops)
306306

307307
assert_neo_object_is_compliant(ep_trials)
308-
assert_same_annotations(ep_trials, starts)
308+
self.assertDictEqual(ep_trials.annotations, {'event_type': 'trial start'})
309309
assert_arrays_almost_equal(ep_trials.times, starts.times, 1e-12)
310310
assert_arrays_almost_equal(ep_trials.durations, stops - starts, 1e-12)
311311

@@ -337,16 +337,16 @@ def test__match_events(self):
337337
def test__cut_block_by_epochs(self):
338338
epoch = Epoch([0.5, 10.0, 25.2] * pq.s, durations=[5.1, 4.8, 5.0] * pq.s,
339339
t_start=.1 * pq.s)
340-
epoch.annotate(epoch_type='a', pick='me')
340+
epoch.annotate(epoch_type='a', pick='me', nix_name='neo.epoch.0')
341341
epoch.array_annotate(trial_id=[1, 2, 3])
342342

343343
epoch2 = Epoch([0.6, 9.5, 16.8, 34.1] * pq.s, durations=[4.5, 4.8, 5.0, 5.0] * pq.s,
344344
t_start=.1 * pq.s)
345-
epoch2.annotate(epoch_type='b')
345+
epoch2.annotate(epoch_type='b', nix_name='neo.epoch.1')
346346
epoch2.array_annotate(trial_id=[1, 2, 3, 4])
347347

348348
event = Event(times=[0.5, 10.0, 25.2] * pq.s, t_start=.1 * pq.s)
349-
event.annotate(event_type='trial start')
349+
event.annotate(event_type='trial start', nix_name='neo.event.0')
350350
event.array_annotate(trial_id=[1, 2, 3])
351351

352352
anasig = AnalogSignal(np.arange(50.0) * pq.mV, t_start=.1 * pq.s,
@@ -362,8 +362,8 @@ def test__cut_block_by_epochs(self):
362362
array_annotations={'spikenum': np.arange(1, 9)})
363363

364364
# test without resetting the time
365-
seg = Segment()
366-
seg2 = Segment(name='NoCut')
365+
seg = Segment(nix_name='neo.segment.0')
366+
seg2 = Segment(name='NoCut', nix_name='neo.segment.1')
367367
seg.epochs = [epoch, epoch2]
368368
seg.events = [event]
369369
seg.analogsignals = [anasig]
@@ -385,6 +385,10 @@ def test__cut_block_by_epochs(self):
385385
self.assertEqual(len(block.segments[epoch_idx].analogsignals), 1)
386386
self.assertEqual(len(block.segments[epoch_idx].irregularlysampledsignals), 1)
387387

388+
annos = block.segments[epoch_idx].annotations
389+
self.assertIn('nix_name', annos)
390+
self.assertTrue(annos['nix_name'].startswith('neo.segment.'))
391+
388392
if epoch_idx != 0:
389393
self.assertEqual(len(block.segments[epoch_idx].epochs), 1)
390394
else:
@@ -414,8 +418,8 @@ def test__cut_block_by_epochs(self):
414418
t_stop=epoch.times[0] + epoch.durations[0]))
415419

416420
# test with resetting the time
417-
seg = Segment()
418-
seg2 = Segment(name='NoCut')
421+
seg = Segment(nix_name='neo.segment.0')
422+
seg2 = Segment(name='NoCut', nix_name='neo.segment.1')
419423
seg.epochs = [epoch, epoch2]
420424
seg.events = [event]
421425
seg.analogsignals = [anasig]
@@ -436,6 +440,11 @@ def test__cut_block_by_epochs(self):
436440
self.assertEqual(len(block.segments[epoch_idx].spiketrains), 1)
437441
self.assertEqual(len(block.segments[epoch_idx].analogsignals), 1)
438442
self.assertEqual(len(block.segments[epoch_idx].irregularlysampledsignals), 1)
443+
444+
annos = block.segments[epoch_idx].annotations
445+
self.assertIn('nix_name', annos)
446+
self.assertTrue(annos['nix_name'].startswith('neo.segment.'))
447+
439448
if epoch_idx != 0:
440449
self.assertEqual(len(block.segments[epoch_idx].epochs), 1)
441450
else:
@@ -527,14 +536,18 @@ def test__add_epoch(self):
527536

528537
regular_event = Event(times=loaded_event.times - 1 * loaded_event.units)
529538

539+
loaded_event.annotate(nix_name='neo.event.0')
540+
regular_event.annotate(nix_name='neo.event.1')
541+
530542
seg = Segment()
531543
seg.events = [regular_event, proxy_event]
532544

533545
# test cutting with two events one of which is a proxy
534546
epoch = add_epoch(seg, regular_event, proxy_event)
535547

536548
assert_neo_object_is_compliant(epoch)
537-
assert_same_annotations(epoch, regular_event)
549+
exp_annos = {k: v for k, v in regular_event.annotations.items() if k != 'nix_name'}
550+
self.assertDictEqual(epoch.annotations, exp_annos)
538551
assert_arrays_almost_equal(epoch.times, regular_event.times, 1e-12)
539552
assert_arrays_almost_equal(epoch.durations,
540553
np.ones(regular_event.shape) * loaded_event.units, 1e-12)

0 commit comments

Comments
 (0)