|
11 | 11 |
|
12 | 12 | import neo |
13 | 13 |
|
14 | | -ignore_annotations = ['nix_name'] |
| 14 | +reserved_annotations = ['nix_name'] |
15 | 15 |
|
16 | 16 | def get_events(container, **properties): |
17 | 17 | """ |
@@ -348,12 +348,8 @@ def add_epoch( |
348 | 348 |
|
349 | 349 | ep = neo.Epoch(times=times, durations=durations, **kwargs) |
350 | 350 |
|
351 | | - annos = {k: v for k, v in event1.annotations.items() |
352 | | - if k not in ignore_annotations} |
353 | | - array_annos = {k: v for k, v in event1.array_annotations.items() |
354 | | - if k not in ignore_annotations} |
355 | | - ep.annotate(**copy.copy(annos)) |
356 | | - ep.array_annotate(**copy.copy(array_annos)) |
| 351 | + ep.annotate(**clean_annotations(event1.annotations)) |
| 352 | + ep.array_annotate(**clean_annotations(event1.array_annotations)) |
357 | 353 |
|
358 | 354 | if attach_result: |
359 | 355 | segment.epochs.append(ep) |
@@ -550,21 +546,34 @@ def cut_segment_by_epoch(seg, epoch, reset_time=False): |
550 | 546 | epoch.times[ep_id] + epoch.durations[ep_id], |
551 | 547 | reset_time=reset_time) |
552 | 548 |
|
553 | | - annos = {k: v for k, v in epoch.annotations.items() |
554 | | - if k not in ignore_annotations} |
555 | | - subseg.annotate(**copy.copy(annos)) |
| 549 | + subseg.annotations = clean_annotations(subseg.annotations) |
| 550 | + subseg.annotate(**clean_annotations(epoch.annotations)) |
556 | 551 |
|
557 | 552 | # Add array-annotations of Epoch |
558 | | - for key, val in epoch.array_annotations.items(): |
559 | | - if key in ignore_annotations: |
560 | | - continue |
| 553 | + for key, val in clean_annotations(epoch.array_annotations).items(): |
561 | 554 | if len(val): |
562 | 555 | subseg.annotations[key] = copy.copy(val[ep_id]) |
563 | 556 |
|
564 | 557 | segments.append(subseg) |
565 | 558 |
|
566 | 559 | return segments |
567 | 560 |
|
| 561 | +def clean_annotations(dictionary): |
| 562 | + """ |
| 563 | + Remove reserved keys from an annotation dictionary. |
| 564 | +
|
| 565 | + Parameters |
| 566 | + ---------- |
| 567 | + dictionary: dict |
| 568 | + annotation dictionary to be cleaned |
| 569 | +
|
| 570 | + Returns: |
| 571 | + -------- |
| 572 | + dict |
| 573 | + A cleaned version of the annotations |
| 574 | + """ |
| 575 | + return {k: v for k, v in dictionary.items() if k not in reserved_annotations} |
| 576 | + |
568 | 577 |
|
569 | 578 | def is_block_rawio_compatible(block, return_problems=False): |
570 | 579 | """ |
|
0 commit comments