Package: ndx-events
ndx-events Extension for NWBThis is an NWB extension for storing timestamped event data and TTL pulses.Events can be:Simple events. These are stored in theEventstype. TheEventstype consists of only a name, a description,
and a 1D array of timestamps. This should be used instead of aTimeSerieswhen the time series has no data.Labeled events. These are stored in theLabeledEventstype. TheLabeledEventstype expands on theEventstype by adding 1) a 1D array of integer values (data) with the same length as the timestamps and 2) a 1D array of
labels (labels) associated with each unique integer value in the data array. The data values are indices into the
array of labels. TheLabeledEventstype can be used to encode additional information about individual events,
such as the reward values for each reward event.TTL pulses. These are stored in theTTLstype. TheTTLstype is a subtype of theLabeledEventstype
specifically for TTL pulse data. A single instance should be used for all TTL pulse data. The pulse value (or channel)
should be stored in the 1D data array, and the labels associated with each pulse value (or channel)
should be stored in the 1D array of labels.Annotated events. These are stored in theAnnotatedEventsTabletype. TheAnnotatedEventsTabletype is a
subtype ofDynamicTable, where each row corresponds to a different event type. The table has a ragged
(variable-length) 1D column of event times, such that each event type (row) is associated with an array of event times.
Unlike for the other event types, users can add their own custom columns to annotate each event type or event time.
This can be useful for storing event metadata related to data preprocessing and analysis, such as marking bad events.This extension was developed by Ryan Ly, Ben Dichter, Oliver RÃ¼bel, and Andrew Tritt. Information about the rationale,
background, and alternative approaches to this extension can be found here:https://docs.google.com/document/d/1qcsjyFVX9oI_746RdMoDdmQPu940s0YtDjb1en1XtdwInstallationpip install ndx-eventsExample usagefromdatetimeimportdatetimefrompynwbimportNWBFile,NWBHDF5IOfromndx_eventsimportLabeledEvents,AnnotatedEventsTablenwb=NWBFile(session_description='session description',identifier='cool_experiment_001',session_start_time=datetime.now().astimezone())# create a new LabeledEvents type to hold events recorded from the data acquisition systemevents=LabeledEvents(name='LabeledEvents',description='events from my experiment',timestamps=[0.,0.5,0.6,2.,2.05,3.,3.5,3.6,4.],resolution=1e-5,# resolution of the timestamps, i.e., smallest possible difference between timestampsdata=[0,1,2,3,5,0,1,2,4],labels=['trial_start','cue_onset','cue_offset','response_left','response_right','reward'])# add the LabeledEvents type to the acquisition group of the NWB filenwb.add_acquisition(events)# create a new AnnotatedEventsTable type to hold annotated eventsannotated_events=AnnotatedEventsTable(name='AnnotatedEventsTable',description='annotated events from my experiment',resolution=1e-5# resolution of the timestamps, i.e., smallest possible difference between timestamps)# add a custom indexed (ragged) column to represent whether each event time was a bad eventannotated_events.add_column(name='bad_event',description='whether each event time should be excluded',index=True)# add an event type (row) to the AnnotatedEventsTable instanceannotated_events.add_event_type(label='Reward',event_description='Times when the subject received juice reward.',event_times=[1.,2.,3.],bad_event=[False,False,True],id=3)# create a processing module in the NWB file to hold processed events dataevents_module=nwb.create_processing_module(name='events',description='processed event data')# add the AnnotatedEventsTable instance to the processing moduleevents_module.add(annotated_events)# write nwb filefilename='test.nwb'withNWBHDF5IO(filename,'w')asio:io.write(nwb)# read nwb file and check its contentswithNWBHDF5IO(filename,'r',load_namespaces=True)asio:nwb=io.read()print(nwb)This extension was created usingndx-template.