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

Function _select_annotations_based_on_description

mne/annotations.py:2163–2195  ·  view source on GitHub ↗

Get a collection of descriptions and returns index of selected.

(descriptions, event_id, regexp)

Source from the content-addressed store, hash-verified

2161
2162
2163def _select_annotations_based_on_description(descriptions, event_id, regexp):
2164 """Get a collection of descriptions and returns index of selected."""
2165 regexp_comp = re.compile(".*" if regexp is None else regexp)
2166
2167 event_id_ = dict()
2168 dropped = []
2169 # Iterate over the sorted descriptions so that the Counter mapping
2170 # is slightly less arbitrary
2171 for desc in sorted(descriptions):
2172 if desc in event_id_:
2173 continue
2174
2175 if regexp_comp.match(desc) is None:
2176 continue
2177
2178 if isinstance(event_id, dict):
2179 if desc in event_id:
2180 event_id_[desc] = event_id[desc]
2181 else:
2182 continue
2183 else:
2184 trigger = event_id(desc)
2185 if trigger is not None:
2186 event_id_[desc] = trigger
2187 else:
2188 dropped.append(desc)
2189
2190 event_sel = [ii for ii, kk in enumerate(descriptions) if kk in event_id_]
2191
2192 if len(event_sel) == 0 and regexp is not None:
2193 raise ValueError("Could not find any of the events you specified.")
2194
2195 return event_sel, event_id_
2196
2197
2198def _select_events_based_on_id(events, event_desc):

Callers 1

events_from_annotationsFunction · 0.85

Calls 2

compileMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected