Skip to content

Commit 78537e3

Browse files
oruebelrly
andauthored
Replace ic_electrode with icephys_electrode on NWBFile (#1200)
* Deprecate ic_electrode params and funcs on NWBFile with icephys_electrode params and funcs. Fix #1181 * Replace use of ic_electrode with icephys_electrode in integration tests * Add tests to check that deprecation warnings are raised for ic_electrode uses * Replace use of ic_electrode with icephys_electrode in the ICEphys tutorial * Fix flake8 * Update tests/unit/test_icephys.py Co-Authored-By: Ryan Ly <[email protected]> * Simplify testing of warnings using self.assertWarnsWith as suggested by @rly * Mover icephys_electrodes NWBFile constructor arg to the end to not break backward compatibility as suggest by @rly Co-authored-by: Ryan Ly <[email protected]>
1 parent 13c8c51 commit 78537e3

File tree

5 files changed

+141
-27
lines changed

5 files changed

+141
-27
lines changed

docs/gallery/domain/icephys.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
#
4545
# Intracellular electrode metadata is represented by :py:class:`~pynwb.icephys.IntracellularElectrode` objects.
4646
# To create an electrode group, you can use the :py:class:`~pynwb.file.NWBFile` instance method
47-
# :py:meth:`~pynwb.file.NWBFile.create_ic_electrode`.
47+
# :py:meth:`~pynwb.file.NWBFile.create_icephys_electrode`.
4848

49-
elec = nwbfile.create_ic_electrode(name="elec0",
50-
description='a mock intracellular electrode',
51-
device=device)
49+
elec = nwbfile.create_icephys_electrode(name="elec0",
50+
description='a mock intracellular electrode',
51+
device=device)
5252

5353
#######################
5454
# Stimulus data
@@ -160,7 +160,7 @@
160160
####################
161161
# We can also get back the electrode we added.
162162

163-
elec = nwbfile.get_ic_electrode('elec0')
163+
elec = nwbfile.get_icephys_electrode('elec0')
164164

165165
####################
166166
# Alternatively, we can also get this electrode from the :py:class:`~pynwb.icephys.CurrentClampStimulusSeries`

src/pynwb/file.py

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ class NWBFile(MultiContainerInterface):
140140
'get': 'get_imaging_plane'
141141
},
142142
{
143-
'attr': 'ic_electrodes',
144-
'add': 'add_ic_electrode',
143+
'attr': 'icephys_electrodes',
144+
'add': 'add_icephys_electrode',
145145
'type': IntracellularElectrode,
146-
'create': 'create_ic_electrode',
147-
'get': 'get_ic_electrode'
146+
'create': 'create_icephys_electrode',
147+
'get': 'get_icephys_electrode'
148148
},
149149
{
150150
'attr': 'ogen_sites',
@@ -275,7 +275,8 @@ class NWBFile(MultiContainerInterface):
275275
{'name': 'electrode_groups', 'type': Iterable,
276276
'doc': 'the ElectrodeGroups that belong to this NWBFile', 'default': None},
277277
{'name': 'ic_electrodes', 'type': (list, tuple),
278-
'doc': 'IntracellularElectrodes that belong to this NWBFile', 'default': None},
278+
'doc': 'DEPRECATED use icephys_electrodes parameter instead. '
279+
'IntracellularElectrodes that belong to this NWBFile', 'default': None},
279280
{'name': 'sweep_table', 'type': SweepTable,
280281
'doc': 'the SweepTable that belong to this NWBFile', 'default': None},
281282
{'name': 'imaging_planes', 'type': (list, tuple),
@@ -287,7 +288,9 @@ class NWBFile(MultiContainerInterface):
287288
{'name': 'subject', 'type': Subject,
288289
'doc': 'subject metadata', 'default': None},
289290
{'name': 'scratch', 'type': (list, tuple),
290-
'doc': 'scratch data', 'default': None})
291+
'doc': 'scratch data', 'default': None},
292+
{'name': 'icephys_electrodes', 'type': (list, tuple),
293+
'doc': 'IntracellularElectrodes that belong to this NWBFile.', 'default': None})
291294
def __init__(self, **kwargs):
292295
kwargs['name'] = 'root'
293296
call_docval_func(super(NWBFile, self).__init__, kwargs)
@@ -322,7 +325,6 @@ def __init__(self, **kwargs):
322325
'electrodes',
323326
'electrode_groups',
324327
'devices',
325-
'ic_electrodes',
326328
'imaging_planes',
327329
'ogen_sites',
328330
'intervals',
@@ -352,6 +354,14 @@ def __init__(self, **kwargs):
352354
for attr in fieldnames:
353355
setattr(self, attr, kwargs.get(attr, None))
354356

