Skip to main content

NWB extension for storing timestamped event and TTL pulse data

Project description

ndx-events Extension for NWB

This is an NWB extension for storing timestamped event data and TTL pulses.

Events can be:

  1. Simple events. These are stored in the Events type. The Events type consists of only a name, a description, and a 1D array of timestamps. This should be used instead of a TimeSeries when the time series has no data.
  2. Labeled events. These are stored in the LabeledEvents type. The LabeledEvents type expands on the Events type 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. The LabeledEvents type can be used to encode additional information about individual events, such as the reward values for each reward event.
  3. TTL pulses. These are stored in the TTLs type. The TTLs type is a subtype of the LabeledEvents type 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.
  4. Annotated events. These are stored in the AnnotatedEventsTable type. The AnnotatedEventsTable type is a subtype of DynamicTable, 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_746RdMoDdmQPu940s0YtDjb1en1Xtdw

Installation

pip install ndx-events

Example usage

from datetime import datetime

from pynwb import NWBFile, NWBHDF5IO
from ndx_events import LabeledEvents, AnnotatedEventsTable


nwb = 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 system
events = 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 timestamps
    data=[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 file
nwb.add_acquisition(events)

# create a new AnnotatedEventsTable type to hold annotated events
annotated_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 event
annotated_events.add_column(
    name='bad_event',
    description='whether each event time should be excluded',
    index=True
)
# add an event type (row) to the AnnotatedEventsTable instance
annotated_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 data
events_module = nwb.create_processing_module(
    name='events',
    description='processed event data'
)

# add the AnnotatedEventsTable instance to the processing module
events_module.add(annotated_events)

# write nwb file
filename = 'test.nwb'
with NWBHDF5IO(filename, 'w') as io:
    io.write(nwb)

# read nwb file and check its contents
with NWBHDF5IO(filename, 'r', load_namespaces=True) as io:
    nwb = io.read()
    print(nwb)

This extension was created using ndx-template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ndx-events-0.2.0.tar.gz (46.6 kB view details)

Uploaded Source

Built Distribution

ndx_events-0.2.0-py2.py3-none-any.whl (13.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ndx-events-0.2.0.tar.gz.

File metadata

  • Download URL: ndx-events-0.2.0.tar.gz
  • Upload date:
  • Size: 46.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1.post20200807 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.7

File hashes

Hashes for ndx-events-0.2.0.tar.gz
Algorithm Hash digest
SHA256 25eceed121a9b889b35e7d32dba8c7c3d53ae22c28757942643ace970344c25b
MD5 a02c00e9a6a398e7b21a534562aa1b98
BLAKE2b-256 cc8efee05ba54096c7018a899a792c771f273350a88048cb279a99da58ffdbd5

See more details on using hashes here.

File details

Details for the file ndx_events-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: ndx_events-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1.post20200807 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.7

File hashes

Hashes for ndx_events-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9db80ab09b11979c1678d948f6a7cb7ee2833f3d743e660391b731f6c15320af
MD5 e8840977416fc58e1c2bb317728e0e4f
BLAKE2b-256 c9ca80b271590d381d958864936478a7c7807a7e7cb0a11a0b51e65c3fb3d84d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page