Skip to content

Commit

Permalink
Merge branch 'dev' into conda-release-docs-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bendichter authored Jul 30, 2018
2 parents f88066e + cc1b253 commit 504471e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/gallery/domain/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions docs/gallery/domain/icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/pynwb/device.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 1 addition & 15 deletions src/pynwb/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/pynwb_tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 504471e

Please sign in to comment.