Skip to content

Commit

Permalink
channel_id (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandercwikla authored May 6, 2020
1 parent 9cd8b61 commit 9800c19
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def inject_extensions(self, nwb_content: NWBFile, fl_electrode_extension: FlElec
fl_electrode_extension.rel_z,
fl_electrode_extension.hw_chan,
fl_electrode_extension.ntrode_id,
fl_electrode_extension.channel_id,
fl_electrode_extension.bad_channels,
fl_electrode_extension.probe_shank,
fl_electrode_extension.probe_channel
Expand All @@ -42,6 +43,11 @@ def __join_extensions_to_electrodes(nwb_content, fl_electrode_extension):
description='None',
data=fl_electrode_extension.ntrode_id
)
nwb_content.electrodes.add_column(
name='channel_id',
description='None',
data=fl_electrode_extension.channel_id
)
nwb_content.electrodes.add_column(
name='bad_channel',
description='None',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class FlElectrodeExtension:

def __init__(self, rel_x, rel_y, rel_z, hw_chan, ntrode_id, bad_channels, probe_shank, probe_channel):
def __init__(self, rel_x, rel_y, rel_z, hw_chan, ntrode_id, channel_id, bad_channels, probe_shank, probe_channel):
self.rel_x = rel_x
self.rel_y = rel_y
self.rel_z = rel_z
self.hw_chan = hw_chan
self.ntrode_id = ntrode_id
self.channel_id = channel_id
self.bad_channels = bad_channels
self.probe_shank = probe_shank
self.probe_channel = probe_channel
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class FlElectrodeExtensionBuilder:

@staticmethod
@beartype
def build(rel_x: list, rel_y: list, rel_z: list, hw_chan: list, ntrode_id: list, bad_channels: list,
probe_shank: list, probe_channel: list):
def build(rel_x: list, rel_y: list, rel_z: list, hw_chan: list, ntrode_id: list, channel_id: list,
bad_channels: list, probe_shank: list, probe_channel: list):
return FlElectrodeExtension(
rel_x=rel_x,
rel_y=rel_y,
rel_z=rel_z,
hw_chan=hw_chan,
ntrode_id=ntrode_id,
channel_id=channel_id,
bad_channels=bad_channels,
probe_shank=probe_shank,
probe_channel=probe_channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def create_ntrode_id(cls, ntrode_metadata):
[ntrode_id.extend([ntrode['ntrode_id']] * len(ntrode['map'])) for ntrode in ntrode_metadata]
return ntrode_id

@classmethod
def create_channel_id(cls, ntrode_metadata):
validate_parameters_not_none(__name__, ntrode_metadata)

channel_id = []
for ntrode in ntrode_metadata:
[channel_id.append(map_index) for map_index in ntrode['map']]
return channel_id

@classmethod
def create_bad_channels(cls, ntrode_metadata):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def get_fl_electrodes_extension(self, electrodes_valid_map: list) -> FlElectrode
ntrode_id = FlElectrodeExtensionFactory.create_ntrode_id(
ntrode_metadata=ntrode_metadata
)
channel_id = FlElectrodeExtensionFactory.create_channel_id(
ntrode_metadata=ntrode_metadata
)
bad_channels = FlElectrodeExtensionFactory.create_bad_channels(
ntrode_metadata=ntrode_metadata
)
Expand All @@ -61,6 +64,7 @@ def get_fl_electrodes_extension(self, electrodes_valid_map: list) -> FlElectrode
rel['rel_z'],
hw_chan,
ntrode_id,
channel_id,
bad_channels,
probe_shank,
probe_channel
Expand All @@ -72,6 +76,7 @@ def get_fl_electrodes_extension(self, electrodes_valid_map: list) -> FlElectrode
rel_z=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, rel['rel_z']),
hw_chan=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, hw_chan),
ntrode_id=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, ntrode_id),
channel_id=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, channel_id),
bad_channels=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, bad_channels),
probe_shank=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, probe_shank),
probe_channel=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, probe_channel),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_electrode_extension_injector_inject_proper_values_successfully(self):
mock_fl_electrode_extension.rel_z = [2, 2, 2, 2]
mock_fl_electrode_extension.hw_chan = [0, 1, 2, 3]
mock_fl_electrode_extension.ntrode_id = [11, 11, 22, 22]
mock_fl_electrode_extension.channel_id = [1, 1, 2, 3]
mock_fl_electrode_extension.bad_channels = [False, False, False, False]
mock_fl_electrode_extension.probe_shank = [0, 0, 1, 2]
mock_fl_electrode_extension.probe_channel = [0, 1, 2, 3]
Expand All @@ -72,15 +73,6 @@ def test_electrode_extension_injector_inject_proper_values_successfully(self):
fl_electrode_extension=mock_fl_electrode_extension
)

