diff --git a/docs/gallery/domain/ecephys.py b/docs/gallery/domain/ecephys.py index d0f231fcd..7a114e3f2 100644 --- a/docs/gallery/domain/ecephys.py +++ b/docs/gallery/domain/ecephys.py @@ -45,7 +45,7 @@ device = nwbfile.create_device(name='trodes_rig123', source="a source") ####################### -# Once you have created the :py:class:`~pynwb.ecephys.Device`, you can create an +# Once you have created the :py:class:`~pynwb.device.Device`, you can create an # :py:class:`~pynwb.ecephys.ElectrodeGroup`. electrode_name = 'tetrode1' diff --git a/docs/gallery/domain/icephys.py b/docs/gallery/domain/icephys.py index 4f66675ed..6c548e6ae 100644 --- a/docs/gallery/domain/icephys.py +++ b/docs/gallery/domain/icephys.py @@ -31,8 +31,8 @@ # Device metadata # ^^^^^^^^^^^^^^^ # -# Device metadata is represented by :py:class:`~pynwb.ecephys.Device` objects. -# To create a device, you can use the :py:class:`~pynwb.ecephys.Device` instance method +# Device metadata is represented by :py:class:`~pynwb.device.Device` objects. +# To create a device, you can use the :py:class:`~pynwb.device.Device` instance method # :py:meth:`~pynwb.file.NWBFile.create_device`. device = nwbfile.create_device(name='Heka ITC-1600', source='a source') @@ -74,6 +74,7 @@ nwbfile.add_stimulus(ccss) +####################### # Here, we will use :py:class:`~pynwb.icephys.VoltageClampSeries` to store voltage clamp # data and then add it to our NWBFile as acquired data using the :py:class:`~pynwb.file.NWBFile` method # :py:meth:`~pynwb.file.NWBFile.add_acquisition`. @@ -124,6 +125,7 @@ ccss = nwbfile.get_stimulus('ccss') +#################### # Grabbing acquisition data an be done via :py:meth:`~pynwb.file.NWBFile.get_acquisition` vcs = nwbfile.get_acquisition('vcs') diff --git a/src/pynwb/__init__.py b/src/pynwb/__init__.py index dc3b26a58..820aee91a 100644 --- a/src/pynwb/__init__.py +++ b/src/pynwb/__init__.py @@ -232,6 +232,7 @@ def __init__(self, **kwargs): from .file import NWBFile # noqa: E402, F401 from . import behavior # noqa: F401,E402 +from . import device # noqa: F401,E402 from . import ecephys # noqa: F401,E402 from . import epoch # noqa: F401,E402 from . import icephys # noqa: F401,E402 diff --git a/src/pynwb/device.py b/src/pynwb/device.py new file mode 100644 index 000000000..04f6b60af --- /dev/null +++ b/src/pynwb/device.py @@ -0,0 +1,18 @@ +from .form.utils import docval, call_docval_func +from . import register_class, CORE_NAMESPACE +from .core import NWBContainer + + +@register_class('Device', CORE_NAMESPACE) +class Device(NWBContainer): + """ + """ + + __nwbfields__ = ('name',) + + @docval({'name': 'name', 'type': str, 'doc': 'the name of this device'}, + {'name': 'source', 'type': str, 'doc': 'the source of the data'}, + {'name': 'parent', 'type': 'NWBContainer', + 'doc': 'The parent NWBContainer for this NWBContainer', 'default': None}) + def __init__(self, **kwargs): + call_docval_func(super(Device, self).__init__, kwargs) diff --git a/src/pynwb/ecephys.py b/src/pynwb/ecephys.py index 46bfe7060..3c1b06014 100644 --- a/src/pynwb/ecephys.py +++ b/src/pynwb/ecephys.py @@ -8,21 +8,7 @@ from . import register_class, CORE_NAMESPACE from .base import TimeSeries, _default_resolution, _default_conversion from .core import NWBContainer, NWBTable, NWBTableRegion, NWBDataInterface, MultiContainerInterface - - -@register_class('Device', CORE_NAMESPACE) -class Device(NWBContainer): - """ - """ - - __nwbfields__ = ('name',) - - @docval({'name': 'name', 'type': str, 'doc': 'the name of this device'}, - {'name': 'source', 'type': str, 'doc': 'the source of the data'}, - {'name': 'parent', 'type': 'NWBContainer', - 'doc': 'The parent NWBContainer for this NWBContainer', 'default': None}) - def __init__(self, **kwargs): - call_docval_func(super(Device, self).__init__, kwargs) +from .device import Device @register_class('ElectrodeGroup', CORE_NAMESPACE) diff --git a/src/pynwb/file.py b/src/pynwb/file.py index 564820caf..4ba75632e 100644 --- a/src/pynwb/file.py +++ b/src/pynwb/file.py @@ -341,6 +341,11 @@ def create_electrode_table_region(self, **kwargs): msg = "no electrodes available. add electrodes before creating a region" raise RuntimeError(msg) region = getargs('region', kwargs) + for idx in region: + if idx < 0 or idx >= len(self.ec_electrodes): + raise IndexError('The index ' + str(idx) + + ' is out of range for the ElectrodeTable of length ' + + str(len(self.ec_electrodes))) desc = getargs('description', kwargs) name = getargs('name', kwargs) return ElectrodeTableRegion(self.ec_electrodes, region, desc, name) diff --git a/tests/unit/pynwb_tests/test_file.py b/tests/unit/pynwb_tests/test_file.py index e80e16036..8f94f10df 100644 --- a/tests/unit/pynwb_tests/test_file.py +++ b/tests/unit/pynwb_tests/test_file.py @@ -60,6 +60,21 @@ def test_create_electrode_group(self): self.assertEqual(elecgrp.location, loc) self.assertIs(elecgrp.device, d) + def test_create_electrode_group_invalid_index(self): + """ + Test the case where the user creates an electrode table region with + indexes that are out of range of the amount of electrodes added. + """ + nwbfile = NWBFile('a', 'b', 'c', datetime.now()) + device = nwbfile.create_device('a', 'b') + elecgrp = nwbfile.create_electrode_group('a', 'b', 'c', device=device, location='a') + for i in range(4): + nwbfile.add_electrode(i, np.nan, np.nan, np.nan, np.nan, group=elecgrp, + location='a', filtering='a', description='a') + with self.assertRaises(IndexError) as err: + nwbfile.create_electrode_table_region(list(range(6)), 'test') + self.assertTrue('out of range' in str(err.exception)) + def test_epoch_tags(self): tags1 = ['t1', 't2'] tags2 = ['t3', 't4']