Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add UnitSeries #822

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/pynwb/data/nwb.misc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,32 @@ groups:
- null
quantity: '?'
default_name: Units
- neurodata_type_def: UnitSeries
neurodata_type_inc: TimeSeries
doc: Unit spike times a stream of IDs of spiking units
attributes:
- name: help
dtype: text
doc: Value is 'Unit spike times a stream of IDs of spiking units'
value: Unit spike times a stream of IDs of spiking units
datasets:
- name: data
dtype: int
doc: the index of the spike unit in the DynamicTableRegion "units"
attributes:
- name: resolution
dtype: float
doc: Value is -1.0. Indices do not have resolution
value: -1.0
- name: unit
dtype: text
doc: Value is 'index'
value: index
dims:
- num_times
shape:
- null
links:
- name: units
doc: The units table that is being indexed
target_type: Units
26 changes: 26 additions & 0 deletions src/pynwb/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,29 @@ def add_band(self, **kwargs):
self.__check_column('band_stdev', 'the standard deviation of Gaussian filters in Hz')

self.bands.add_row({k: v for k, v in kwargs.items() if v is not None})


class UnitSeries(TimeSeries):

__nwbfields__ = ({'name': 'units', 'child': False, 'doc': 'link to Units table'},)

@docval({'name': 'name', 'type': str, 'doc': 'The name of this UnitSeries dataset'},
{'name': 'data', 'type': ('array_data', 'data', TimeSeries), 'shape': (None,),
'doc': 'Indices of Units table (0-indexed)'},
{'name': 'timestamps', 'type': ('array_data', 'data', TimeSeries), 'shape': (None,),
'doc': 'Timestamps for samples stored in data', 'default': None},
{'name': 'units', 'type': Units, 'doc': 'Units table', 'default': None},
{'name': 'description', 'type': str,
'doc': 'Description of this TimeSeries dataset', 'default': 'no description'},
{'name': 'control', 'type': Iterable,
'doc': 'Numerical labels that apply to each element in data', 'default': None},
{'name': 'control_description', 'type': Iterable,
'doc': 'Description of each control value', 'default': None},
{'name': 'parent', 'type': NWBContainer,
'doc': 'The parent NWBContainer for this NWBContainer', 'default': None})
def __init__(self, **kwargs):
kwargs.update(conversion=np.nan, resolution=np.nan)

name, data, units = popargs('name', 'data', 'units', kwargs)
super(UnitSeries, self).__init__(name, data, **kwargs)
self.units = units
11 changes: 10 additions & 1 deletion tests/unit/pynwb_tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from pynwb.misc import AnnotationSeries, AbstractFeatureSeries, IntervalSeries, Units, \
DecompositionSeries
DecompositionSeries, UnitSeries
from pynwb.file import TimeSeries, DynamicTable
from pynwb.core import VectorData

Expand Down Expand Up @@ -150,5 +150,14 @@ def test_times_and_intervals(self):
self.assertTrue(np.all(ut['obs_intervals'][1] == np.array([[2, 3], [4, 5]])))


class UnitSeriesConstructor(unittest.TestCase):
def test_init(self):
units = Units()
us = UnitSeries('test_unit_series', np.array([0, 0, 1, 1], dtype=int),
timestamps=[.1, .2, .3, .4], units=units, description='description')
self.assertTrue(all(us.data == np.array([0, 0, 1, 1], dtype=int)))
self.assertEqual(units, us.units)


if __name__ == '__main__':
unittest.main()