self.assertIsInstance(nwb_file.electrodes['rel_x'], VectorData)
self.assertIsInstance(nwb_file.electrodes['rel_y'], VectorData)
self.assertIsInstance(nwb_file.electrodes['rel_z'], VectorData)
self.assertIsInstance(nwb_file.electrodes['ntrode_id'], VectorData)
self.assertIsInstance(nwb_file.electrodes['bad_channel'], VectorData)
self.assertIsInstance(nwb_file.electrodes['hwChan'], VectorData)
self.assertIsInstance(nwb_file.electrodes['probe_shank'], VectorData)
self.assertIsInstance(nwb_file.electrodes['probe_channel'], VectorData)

# header_extension - hw_chan
self.assertIsInstance(nwb_file.electrodes[0, 9], int)
self.assertEqual(nwb_file.electrodes[0, 9], 0)
Expand All @@ -95,47 +87,54 @@ def test_electrode_extension_injector_inject_proper_values_successfully(self):
self.assertEqual(nwb_file.electrodes[2, 10], 22)
self.assertEqual(nwb_file.electrodes[3, 10], 22)

# ntrodes_extension - channel_id
self.assertIsInstance(nwb_file.electrodes[0, 11], int)
self.assertEqual(nwb_file.electrodes[0, 11], 1)
self.assertEqual(nwb_file.electrodes[1, 11], 1)
self.assertEqual(nwb_file.electrodes[2, 11], 2)
self.assertEqual(nwb_file.electrodes[3, 11], 3)

# ntrodes_extension - bad_channels
self.assertIsInstance(nwb_file.electrodes[0, 11], bool)
self.assertEqual(nwb_file.electrodes[0, 11], False)
self.assertEqual(nwb_file.electrodes[1, 11], False)
self.assertEqual(nwb_file.electrodes[2, 11], False)
self.assertEqual(nwb_file.electrodes[3, 11], False)
self.assertIsInstance(nwb_file.electrodes[0, 12], bool)
self.assertEqual(nwb_file.electrodes[0, 12], False)
self.assertEqual(nwb_file.electrodes[1, 12], False)
self.assertEqual(nwb_file.electrodes[2, 12], False)
self.assertEqual(nwb_file.electrodes[3, 12], False)

# metadata_extension - rel_x
self.assertIsInstance(nwb_file.electrodes[0, 12], int)
self.assertEqual(nwb_file.electrodes[0, 12], 0)
self.assertEqual(nwb_file.electrodes[1, 12], 0)
self.assertEqual(nwb_file.electrodes[2, 12], 0)
self.assertEqual(nwb_file.electrodes[3, 12], 0)

# metadata_extension - rel_y
self.assertIsInstance(nwb_file.electrodes[0, 13], int)
self.assertEqual(nwb_file.electrodes[0, 13], 1)
self.assertEqual(nwb_file.electrodes[1, 13], 1)
self.assertEqual(nwb_file.electrodes[2, 13], 1)
self.assertEqual(nwb_file.electrodes[3, 13], 1)
self.assertEqual(nwb_file.electrodes[0, 13], 0)
self.assertEqual(nwb_file.electrodes[1, 13], 0)
self.assertEqual(nwb_file.electrodes[2, 13], 0)
self.assertEqual(nwb_file.electrodes[3, 13], 0)

