From 038b1863bae56de200298c009c8664d2ca1cb205 Mon Sep 17 00:00:00 2001 From: wbodo <55714242+wbodo@users.noreply.github.com> Date: Wed, 17 Jun 2020 10:19:01 +0200 Subject: [PATCH] User/wbodo/reference electrode information (#455) --- .../extension/electrode_extension_injector.py | 14 +++----- .../extension/fl_electrode_extension.py | 5 ++- .../fl_electrode_extension_builder.py | 5 ++- .../fl_electrode_extension_factory.py | 33 ++++++++----------- .../fl_electrode_extension_manager.py | 13 +++----- .../test_electrodeExtensionInjector.py | 16 +++------ .../test_flElectrodeExtensionManager.py | 3 +- .../res/electrodes_extensions/header.xml | 2 +- 8 files changed, 33 insertions(+), 58 deletions(-) diff --git a/rec_to_nwb/processing/nwb/components/electrodes/extension/electrode_extension_injector.py b/rec_to_nwb/processing/nwb/components/electrodes/extension/electrode_extension_injector.py index 26afedbbb..cf1d88b9f 100644 --- a/rec_to_nwb/processing/nwb/components/electrodes/extension/electrode_extension_injector.py +++ b/rec_to_nwb/processing/nwb/components/electrodes/extension/electrode_extension_injector.py @@ -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) @@ -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 + ) \ No newline at end of file diff --git a/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension.py b/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension.py index 8faf11f8c..424ebcc1f 100644 --- a/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension.py +++ b/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension.py @@ -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 @@ -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 diff --git a/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_builder.py b/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_builder.py index 531131582..b8b6e313b 100644 --- a/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_builder.py +++ b/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_builder.py @@ -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, @@ -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 ) diff --git a/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_factory.py b/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_factory.py index e7bdcbf8a..bfa7ba7e4 100644 --- a/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_factory.py +++ b/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_factory.py @@ -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 diff --git a/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_manager.py b/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_manager.py index a7fc43f62..b209443a0 100644 --- a/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_manager.py +++ b/rec_to_nwb/processing/nwb/components/electrodes/extension/fl_electrode_extension_manager.py @@ -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'], @@ -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( @@ -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 diff --git a/rec_to_nwb/test/processing/electrodes/extension/test_electrodeExtensionInjector.py b/rec_to_nwb/test/processing/electrodes/extension/test_electrodeExtensionInjector.py index 5d0badcad..1749ced97 100644 --- a/rec_to_nwb/test/processing/electrodes/extension/test_electrodeExtensionInjector.py +++ b/rec_to_nwb/test/processing/electrodes/extension/test_electrodeExtensionInjector.py @@ -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( @@ -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): @@ -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( diff --git a/rec_to_nwb/test/processing/electrodes/extension/test_flElectrodeExtensionManager.py b/rec_to_nwb/test/processing/electrodes/extension/test_flElectrodeExtensionManager.py index 166ac6aff..5e1caddb6 100644 --- a/rec_to_nwb/test/processing/electrodes/extension/test_flElectrodeExtensionManager.py +++ b/rec_to_nwb/test/processing/electrodes/extension/test_flElectrodeExtensionManager.py @@ -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): diff --git a/rec_to_nwb/test/processing/res/electrodes_extensions/header.xml b/rec_to_nwb/test/processing/res/electrodes_extensions/header.xml index 1a890d5b3..d3f4a2bfe 100644 --- a/rec_to_nwb/test/processing/res/electrodes_extensions/header.xml +++ b/rec_to_nwb/test/processing/res/electrodes_extensions/header.xml @@ -189,7 +189,7 @@ - +