neuralset.events.etypes.Event¶
- class neuralset.events.etypes.Event(*, start: float, timeline: str, duration: Annotated[float, Ge(ge=0)] = 0.0, extra: dict[str, Any] = {})[source][source]¶
Base class for all event types.
Every event has a time span (
start,duration) and belongs to a timeline. Concrete subclasses (Meg,Image,Word,Fmri, …) add type-specific fields. Events are collected into a pandas DataFrame for bulk processing; thestopcolumn (start + duration) is added bystandardize_events().When instantiated via
from_dict(), extra fields not in the schema are silently grouped underextrarather than raising.- Parameters:
start (float) – Start time of the event in seconds.
timeline (str) – Timeline identifier to which this event belongs.
duration (float, optional) – Duration of the event in seconds (default: 0.0).
extra (dict, optional) – Dictionary for storing additional arbitrary fields (default: {}).
admonition: (..) – Design rationale —
start/duration: Events usestart/durationrather thanonset/offsetbecauseoffsetis ambiguous — it can mean “end time” or “time shift from a reference” (e.g.Video.offset, fMRI HRF delays, MEGfirst_samp).durationis unambiguous and is used directly to compute sample counts, rather thanto_ind(stop) - to_ind(start)which can vary with alignment.onset/offset (not) – Events use
start/durationrather thanonset/offsetbecauseoffsetis ambiguous — it can mean “end time” or “time shift from a reference” (e.g.Video.offset, fMRI HRF delays, MEGfirst_samp).durationis unambiguous and is used directly to compute sample counts, rather thanto_ind(stop) - to_ind(start)which can vary with alignment.
- classmethod from_dict(row: Any) E[source][source]¶
Create event from dictionary/row/named-tuple while grouping non-specified fields.
Fields not defined in the event class schema are automatically grouped under the
extradict attribute.- Parameters:
row (dict, NamedTuple, or pandas.Series) – Input data containing event fields. Must include a ‘type’ field indicating the event class name.
- Returns:
Instance of the appropriate Event subclass based on the ‘type’ field
- Return type:
Notes
NaN values in the input are ignored
if the input has an Index attribute, it’s stored in
_indexfor debugging
Examples
data = {'type': 'Word', 'start': 1.0, 'timeline': 'exp1', 'text': 'hello'} event = Event.from_dict(data) # returns a Word instance
- property stop: float[source]¶
Compute the end time of the event.
- Returns:
The stop time calculated as start + duration
- Return type:
- to_dict() dict[str, Any][source][source]¶
Export the event as a dictionary usable for CSV dump.
The
extradictionary field is flattened into separate fields to simplify queries through pandas DataFrames.- Returns:
Flattened dictionary representation of the event with ‘type’ field included
- Return type:
Examples
event = Word(start=1.0, timeline="exp", text="hello") event_dict = event.to_dict() df = pd.DataFrame([event_dict])