Skip to content

Commit e1b5f40

Browse files
Merge pull request #42 from NovelaNeuro/user/acwikla/data_acq_device
User/acwikla/data acq device
2 parents 455e7cc + 74a120e commit e1b5f40

File tree

9 files changed

+158
-3
lines changed

9 files changed

+158
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,12 @@ Representation of Probe object in NWB <br>
6060
**contact_size** `float`: value of contact size as float <br>
6161
**shanks** `object`: shanks in the probe <br>
6262

63+
#### DataAcqDevice
64+
Representation of DataAcqDevice object in NWB <br>
65+
**Attributes:** <br>
66+
**system** `string`: system of device <br>
67+
**amplifier** `string`: amplifier (default: '') <br>
68+
**adc_circuit** `string`: adc_circuit (default: '') <br>
69+
70+
6371
This extension was created using [ndx-template](https://github.com/nwb-extensions/ndx-template).

spec/ndx-franklab-novela.extensions.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ groups:
5252
- neurodata_type_inc: Shank
5353
doc: shank in the probe
5454
quantity: '*'
55+
- neurodata_type_def: DataAcqDevice
56+
neurodata_type_inc: Device
57+
doc: A custom Device interface
58+
attributes:
59+
- name: system
60+
dtype: text
61+
doc: system of device
62+
- name: amplifier
63+
dtype: text
64+
doc: amplifier
65+
- name: adc_circuit
66+
dtype: text
67+
doc: adc_circuit
5568
- neurodata_type_def: HeaderDevice
5669
neurodata_type_inc: Device
5770
doc: metadata from global configuration from header

spec/ndx-franklab-novela.namespace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ namespaces:
1212
- Device
1313
- NWBDataInterface
1414
- source: ndx-franklab-novela.extensions.yaml
15-
version: 0.0.004
15+
version: 0.0.005
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from hdmf import docval
2+
from hdmf.utils import get_docval, call_docval_func
3+
from pynwb import register_class
4+
from pynwb.device import Device
5+
6+
7+
@register_class('DataAcqDevice', 'ndx-franklab-novela')
8+
class DataAcqDevice(Device):
9+
''' Representation of Probe object in NWB '''
10+
11+
@docval(*get_docval(Device.__init__) + (
12+
{'name': 'system', 'type': 'str', 'doc': 'system of device'},
13+
{'name': 'amplifier', 'type': 'str', 'doc': 'amplifier', 'default': ''},
14+
{'name': 'adc_circuit', 'type': 'str', 'doc': 'adc_circuit', 'default': ''},
15+
))
16+
def __init__(self, **kwargs):
17+
super().__init__(**{kwargs_item: kwargs[kwargs_item]
18+
for kwargs_item in kwargs.copy()
19+
if kwargs_item != 'system'
20+
if kwargs_item != 'amplifier'
21+
if kwargs_item != 'adc_circuit'
22+
})
23+
call_docval_func(super(DataAcqDevice, self).__init__, kwargs)
24+
self.system = kwargs['system']
25+
self.amplifier = kwargs['amplifier']
26+
self.adc_circuit = kwargs['adc_circuit']
27+
28+
__nwbfields__ = ('system', 'amplifier', 'adc_circuit')

src/pynwb/ndx_franklab_novela/spec/ndx-franklab-novela.extensions.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ groups:
5252
- neurodata_type_inc: Shank
5353
doc: shank in the probe
5454
quantity: '*'
55+
- neurodata_type_def: DataAcqDevice
56+
neurodata_type_inc: Device
57+
doc: A custom Device interface
58+
attributes:
59+
- name: system
60+
dtype: text
61+
doc: system of device
62+
- name: amplifier
63+
dtype: text
64+
doc: amplifier
65+
- name: adc_circuit
66+
dtype: text
67+
doc: adc_circuit
5568
- neurodata_type_def: HeaderDevice
5669
neurodata_type_inc: Device
5770
doc: metadata from global configuration from header

src/pynwb/ndx_franklab_novela/spec/ndx-franklab-novela.namespace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ namespaces:
1212
- Device
1313
- NWBDataInterface
1414
- source: ndx-franklab-novela.extensions.yaml
15-
version: 0.0.004
15+
version: 0.0.005
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import unittest
2+
3+
from src.pynwb.ndx_franklab_novela.data_acq_device import DataAcqDevice
4+
5+
6+
class TestDataAcqDevice(unittest.TestCase):
7+
8+
def test_data_acq_device_successfully_created_with_optional_data(self):
9+
10+
data_acq_device = DataAcqDevice(
11+
name='DataAcqDevice1',
12+
system='System1',
13+
amplifier='Amplifier1',
14+
adc_circuit='adc_circuit1',
15+
)
16+
17+
self.assertIsInstance(data_acq_device, DataAcqDevice)
18+
19+
self.assertIsInstance(data_acq_device.name, str)
20+
self.assertIsInstance(data_acq_device.system, str)
21+
self.assertIsInstance(data_acq_device.amplifier, str)
22+
self.assertIsInstance(data_acq_device.adc_circuit, str)
23+
24+
self.assertEqual(data_acq_device.name, 'DataAcqDevice1')
25+
self.assertEqual(data_acq_device.system, 'System1')
26+
self.assertEqual(data_acq_device.amplifier, 'Amplifier1')
27+
self.assertEqual(data_acq_device.adc_circuit, 'adc_circuit1')
28+
29+
def test_data_acq_device_successfully_created_without_optional_data(self):
30+
31+
data_acq_device = DataAcqDevice(
32+
name='DataAcqDevice1',
33+
system='System1'
34+
)
35+
36+
self.assertIsInstance(data_acq_device, DataAcqDevice)
37+
38+
self.assertIsInstance(data_acq_device.name, str)
39+
self.assertIsInstance(data_acq_device.system, str)
40+
self.assertIsInstance(data_acq_device.amplifier, str)
41+
self.assertIsInstance(data_acq_device.adc_circuit, str)
42+
43+
self.assertEqual(data_acq_device.name, 'DataAcqDevice1')
44+
self.assertEqual(data_acq_device.system, 'System1')
45+
self.assertEqual(data_acq_device.amplifier, '')
46+
self.assertEqual(data_acq_device.adc_circuit, '')
47+

src/pynwb/tests/test_read_nwb.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pynwb.device import Device
1010
from pynwb.testing import TestCase
1111

12+
from src.pynwb.ndx_franklab_novela.data_acq_device import DataAcqDevice
1213
from src.pynwb.ndx_franklab_novela.header_device import HeaderDevice
1314
from src.pynwb.ndx_franklab_novela.nwb_electrode_group import NwbElectrodeGroup
1415
from src.pynwb.ndx_franklab_novela.probe import Probe, Shank, ShanksElectrode
@@ -95,6 +96,26 @@ def test_read_nwb_probe_successfully(self):
9596

9697
self.delete_nwb('probe')
9798

99+
def test_read_nwb_data_acq_device_successfully(self):
100+
data_acq_device = DataAcqDevice(
101+
name='DataAcqDevice1',
102+
system='System1',
103+
amplifier='Amplifier1',
104+
adc_circuit='adc_circuit1'
105+
)
106+
self.nwb_file_content.add_device(data_acq_device)
107+
108+
nwb_file_handler = NWBHDF5IO('data_acq_device.nwb', mode='w')
109+
nwb_file_handler.write(self.nwb_file_content)
110+
nwb_file_handler.close()
111+
112+
self.assertTrue(os.path.exists('data_acq_device.nwb'))
113+
with pynwb.NWBHDF5IO('data_acq_device.nwb', 'r', load_namespaces=True) as nwb_file_handler:
114+
nwb_file = nwb_file_handler.read()
115+
self.assertContainerEqual(nwb_file.devices['DataAcqDevice1'], data_acq_device)
116+
117+
self.delete_nwb('data_acq_device')
118+
98119
def test_read_nwb_nwb_electrode_group_successfully(self):
99120
device = Device('device_0')
100121
self.nwb_file_content.add_device(device)

src/spec/create_extension_spec.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ def main():
118118
]
119119
)
120120

121+
data_acq_device = NWBGroupSpec(
122+
doc='A custom Device interface',
123+
neurodata_type_def='DataAcqDevice',
124+
neurodata_type_inc='Device',
125+
attributes=[
126+
NWBAttributeSpec(
127+
name='system',
128+
doc='system of device',
129+
dtype='text'
130+
),
131+
NWBAttributeSpec(
132+
name='amplifier',
133+
doc='amplifier',
134+
dtype='text'
135+
),
136+
NWBAttributeSpec(
137+
name='adc_circuit',
138+
doc='adc_circuit',
139+
dtype='text'
140+
),
141+
]
142+
)
143+
121144
associated_files = NWBGroupSpec(
122145
neurodata_type_def='AssociatedFiles',
123146
neurodata_type_inc='NWBDataInterface',
@@ -277,7 +300,9 @@ def main():
277300
]
278301
)
279302

280-
new_data_types = [shanks_electrode, shanks, probe, header_device, associated_files, nwb_electrode_group]
303+
new_data_types = [
304+
shanks_electrode, shanks, probe, data_acq_device, header_device, associated_files, nwb_electrode_group
305+
]
281306

282307
# export the spec to yaml files in the spec folder
283308
output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'spec'))

0 commit comments

Comments
 (0)