Skip to content

Commit

Permalink
User/wbodo/reference electrode information (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
wbodo authored Jun 17, 2020
1 parent eeba483 commit 038b186
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def inject_extensions(self, nwb_content: NWBFile, fl_electrode_extension: FlElec
fl_electrode_extension.bad_channels,
fl_electrode_extension.probe_shank,
fl_electrode_extension.probe_electrode,
fl_electrode_extension.ref_n_trode_id,
fl_electrode_extension.ref_chan
fl_electrode_extension.ref_elect_id
)
self.__join_extensions_to_electrodes(nwb_content, fl_electrode_extension)

Expand Down Expand Up @@ -81,12 +80,7 @@ def __join_extensions_to_electrodes(nwb_content, fl_electrode_extension):
data=fl_electrode_extension.probe_electrode
)
nwb_content.electrodes.add_column(
name='ref_n_trode_id',
name='ref_elect_id',
description='None',
data=fl_electrode_extension.ref_n_trode_id
)
nwb_content.electrodes.add_column(
name='ref_chan',
description='None',
data=fl_electrode_extension.ref_chan
)
data=fl_electrode_extension.ref_elect_id
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class FlElectrodeExtension:

def __init__(self, rel_x, rel_y, rel_z, hw_chan, ntrode_id, channel_id, bad_channels, probe_shank, probe_electrode,
ref_n_trode_id, ref_chan):
ref_elect_id):
self.rel_x = rel_x
self.rel_y = rel_y
self.rel_z = rel_z
Expand All @@ -11,5 +11,4 @@ def __init__(self, rel_x, rel_y, rel_z, hw_chan, ntrode_id, channel_id, bad_chan
self.bad_channels = bad_channels
self.probe_shank = probe_shank
self.probe_electrode = probe_electrode
self.ref_n_trode_id = ref_n_trode_id
self.ref_chan = ref_chan
self.ref_elect_id = ref_elect_id
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class FlElectrodeExtensionBuilder:
@staticmethod
@beartype
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_electrode: list, ref_n_trode_id: list, ref_chan: list
bad_channels: list, probe_shank: list, probe_electrode: list, ref_elect_id: list
) -> FlElectrodeExtension:
return FlElectrodeExtension(
rel_x=rel_x,
Expand All @@ -19,6 +19,5 @@ def build(rel_x: list, rel_y: list, rel_z: list, hw_chan: list, ntrode_id: list,
bad_channels=bad_channels,
probe_shank=probe_shank,
probe_electrode=probe_electrode,
ref_n_trode_id=ref_n_trode_id,
ref_chan=ref_chan
ref_elect_id=ref_elect_id
)
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,18 @@ def create_probe_electrode(cls, probes_metadata: list, electrode_groups_metadata
return probe_electrode

@classmethod
def create_ref_n_trode_id(cls, spike_n_trodes: list):
ref_n_trode_id = []
[
ref_n_trode_id.extend(
[int(spike_n_trode.ref_n_trode_id)] * len(spike_n_trode.spike_channels)
)
for spike_n_trode in spike_n_trodes
]
return ref_n_trode_id
def create_ref_elect_id(cls, spike_n_trodes: list, ntrode_metadata: dict):
ref_elect_id = []
for spike_n_trode in spike_n_trodes:
if not int(spike_n_trode.ref_n_trode_id) == 0:
for ntrode in ntrode_metadata:
if ntrode["ntrode_id"] == int(spike_n_trode.ref_n_trode_id):
ref_elect_id.extend(
[ntrode["map"][int(spike_n_trode.ref_chan)]]
* len(spike_n_trode.spike_channels)
)
else:
ref_elect_id.extend([-1] * len(spike_n_trode.spike_channels))
return ref_elect_id


@classmethod
def create_ref_chan(cls, spike_n_trodes: list):
ref_chan = []
[
ref_chan.extend(
[int(spike_n_trode.ref_chan)] * len(spike_n_trode.spike_channels)
)
for spike_n_trode in spike_n_trodes
]
return ref_chan
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ def get_fl_electrodes_extension(self, electrodes_valid_map: list) -> FlElectrode
probes_metadata=probes_metadata,
electrode_groups_metadata=electrode_groups_metadata
)
ref_n_trode_id = FlElectrodeExtensionFactory.create_ref_n_trode_id(
spike_n_trodes=spike_n_trodes,
)
ref_chan = FlElectrodeExtensionFactory.create_ref_chan(
ref_elect_id = FlElectrodeExtensionFactory.create_ref_elect_id(
spike_n_trodes=spike_n_trodes,
ntrode_metadata=ntrode_metadata
)


self.__validate_extension_length(
electrodes_valid_map,
rel['rel_x'],
Expand All @@ -74,8 +73,7 @@ def get_fl_electrodes_extension(self, electrodes_valid_map: list) -> FlElectrode
bad_channels,
probe_shank,
probe_electrode,
ref_n_trode_id,
ref_chan
ref_elect_id
)

return FlElectrodeExtensionBuilder.build(
Expand All @@ -88,8 +86,7 @@ def get_fl_electrodes_extension(self, electrodes_valid_map: list) -> FlElectrode
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_electrode=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, probe_electrode),
ref_n_trode_id=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, ref_n_trode_id),
ref_chan=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, ref_chan),
ref_elect_id=self.__filter_extension_list_with_electrodes_valid_map(electrodes_valid_map, ref_elect_id),
)

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def test_electrode_extension_injector_inject_proper_values_successfully(self):
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_electrode = [0, 1, 2, 3]
mock_fl_electrode_extension.ref_n_trode_id = [0, 1, 2, 2]
mock_fl_electrode_extension.ref_chan = [0, 1, 2, 3]
mock_fl_electrode_extension.ref_elect_id = [0, 1, 2, 3]