# metadata_extension - rel_z
# metadata_extension - rel_y
self.assertIsInstance(nwb_file.electrodes[0, 14], int)
self.assertEqual(nwb_file.electrodes[0, 14], 2)
self.assertEqual(nwb_file.electrodes[1, 14], 2)
self.assertEqual(nwb_file.electrodes[2, 14], 2)
self.assertEqual(nwb_file.electrodes[3, 14], 2)
self.assertEqual(nwb_file.electrodes[0, 14], 1)
self.assertEqual(nwb_file.electrodes[1, 14], 1)
self.assertEqual(nwb_file.electrodes[2, 14], 1)
self.assertEqual(nwb_file.electrodes[3, 14], 1)

# metadata_extension - proba_shank
# metadata_extension - rel_z
self.assertIsInstance(nwb_file.electrodes[0, 15], int)
self.assertEqual(nwb_file.electrodes[0, 15], 0)
self.assertEqual(nwb_file.electrodes[1, 15], 0)
self.assertEqual(nwb_file.electrodes[2, 15], 1)
self.assertEqual(nwb_file.electrodes[0, 15], 2)
self.assertEqual(nwb_file.electrodes[1, 15], 2)
self.assertEqual(nwb_file.electrodes[2, 15], 2)
self.assertEqual(nwb_file.electrodes[3, 15], 2)

# metadata_extension - probe_channel
# metadata_extension - proba_shank
self.assertIsInstance(nwb_file.electrodes[0, 16], int)
self.assertEqual(nwb_file.electrodes[0, 16], 0)
self.assertEqual(nwb_file.electrodes[1, 16], 1)
self.assertEqual(nwb_file.electrodes[2, 16], 2)
self.assertEqual(nwb_file.electrodes[3, 16], 3)
self.assertEqual(nwb_file.electrodes[1, 16], 0)
self.assertEqual(nwb_file.electrodes[2, 16], 1)
self.assertEqual(nwb_file.electrodes[3, 16], 2)

# metadata_extension - probe_channel
self.assertIsInstance(nwb_file.electrodes[0, 17], int)
self.assertEqual(nwb_file.electrodes[0, 17], 0)
self.assertEqual(nwb_file.electrodes[1, 17], 1)
self.assertEqual(nwb_file.electrodes[2, 17], 2)
self.assertEqual(nwb_file.electrodes[3, 17], 3)

@should_raise(NoneParamException)
def test_electrodes_extension_injector_failed_injecting_due_to_None_fl_electrode_attr(self):
Expand All @@ -151,6 +150,7 @@ def test_electrodes_extension_injector_failed_injecting_due_to_None_fl_electrode
mock_fl_electrode_extension.rel_z = [2, 2, 2, 2]
mock_fl_electrode_extension.hw_chan = [0, 1, 2, 3]
mock_fl_electrode_extension.ntrode_id = [11, 11, 22, 22]
mock_fl_electrode_extension.channel_id = [1, 2, 3, 3]
mock_fl_electrode_extension.bad_channels = [False, False, False, False]
mock_fl_electrode_extension.probe_shank = None
mock_fl_electrode_extension.probe_channel = [0, 1, 2, 3]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_electrode_extension_manager_get_fl_electrode_extension_successfully(sel
self.assertEqual(fl_electrode_extension.hw_chan[0], 85)
self.assertEqual(fl_electrode_extension.hw_chan[-1], 102)
self.assertEqual(fl_electrode_extension.ntrode_id, [1, 2, 2, 3, 4])
self.assertEqual(fl_electrode_extension.channel_id, [1, 1, 2, 2, 1])
self.assertEqual(fl_electrode_extension.probe_shank, [0, 0, 0, 2, 3])
self.assertEqual(fl_electrode_extension.bad_channels, [False, False, False, False, False])
self.assertEqual(fl_electrode_extension.probe_channel, [1, 33, 34, 66, 97])
Expand Down

0 comments on commit 9800c19

Please sign in to comment.