Skip to content

Commit 504471e

Browse files
authored
Merge branch 'dev' into conda-release-docs-improvements
2 parents f88066e + cc1b253 commit 504471e

File tree

7 files changed

+45
-18
lines changed

7 files changed

+45
-18
lines changed

docs/gallery/domain/ecephys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
device = nwbfile.create_device(name='trodes_rig123', source="a source")
4646

4747
#######################
48-
# Once you have created the :py:class:`~pynwb.ecephys.Device`, you can create an
48+
# Once you have created the :py:class:`~pynwb.device.Device`, you can create an
4949
# :py:class:`~pynwb.ecephys.ElectrodeGroup`.
5050

5151
electrode_name = 'tetrode1'

docs/gallery/domain/icephys.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
# Device metadata
3232
# ^^^^^^^^^^^^^^^
3333
#
34-
# Device metadata is represented by :py:class:`~pynwb.ecephys.Device` objects.
35-
# To create a device, you can use the :py:class:`~pynwb.ecephys.Device` instance method
34+
# Device metadata is represented by :py:class:`~pynwb.device.Device` objects.
35+
# To create a device, you can use the :py:class:`~pynwb.device.Device` instance method
3636
# :py:meth:`~pynwb.file.NWBFile.create_device`.
3737

3838
device = nwbfile.create_device(name='Heka ITC-1600', source='a source')
@@ -74,6 +74,7 @@
7474

7575
nwbfile.add_stimulus(ccss)
7676

77+
#######################
7778
# Here, we will use :py:class:`~pynwb.icephys.VoltageClampSeries` to store voltage clamp
7879
# data and then add it to our NWBFile as acquired data using the :py:class:`~pynwb.file.NWBFile` method
7980
# :py:meth:`~pynwb.file.NWBFile.add_acquisition`.
@@ -124,6 +125,7 @@
124125

125126
ccss = nwbfile.get_stimulus('ccss')
126127

128+
####################
127129
# Grabbing acquisition data an be done via :py:meth:`~pynwb.file.NWBFile.get_acquisition`
128130

129131
vcs = nwbfile.get_acquisition('vcs')

src/pynwb/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def __init__(self, **kwargs):
232232
from .file import NWBFile # noqa: E402, F401
233233

234234
from . import behavior # noqa: F401,E402
235+
from . import device # noqa: F401,E402
235236
from . import ecephys # noqa: F401,E402
236237
from . import epoch # noqa: F401,E402
237238
from . import icephys # noqa: F401,E402

src/pynwb/device.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from .form.utils import docval, call_docval_func
2+
from . import register_class, CORE_NAMESPACE
3+
from .core import NWBContainer
4+
5+
6+
@register_class('Device', CORE_NAMESPACE)
7+
class Device(NWBContainer):
8+
"""
9+
"""
10+
11+
__nwbfields__ = ('name',)
12+
13+
@docval({'name': 'name', 'type': str, 'doc': 'the name of this device'},
14+
{'name': 'source', 'type': str, 'doc': 'the source of the data'},
15+
{'name': 'parent', 'type': 'NWBContainer',
16+
'doc': 'The parent NWBContainer for this NWBContainer', 'default': None})
17+
def __init__(self, **kwargs):
18+
call_docval_func(super(Device, self).__init__, kwargs)

src/pynwb/ecephys.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,7 @@
88
from . import register_class, CORE_NAMESPACE
99
from .base import TimeSeries, _default_resolution, _default_conversion
1010
from .core import NWBContainer, NWBTable, NWBTableRegion, NWBDataInterface, MultiContainerInterface
11-
12-
13-
@register_class('Device', CORE_NAMESPACE)
14-
class Device(NWBContainer):
15-
"""
16-
"""
17-
18-
__nwbfields__ = ('name',)
19-
20-
@docval({'name': 'name', 'type': str, 'doc': 'the name of this device'},
21-
{'name': 'source', 'type': str, 'doc': 'the source of the data'},
22-
{'name': 'parent', 'type': 'NWBContainer',
23-
'doc': 'The parent NWBContainer for this NWBContainer', 'default': None})
24-
def __init__(self, **kwargs):
25-
call_docval_func(super(Device, self).__init__, kwargs)
11+
from .device import Device
2612

2713

2814
@register_class('ElectrodeGroup', CORE_NAMESPACE)

src/pynwb/file.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ def create_electrode_table_region(self, **kwargs):
341341
msg = "no electrodes available. add electrodes before creating a region"
342342
raise RuntimeError(msg)
343343
region = getargs('region', kwargs)
344+
for idx in region:
345+
if idx < 0 or idx >= len(self.ec_electrodes):
346+
raise IndexError('The index ' + str(idx) +
347+
' is out of range for the ElectrodeTable of length '
348+
+ str(len(self.ec_electrodes)))
344349
desc = getargs('description', kwargs)
345350
name = getargs('name', kwargs)
346351
return ElectrodeTableRegion(self.ec_electrodes, region, desc, name)

tests/unit/pynwb_tests/test_file.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ def test_create_electrode_group(self):
6060
self.assertEqual(elecgrp.location, loc)
6161
self.assertIs(elecgrp.device, d)
6262

63+
def test_create_electrode_group_invalid_index(self):
64+
"""
65+
Test the case where the user creates an electrode table region with
66+
indexes that are out of range of the amount of electrodes added.
67+
"""
68+
nwbfile = NWBFile('a', 'b', 'c', datetime.now())
69+
device = nwbfile.create_device('a', 'b')
70+
elecgrp = nwbfile.create_electrode_group('a', 'b', 'c', device=device, location='a')
71+
for i in range(4):
72+
nwbfile.add_electrode(i, np.nan, np.nan, np.nan, np.nan, group=elecgrp,
73+
location='a', filtering='a', description='a')
74+
with self.assertRaises(IndexError) as err:
75+
nwbfile.create_electrode_table_region(list(range(6)), 'test')
76+
self.assertTrue('out of range' in str(err.exception))
77+
6378
def test_epoch_tags(self):
6479
tags1 = ['t1', 't2']
6580
tags2 = ['t3', 't4']

0 commit comments

Comments
 (0)