MCPcopy Index your code
hub / github.com/mne-tools/mne-python / count_annotations

Function count_annotations

mne/annotations.py:2468–2490  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2466
2467
2468def 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)}

Callers 2

test_count_annotationsFunction · 0.90
countMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_count_annotationsFunction · 0.72