357+
# backwards-compatibility code for ic_electrodes / icephys_electrodes
358+
ic_elec_val = kwargs.get('icephys_electrodes', None)
359+
if ic_elec_val is None and kwargs.get('ic_electrodes', None) is not None:
360+
ic_elec_val = kwargs.get('ic_electrodes', None)
361+
warn("Use of the ic_electrodes parameter is deprecated. "
362+
"Use the icephys_electrodes parameter instead", DeprecationWarning)
363+
setattr(self, 'icephys_electrodes', ic_elec_val)
364+
355365
experimenter = kwargs.get('experimenter', None)
356366
if isinstance(experimenter, str):
357367
experimenter = (experimenter,)
@@ -404,6 +414,35 @@ def ec_electrodes(self):
404414
warn("replaced by NWBFile.electrodes", DeprecationWarning)
405415
return self.electrodes
406416

417+
@property
418+
def ic_electrodes(self):
419+
warn("deprecated. use NWBFile.icephys_electrodes instead", DeprecationWarning)
420+
return self.icephys_electrodes
421+
422+
def add_ic_electrode(self, *args, **kwargs):
423+
"""
424+
This method is deprecated and will be removed in future versions. Please
425+
use :py:meth:`~pynwb.file.NWBFile.add_icephys_electrode` instead
426+
"""
427+
warn("deprecated, use NWBFile.add_icephys_electrode instead", DeprecationWarning)
428+
return self.add_icephys_electrode(*args, **kwargs)
429+
430+
def create_ic_electrode(self, *args, **kwargs):
431+
"""
432+
This method is deprecated and will be removed in future versions. Please
433+
use :py:meth:`~pynwb.file.NWBFile.create_icephys_electrode` instead
434+
"""
435+
warn("deprecated, use NWBFile.create_icephys_electrode instead", DeprecationWarning)
436+
return self.create_icephys_electrode(*args, **kwargs)
437+
438+
def get_ic_electrode(self, *args, **kwargs):
439+
"""
440+
This method is deprecated and will be removed in future versions. Please
441+
use :py:meth:`~pynwb.file.NWBFile.get_icephys_electrode` instead
442+
"""
443+
warn("deprecated, use NWBFile.get_icephys_electrode instead", DeprecationWarning)
444+
return self.get_icephys_electrode(*args, **kwargs)
445+
407446
def __check_epochs(self):
408447
if self.epochs is None:
409448
self.epochs = TimeIntervals('epochs', 'experimental epochs')

src/pynwb/io/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self, spec):
4949

5050
icephys_spec = general_spec.get_group('intracellular_ephys')
5151
self.unmap(icephys_spec)
52-
self.map_spec('ic_electrodes', icephys_spec.get_neurodata_type('IntracellularElectrode'))
52+
self.map_spec('icephys_electrodes', icephys_spec.get_neurodata_type('IntracellularElectrode'))
5353
self.map_spec('sweep_table', icephys_spec.get_neurodata_type('SweepTable'))
5454

5555
# TODO map the filtering dataset to something or deprecate it

tests/integration/hdf5/test_icephys.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def setUpContainer(self):
2222

2323
def addContainer(self, nwbfile):
2424
""" Add the test IntracellularElectrode and Device to the given NWBFile """
25-
nwbfile.add_ic_electrode(self.container)
25+
nwbfile.add_icephys_electrode(self.container)
2626
nwbfile.add_device(self.device)
2727

2828
def getContainer(self, nwbfile):
2929
""" Return the test IntracellularElectrode from the given NWBFile """
30-
return nwbfile.get_ic_electrode(self.container.name)
30+
return nwbfile.get_icephys_electrode(self.container.name)
3131

3232

3333
class TestPatchClampSeries(AcquisitionH5IOMixin, TestCase):
@@ -54,7 +54,7 @@ def addContainer(self, nwbfile):
5454
"""
5555
Add the test PatchClampSeries as an acquisition and IntracellularElectrode and Device to the given NWBFile
5656
"""
57-
nwbfile.add_ic_electrode(self.elec)
57+
nwbfile.add_icephys_electrode(self.elec)
5858
nwbfile.add_device(self.device)
5959
super().addContainer(nwbfile)
6060

@@ -132,7 +132,7 @@ def addContainer(self, nwbfile):
132132
"""
133133
nwbfile.sweep_table = self.container
134134
nwbfile.add_device(self.device)
135-
nwbfile.add_ic_electrode(self.elec)
135+
nwbfile.add_icephys_electrode(self.elec)
136136
nwbfile.add_acquisition(self.pcs)
137137

138138
def getContainer(self, nwbfile):
@@ -182,7 +182,7 @@ def addContainer(self, nwbfile):
182182
"""
183183
nwbfile.sweep_table = self.container
184184
nwbfile.add_device(self.device)
185-
nwbfile.add_ic_electrode(self.elec)
185+
nwbfile.add_icephys_electrode(self.elec)
186186

