Skip to content

Commit db29bbf

Browse files
authored
Deprecate EventDetection.times (#2101)
* add deprecation warning to eventdetection * add tests for time deprecation * update CHANGELOG
1 parent ddca692 commit db29bbf

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Deprecated `Device.model_name`, `Device.model_number`, and `Device.manufacturer` fields in favor of `DeviceModel`. @rly [#2088](https://github.com/NeurodataWithoutBorders/pynwb/pull/2088)
1616
- Added support for 2D `EventDetection.source_index` to indicate [time_index, channel_index]. @stephprince [#2091](https://github.com/NeurodataWithoutBorders/pynwb/pull/2091)
1717
- Made `EventDetection.times` optional. @stephprince [#2091](https://github.com/NeurodataWithoutBorders/pynwb/pull/2091)
18+
- Deprecated `EventDetection.times`. @stephprince [#2101](https://github.com/NeurodataWithoutBorders/pynwb/pull/2101)
1819
- Automatically add timezone information to timestamps reference time if no timezone information is specified. @stephprince [#2056](https://github.com/NeurodataWithoutBorders/pynwb/pull/2056)
1920
- Added option to disable typemap caching and updated type map cache location. @stephprince [#2057](https://github.com/NeurodataWithoutBorders/pynwb/pull/2057)
2021
- Added dictionary-like operations directly on `ProcessingModule` objects (e.g., `len(processing_module)`). @bendichter [#2020](https://github.com/NeurodataWithoutBorders/pynwb/pull/2020)

src/pynwb/ecephys.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,21 @@ class EventDetection(NWBDataInterface):
225225
'[time_index, channel_index] for each event. Module description should define what is meant '
226226
'by time of event (e.g., .25msec before action potential peak, zero-crossing time, etc). '
227227
'The index points to each event from the raw data'},
228-
{'name': 'times', 'type': ('array_data', 'data'), 'doc': 'Timestamps of events, in Seconds',
228+
{'name': 'times', 'type': ('array_data', 'data'), 'doc': 'DEPRECATED. Timestamps of events, in Seconds',
229229
'default': None},
230230
{'name': 'name', 'type': str, 'doc': 'the name of this container', 'default': 'EventDetection'},
231231
allow_positional=AllowPositional.WARNING,)
232232
def __init__(self, **kwargs):
233233
args_to_set = popargs_to_dict(('detection_method', 'source_electricalseries', 'source_idx', 'times'), kwargs)
234234
super().__init__(**kwargs)
235235

236+
if args_to_set['times'] is not None:
237+
warnings.warn(
238+
"The 'times' argument is deprecated and will be removed in a future version. " \
239+
"Use 'source_idx' instead to specify the time of events.",
240+
DeprecationWarning,
241+
)
242+
236243
# Validate source_idx shape
237244
source_idx = args_to_set['source_idx']
238245
source_idx_shape = get_data_shape(source_idx, strict_no_data_load=True)

tests/integration/hdf5/test_ecephys.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ def addContainer(self):
326326
detection_method='detection_method',
327327
source_electricalseries=eS,
328328
source_idx=(1, 2, 3),
329-
times=(0.1, 0.2, 0.3)
330329
)
331330

332331
self.nwbfile.add_acquisition(eS)

tests/unit/test_ecephys.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,10 @@ def test_init(self):
282282
eS = ElectricalSeries(name='test_eS', data=data, electrodes=region, timestamps=ts)
283283
eD = EventDetection(detection_method='detection_method',
284284
source_electricalseries=eS,
285-
source_idx=(1, 2, 3),
286-
times=(0.1, 0.2, 0.3))
285+
source_idx=(1, 2, 3))
287286
self.assertEqual(eD.detection_method, 'detection_method')
288287
self.assertEqual(eD.source_electricalseries, eS)
289288
self.assertEqual(eD.source_idx, (1, 2, 3))
290-
self.assertEqual(eD.times, (0.1, 0.2, 0.3))
291289
self.assertEqual(eD.unit, 'seconds')
292290

293291
def test_init_2d_source_idx(self):
@@ -299,17 +297,14 @@ def test_init_2d_source_idx(self):
299297

300298
# 2D source_idx with shape (num_events, 2) for [time_index, channel_index]
301299
source_idx_2d = np.array([[1, 0], [2, 1], [3, 0],]) # 3 events
302-
times = (0.1, 0.2, 0.3)
303300

304301
eD = EventDetection(detection_method='threshold detection',
305302
source_electricalseries=eS,
306-
source_idx=source_idx_2d,
307-
times=times)
303+
source_idx=source_idx_2d)
308304

309305
self.assertEqual(eD.detection_method, 'threshold detection')
310306
self.assertEqual(eD.source_electricalseries, eS)
311307
np.testing.assert_array_equal(eD.source_idx, source_idx_2d)
312-
self.assertEqual(eD.times, times)
313308
self.assertEqual(eD.unit, 'seconds')
314309

315310
def test_init_optional_times(self):
@@ -328,6 +323,22 @@ def test_init_optional_times(self):
328323
self.assertEqual(eD.source_idx, (1, 2, 3))
329324
self.assertIsNone(eD.times)
330325

326+
def test_times_deprecation_warning(self):
327+
"""Test that using times parameter raises deprecation warning"""
328+
data = list(range(10))
329+
ts = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
330+
_, region = self._create_table_and_region()
331+
eS = ElectricalSeries(name='test_eS', data=data, electrodes=region, timestamps=ts)
332+
333+
# Test that deprecation warning is raised when times is provided
334+
msg = ("The 'times' argument is deprecated and will be removed in a future version. "
335+
"Use 'source_idx' instead to specify the time of events.")
336+
with self.assertWarnsWith(DeprecationWarning, msg):
337+
EventDetection(detection_method='test_method',
338+
source_electricalseries=eS,
339+
source_idx=(1, 2, 3),
340+
times=(0.1, 0.2, 0.3))
341+
331342
def test_invalid_2d_source_idx_shape(self):
332343
"""Test error handling for invalid 2D source_idx shapes"""
333344
data = list(range(10))
@@ -343,8 +354,7 @@ def test_invalid_2d_source_idx_shape(self):
343354
with self.assertRaisesWith(ValueError, msg):
344355
EventDetection(detection_method='detection_method',
345356
source_electricalseries=eS,
346-
source_idx=invalid_source_idx,
347-
times=(0.1, 0.2))
357+
source_idx=invalid_source_idx)
348358

349359
def test_invalid_3d_source_idx(self):
350360
"""Test error handling for 3D source_idx arrays"""
@@ -361,8 +371,7 @@ def test_invalid_3d_source_idx(self):
361371
with self.assertRaisesWith(ValueError, msg):
362372
EventDetection(detection_method='detection_method',
363373
source_electricalseries=eS,
364-
source_idx=invalid_source_idx,
365-
times=(0.1, 0.2))
374+
source_idx=invalid_source_idx)
366375

367376
class EventWaveformConstructor(TestCase):
368377

0 commit comments

Comments
 (0)