Events#
CSV Events#
- class CSVEventsInterface(file_path: Annotated[pathlib._local.Path, PathType(path_type='file')], *, timestamps_column: str | int, event_type_column: str | int | None, metadata_key: str | None = None, read_kwargs: dict | None = None, verbose: bool = False)[source]#
Bases:
BaseDataInterfaceData Interface for converting discrete events from a single CSV file.
This is a general-purpose CSV events reader: the caller points at one CSV file and names the column holding the event timestamps in seconds (
timestamps_column) and, optionally, the column that tells the event types apart (event_type_column).Two layouts are supported:
A single event type (
event_type_column=None): every row is one occurrence of the same event, and the file becomes onendx_events.Eventsobject named after the file stem.Several event types in one file (
event_type_columnset): each row carries a label in that column, and the file becomes onendx_events.LabeledEventsobject named after the file stem – the timestamps plus a per-event integer code into the label vocabulary. This mirrors howTDTEventsInterfacewrites a labeled (strobe) store.
Columns other than
timestamps_columnandevent_type_columnare ignored; only timestamps (and, for the labeled case, the event labels) are written.Notes
CSV recordings carry no embedded recording-start timestamp, so
get_metadata()does NOT populateNWBFile/session_start_time. The user must supply it via editable metadata.Initialize the CSVEventsInterface.
- Parameters:
file_path (FilePath) – The path to the CSV file holding the events.
timestamps_column (str or int) – The column holding the event timestamps (seconds). A column name for a CSV with a header row, or a positional index (0-based) for a header-less CSV.
event_type_column (str, int, or None) – The column, if any, that names the type of each event. Pass a column name or index when the file holds several event types told apart by that column, so that the file is written as a single
LabeledEventswith one label per distinct value. Pass None when the file is a single event type with no such column, in which case the file is written as a plainEventsnamed after the file stem.metadata_key (str, optional) – The key under
metadata["Events"]that namespaces this interface’s events metadata. If None (default),"csv_events"is used.read_kwargs (dict, optional) – Additional keyword arguments forwarded to
pandas.read_csv, used to handle format quirks such assep,encoding,decimal, orskiprows. Any value given here overrides the interface’s own defaults (header,float_precision, andkeep_default_na=False– the latter keeps label tokens such as'None','NA', or'null'from collapsing into a single missing label). Default is None.verbose (bool, optional) – Whether to print status messages, default = False.
- keywords: tuple[str] = ('events', 'CSV')#
- display_name: str | None = 'CSVEvents'#
- info: str | None = 'Data Interface for converting discrete events from a single CSV file.'#
- associated_suffixes: tuple[str] = ('csv',)#
- get_metadata() DeepDict[source]#
Get metadata for the CSVEventsInterface.
NWBFile/session_start_timeis intentionally left unset: CSV recordings carry no embedded recording-start timestamp, so it must be supplied by the user via editable metadata.- Returns:
The metadata dictionary for this interface.
- Return type:
- get_metadata_schema() dict[source]#
Get the metadata schema for the CSVEventsInterface.
- Returns:
The metadata schema for this interface.
- Return type:
dict
- add_to_nwbfile(nwbfile: NWBFile, metadata: dict) None[source]#
Add the events to the NWBFile as an
ndx_events.EventsorLabeledEventsobject.- Parameters:
nwbfile (NWBFile) – The NWB file to add the events to.
metadata (dict) – Metadata dictionary. The single entry in
metadata["Events"][metadata_key]["event_columns"]holds the output object’scolumn_nameanddescription. Acolumn_categories["labels"]map (raw value -> display label) marks the file as labeled and is written asLabeledEvents; its absence writes a plainEvents.
TDT Events#
- class TDTEventsInterface(folder_path: Annotated[pathlib._local.Path, PathType(path_type='dir')], *, exclude_events: list[str] | None = None, metadata_key: str | None = None, verbose: bool = False)[source]#
Bases:
TDTLoadMixin,BaseEventsInterfaceData Interface for converting discrete events (epocs) from a TDT output folder.
The TDT tank stores discrete events as epocs (e.g. camera TTL pulses, port entries, nose pokes). This interface reads those epocs via
tdt.read_blockand writes each selected epoc as onepynwb.event.EventsTableinsidenwbfile.events.Most epoc stores are onset-type epocs whose
dataarray is a meaningless incrementing counter, so only the onsets are written (a timestamp-only table). A store whosedatacarries real strobe codes (e.g. thePAB_store’s[16, 2064, 0]cycle) additionally gets a categoricalstrobecolumn, with the codes as per-event labels. Theoffsetarray of an onset-type epoc is a synthesized fill (offset[i] == onset[i + 1], last valueinf) and is not written. Epocs that carry real offset (STROFF) durations are written as durative events, with each event’s duration (offsetminusonset) in the table’sdurationcolumn.Initialize the TDTEventsInterface.
- Parameters:
folder_path (DirectoryPath) – The path to the folder containing the TDT data.
exclude_events (list[str], optional) – The names of the TDT epocs to skip. If None (default), every epoc in the tank is stored.
metadata_key (str, optional) – The key under
metadata["Events"]that namespaces this interface’s events metadata. If None (default),"tdt_events"is used.verbose (bool, optional) – Whether to print status messages, default = False.
- keywords: tuple[str] = ('events', 'TDT')#
- display_name: str | None = 'TDTEvents'#
- info: str | None = 'Data Interface for converting discrete events (epocs) from TDT files.'#
- associated_suffixes: tuple[str] = ('Tbk', 'Tdx', 'tev', 'tin', 'tsq')#