Count annotations. Parameters ---------- annotations : mne.Annotations The annotations instance. Returns ------- counts : dict A dictionary containing unique annotation descriptions as keys with their counts as values. Examples --------
(annotations)
| 2466 | |
| 2467 | |
| 2468 | def count_annotations(annotations): |
| 2469 | """Count annotations. |
| 2470 | |
| 2471 | Parameters |
| 2472 | ---------- |
| 2473 | annotations : mne.Annotations |
| 2474 | The annotations instance. |
| 2475 | |
| 2476 | Returns |
| 2477 | ------- |
| 2478 | counts : dict |
| 2479 | A dictionary containing unique annotation descriptions as keys with their |
| 2480 | counts as values. |
| 2481 | |
| 2482 | Examples |
| 2483 | -------- |
| 2484 | >>> annotations = mne.Annotations([0, 1, 2], [1, 2, 1], ["T0", "T1", "T0"]) |
| 2485 | >>> count_annotations(annotations) |
| 2486 | {'T0': 2, 'T1': 1} |
| 2487 | """ |
| 2488 | field = "hed_string" if isinstance(annotations, HEDAnnotations) else "description" |
| 2489 | types, counts = np.unique(getattr(annotations, field), return_counts=True) |
| 2490 | return {str(t): int(count) for t, count in zip(types, counts)} |
no outgoing calls