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 support for ElectricalSeries.filtering dataset #1270

Merged
merged 4 commits into from
Jul 30, 2020
Merged
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
17 changes: 14 additions & 3 deletions src/pynwb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class TimeSeries(NWBDataInterface):
"rate",
"starting_time_unit",
"control",
"control_description")
"control_description",
"continuity")

__time_unit = "seconds"

Expand All @@ -118,18 +119,28 @@ class TimeSeries(NWBDataInterface):
{'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})
'default': None},
{'name': 'continuity', 'type': str, 'default': None, 'enum': ["continuous", "instantaneous", "step"],
'doc': 'Optionally describe the continuity of the data. Can be "continuous", "instantaneous", or'
'"step". For example, a voltage trace would be "continuous", because samples are recorded from a '
'continuous process. An array of lick times would be "instantaneous", because the data represents '
'distinct moments in time. Times of image presentations would be "step" because the picture '
'remains the same until the next time-point. This field is optional, but is useful in providing '
'information about the underlying data. It may inform the way this data is interpreted, the way it '
'is visualized, and what analysis methods are applicable.'})
def __init__(self, **kwargs):
"""Create a TimeSeries object
"""

call_docval_func(super(TimeSeries, self).__init__, kwargs)
keys = ("resolution",
"comments",
"description",
"conversion",
"unit",
"control",
"control_description")
"control_description",
"continuity")
for key in keys:
val = kwargs.get(key)
if val is not None:
Expand Down
13 changes: 11 additions & 2 deletions src/pynwb/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class ElectricalSeries(TimeSeries):

__nwbfields__ = ({'name': 'electrodes', 'required_name': 'electrodes',
'doc': 'the electrodes that generated this electrical series', 'child': True},
'channel_conversion')
'channel_conversion',
'filtering')

@docval(*get_docval(TimeSeries.__init__, 'name'), # required
{'name': 'data', 'type': ('array_data', 'data', TimeSeries), # required
Expand All @@ -65,13 +66,21 @@ class ElectricalSeries(TimeSeries):
"to support the storage of electrical recordings as native values generated by data acquisition systems. "
"If this dataset is not present, then there is no channel-specific conversion factor, i.e. it is 1 for all"
" channels.", 'default': None},
{'name': 'filtering', 'type': str, 'doc':
"Filtering applied to all channels of the data. For example, if this ElectricalSeries represents "
"high-pass-filtered data (also known as AP Band), then this value could be 'High-pass 4-pole Bessel "
"filter at 500 Hz'. If this ElectricalSeries represents low-pass-filtered LFP data and the type of "
"filter is unknown, then this value could be 'Low-pass filter at 300 Hz'. If a non-standard filter "
"type is used, provide as much detail about the filter properties as possible.", 'default': None},
*get_docval(TimeSeries.__init__, 'resolution', 'conversion', 'timestamps', 'starting_time', 'rate',
'comments', 'description', 'control', 'control_description'))
def __init__(self, **kwargs):
name, electrodes, data, channel_conversion = popargs('name', 'electrodes', 'data', 'channel_conversion', kwargs)
name, electrodes, data, channel_conversion, filtering = popargs('name', 'electrodes', 'data',
'channel_conversion', 'filtering', kwargs)
super(ElectricalSeries, self).__init__(name, data, 'volts', **kwargs)
self.electrodes = electrodes
self.channel_conversion = channel_conversion
self.filtering = filtering


@register_class('SpikeEventSeries', CORE_NAMESPACE)
Expand Down
1 change: 1 addition & 0 deletions src/pynwb/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, spec):
self.map_spec('unit', data_spec.get_attribute('unit'))
self.map_spec('resolution', data_spec.get_attribute('resolution'))
self.map_spec('conversion', data_spec.get_attribute('conversion'))
self.map_spec('continuity', data_spec.get_attribute('continuity'))

timestamps_spec = self.spec.get_dataset('timestamps')
self.map_spec('timestamps_unit', timestamps_spec.get_attribute('unit'))
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/hdf5/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def setUpContainer(self):
data=list(range(1000)),
unit='SIunit',
timestamps=np.arange(1000.),
resolution=0.1
resolution=0.1,
continuity='continuous',
)


Expand Down
15 changes: 10 additions & 5 deletions tests/integration/hdf5/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ def setUpContainer(self):
table=self.table)
data = list(zip(range(10), range(10, 20)))
timestamps = list(map(lambda x: x/10., range(10)))
es = ElectricalSeries(name='test_eS',
data=data,
electrodes=region,
channel_conversion=[4., .4],
timestamps=timestamps)
channel_conversion = [1., 2., 3., 4.]
filtering = 'Low-pass filter at 300 Hz'
es = ElectricalSeries(
name='test_eS',
data=data,
electrodes=region,
channel_conversion=channel_conversion,
filtering=filtering,
timestamps=timestamps
)
return es

def addContainer(self, nwbfile):
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ def test_timestamps_timeseries(self):
'grams', timestamps=ts1)
self.assertEqual(ts2.timestamps, [0.0, 0.1, 0.2, 0.3, 0.4, 0.5])

def test_good_continuity_timeseries(self):
ts1 = TimeSeries('test_ts1', [0, 1, 2, 3, 4, 5],
'grams', timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5],
continuity='continuous')
self.assertEqual(ts1.continuity, 'continuous')

def test_bad_continuity_timeseries(self):
with self.assertRaises(ValueError):
TimeSeries('test_ts1', [0, 1, 2, 3, 4, 5],
'grams', timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5],
continuity='wrong')

def test_nodata(self):
ts1 = TimeSeries('test_ts1', starting_time=0.0, rate=0.1)
with self.assertWarns(UserWarning):
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@ class ElectricalSeriesConstructor(TestCase):
def test_init(self):
data = list(range(10))
ts = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
channel_conversion = [2., 6.3]
filtering = 'Low-pass filter at 300 Hz'
table = make_electrode_table()
region = DynamicTableRegion('electrodes', [0, 2], 'the first and third electrodes', table)
eS = ElectricalSeries('test_eS', data, region, channel_conversion=[2., 6.3], timestamps=ts)
eS = ElectricalSeries(
name='test_eS',
data=data,
electrodes=region,
channel_conversion=channel_conversion,
filtering=filtering,
timestamps=ts
)
self.assertEqual(eS.name, 'test_eS')
self.assertEqual(eS.data, data)
self.assertEqual(eS.electrodes, region)
self.assertEqual(eS.timestamps, ts)
self.assertEqual(eS.channel_conversion, [2., 6.3])
self.assertEqual(eS.filtering, filtering)

def test_link(self):
table = make_electrode_table()
Expand Down