electrode_extension_injector = ElectrodeExtensionInjector()
electrode_extension_injector.inject_extensions(
Expand Down Expand Up @@ -132,19 +131,13 @@ def test_electrode_extension_injector_inject_proper_values_successfully(self):
self.assertEqual(nwb_file.electrodes[2, 17], 2)
self.assertEqual(nwb_file.electrodes[3, 17], 3)

# metadata_extension - ref_n_trode_id
# metadata_extension - ref_elect_id
self.assertIsInstance(nwb_file.electrodes[0, 18], int)
self.assertEqual(nwb_file.electrodes[0, 18], 0)
self.assertEqual(nwb_file.electrodes[1, 18], 1)
self.assertEqual(nwb_file.electrodes[2, 18], 2)
self.assertEqual(nwb_file.electrodes[3, 18], 2)
self.assertEqual(nwb_file.electrodes[3, 18], 3)

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

@should_raise(NoneParamException)
def test_electrodes_extension_injector_failed_injecting_due_to_None_fl_electrode_attr(self):
Expand All @@ -164,8 +157,7 @@ def test_electrodes_extension_injector_failed_injecting_due_to_None_fl_electrode
mock_fl_electrode_extension.bad_channels = [False, False, False, False]
mock_fl_electrode_extension.probe_shank = None
mock_fl_electrode_extension.probe_electrode = [0, 1, 2, 3]
mock_fl_electrode_extension.ref_n_trode_id = [0, 1, 2, 2]
mock_fl_electrode_extension.ref_chan = [0, 1, 2, 3]
mock_fl_electrode_extension.ref_elect_id = [0, 1, 2, 3]

electrode_extension_injector = ElectrodeExtensionInjector()
electrode_extension_injector.inject_extensions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def test_electrode_extension_manager_get_fl_electrode_extension_successfully(sel
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_electrode, [1, 0, 1, 64, 96])
self.assertEqual(fl_electrode_extension.ref_n_trode_id, [0, 1, 1, 1, 1])
self.assertEqual(fl_electrode_extension.ref_chan, [1, 2, 2, 3, 3])
self.assertEqual(fl_electrode_extension.ref_elect_id, [-1, 2, 2, 34, 34])

@should_raise(NotCompatibleMetadata)
def test_electrode_extension_manager_failed_due_to_not_equal_extensions_length(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
<SpikeChannel maxDisp="225" triggerOn="1" hwChan="72" thresh="10"/>
<SpikeChannel maxDisp="225" triggerOn="1" hwChan="76" thresh="10"/>
</SpikeNTrode>
<SpikeNTrode filterOn="1" lowFilter="300" lfpRefOn="0" color="#24c600" highFilter="6000" lfpFilterOn="1" moduleDataOn="0" LFPHighFilter="400" refGroup="0" LFPChan="1" refNTrodeID="1" refChan="3" groupRefOn="0" refOn="0" id="3">
<SpikeNTrode filterOn="1" lowFilter="300" lfpRefOn="0" color="#24c600" highFilter="6000" lfpFilterOn="1" moduleDataOn="0" LFPHighFilter="400" refGroup="0" LFPChan="1" refNTrodeID="2" refChan="2" groupRefOn="0" refOn="0" id="3">
<SpikeChannel maxDisp="225" triggerOn="1" hwChan="98" thresh="10"/>
<SpikeChannel maxDisp="225" triggerOn="1" hwChan="99" thresh="10"/>
<SpikeChannel maxDisp="225" triggerOn="1" hwChan="102" thresh="10"/>
Expand Down

0 comments on commit 038b186

Please sign in to comment.