187187
nwbfile.add_acquisition(self.pcs1)
188188
nwbfile.add_stimulus_template(self.pcs2a)

tests/unit/test_icephys.py

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,97 @@
44
VoltageClampSeries, VoltageClampStimulusSeries, IntracellularElectrode
55
from pynwb.device import Device
66
from pynwb.testing import TestCase
7+
from pynwb.file import NWBFile # Needed to test icephys functionality defined on NWBFile
8+
from datetime import datetime
9+
from dateutil.tz import tzlocal
710

811

912
def GetElectrode():
1013
device = Device(name='device_name')
11-
elec = IntracellularElectrode('test_iS',
12-
device,
13-
'description',
14-
'slice',
15-
'seal',
16-
'location',
17-
'resistance',
18-
'filtering',
19-
'initial_access_resistance')
14+
elec = IntracellularElectrode(
15+
name='test_iS',
16+
device=device,
17+
description='description',
18+
slice='slice',
19+
seal='seal',
20+
location='location',
21+
resistance='resistance',
22+
filtering='filtering',
23+
initial_access_resistance='initial_access_resistance')
2024
return elec
2125

2226

27+
class NWBFileICEphys(TestCase):
28+
"""Test ICEphys-specific functionality on NWBFile"""
29+
def setUp(self):
30+
self.icephys_electrode = GetElectrode()
31+
32+
def test_ic_electrodes_parameter_deprecation(self):
33+
# Make sure we warn when using the ic_electrodes parameter on NWBFile
34+
msg = "Use of the ic_electrodes parameter is deprecated. Use the icephys_electrodes parameter instead"
35+
with self.assertWarnsWith(DeprecationWarning, msg):
36+
_ = NWBFile(
37+
session_description='NWBFile icephys test',
38+
identifier='NWB123', # required
39+
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()),
40+
ic_electrodes=[self.icephys_electrode, ])
41+
42+
def test_icephys_electrodes_parameter(self):
43+
nwbfile = NWBFile(
44+
session_description='NWBFile icephys test',
45+
identifier='NWB123', # required
46+
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()),
47+
icephys_electrodes=[self.icephys_electrode, ])
48+
self.assertEqual(nwbfile.get_icephys_electrode('test_iS'), self.icephys_electrode)
49+
50+
def test_add_ic_electrode_deprecation(self):
51+
# Make sure we warn when using the add_ic_electrodes parameter on NWBFile
52+
nwbfile = NWBFile(
53+
session_description='NWBFile icephys test',
54+
identifier='NWB123', # required
55+
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()))
56+
57+
msg = "deprecated, use NWBFile.add_icephys_electrode instead"
58+
with self.assertWarnsWith(DeprecationWarning, msg):
59+
nwbfile.add_ic_electrode(self.icephys_electrode)
60+
61+
def test_ic_electrodes_attribute_deprecation(self):
62+
nwbfile = NWBFile(
63+
session_description='NWBFile icephys test',
64+
identifier='NWB123', # required
65+
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()),
66+
icephys_electrodes=[self.icephys_electrode, ])
67+
# make sure NWBFile.ic_electrodes property warns
68+
69+
msg = "deprecated. use NWBFile.icephys_electrodes instead"
70+
with self.assertWarnsWith(DeprecationWarning, msg):
71+
nwbfile.ic_electrodes
72+
73+
# make sure NWBFile.get_ic_electrode warns
74+
msg = "deprecated, use NWBFile.get_icephys_electrode instead"
75+
with self.assertWarnsWith(DeprecationWarning, msg):
76+
nwbfile.get_ic_electrode(self.icephys_electrode.name)
77+
78+
def test_create_ic_electrode_deprecation(self):
79+
nwbfile = NWBFile(
80+
session_description='NWBFile icephys test',
81+
identifier='NWB123', # required
82+
session_start_time=datetime(2017, 4, 3, 11, tzinfo=tzlocal()))
83+
device = Device(name='device_name')
84+
msg = "deprecated, use NWBFile.create_icephys_electrode instead"
85+
with self.assertWarnsWith(DeprecationWarning, msg):
86+
nwbfile.create_ic_electrode(
87+
name='test_iS',
88+
device=device,
89+
description='description',
90+
slice='slice',
91+
seal='seal',
92+
location='location',
93+
resistance='resistance',
94+
filtering='filtering',
95+
initial_access_resistance='initial_access_resistance')
96+
97+
2398
class IntracellularElectrodeConstructor(TestCase):
2499

25100
def test_constructor(self):

0 commit comments

Comments
 (0)