From 64ad906e7a78d7b7b8fc4a47488c918edae07647 Mon Sep 17 00:00:00 2001 From: mavaylon1 Date: Tue, 1 Oct 2024 16:48:19 -0700 Subject: [PATCH] draft complete --- src/pynwb/ecephys.py | 31 ++++++++++++++++---------- src/pynwb/io/file.py | 8 +++---- src/pynwb/testing/mock/ecephys.py | 8 +++---- tests/integration/hdf5/test_nwbfile.py | 1 + tests/unit/test_ecephys.py | 2 +- tests/unit/test_file.py | 2 +- tests/unit/test_mock.py | 5 ++--- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/pynwb/ecephys.py b/src/pynwb/ecephys.py index 146117d53..dbe1c17e3 100644 --- a/src/pynwb/ecephys.py +++ b/src/pynwb/ecephys.py @@ -43,17 +43,17 @@ class ElectrodesTable(DynamicTable): __columns__ = ( {'name': 'location', 'description': 'TODO', 'required': True}, - {'name': 'group', 'description': 'TODO', 'required': True}) - - @docval({'name': 'group_name', 'type': VectorData, 'doc':'TODO', 'default': None}, - {'name': 'x', 'type': float, 'doc':'TODO', 'default': None}, - {'name': 'y', 'type': float, 'doc':'TODO', 'default': None}, - {'name': 'z', 'type': float, 'doc':'TODO', 'default': None}, - {'name': 'imp', 'type': float, 'doc':'TODO', 'default': None}, - {'name': 'filtering', 'type': str, 'doc':'TODO', 'default': None}, - {'name': 'rel_x', 'type': float, 'doc':'TODO', 'default': None}, - {'name': 'rel_y', 'type': float, 'doc':'TODO', 'default': None}, - {'name': 'rel_z', 'type': float, 'doc':'TODO', 'default': None}, + {'name': 'group', 'description': 'TODO', 'required': True}, + {'name': 'group_name', 'description': 'TODO', 'required': False }) + + @docval({'name': 'x', 'type': VectorData, 'doc':'TODO', 'default': None}, + {'name': 'y', 'type': VectorData, 'doc':'TODO', 'default': None}, + {'name': 'z', 'type': VectorData, 'doc':'TODO', 'default': None}, + {'name': 'imp', 'type': VectorData, 'doc':'TODO', 'default': None}, + {'name': 'filtering', 'type': VectorData, 'doc':'TODO', 'default': None}, + {'name': 'rel_x', 'type': VectorData, 'doc':'TODO', 'default': None}, + {'name': 'rel_y', 'type': VectorData, 'doc':'TODO', 'default': None}, + {'name': 'rel_z', 'type': VectorData, 'doc':'TODO', 'default': None}, {'name': 'reference', 'type': VectorData, 'doc':'TODO', 'default': None}, *get_docval(DynamicTable.__init__, 'id', 'columns', 'colnames')) def __init__(self, **kwargs): @@ -62,7 +62,6 @@ def __init__(self, **kwargs): # optional fields keys_to_set = ( - 'group_name', 'x', 'y', 'z', @@ -78,6 +77,14 @@ def __init__(self, **kwargs): super().__init__(**kwargs) + def copy(self): + """ + Return a copy of this DynamicTable. + This is useful for linking. + """ + kwargs = dict(id=self.id, columns=self.columns, colnames=self.colnames) + return self.__class__(**kwargs) + @register_class('ElectricalSeries', CORE_NAMESPACE) class ElectricalSeries(TimeSeries): diff --git a/src/pynwb/io/file.py b/src/pynwb/io/file.py index 81f9bc73b..3189e697f 100644 --- a/src/pynwb/io/file.py +++ b/src/pynwb/io/file.py @@ -182,15 +182,15 @@ def scratch(self, builder, manager): @ObjectMapper.constructor_arg('electrodes') def electrodes(self, builder, manager): - electrodes_builder = builder['general']['extracellular_ephys']['electrodes'] - + try: + electrodes_builder = builder['general']['extracellular_ephys']['electrodes'] + except KeyError: + electrodes_builder = None if (electrodes_builder is not None and electrodes_builder.attributes['neurodata_type'] != 'ElectrodesTable'): electrodes_builder.attributes['neurodata_type'] = 'ElectrodesTable' electrodes_builder.attributes['namespace'] = 'core' new_container = manager.construct(electrodes_builder, True) - # mapper = manager.get_map(electrodes_builder) - breakpoint() return new_container else: return None diff --git a/src/pynwb/testing/mock/ecephys.py b/src/pynwb/testing/mock/ecephys.py index 260c4a663..fd634fb38 100644 --- a/src/pynwb/testing/mock/ecephys.py +++ b/src/pynwb/testing/mock/ecephys.py @@ -35,10 +35,10 @@ def mock_ElectrodeGroup( return electrode_group -def mock_ElectrodeTable( +def mock_ElectrodesTable( n_rows: int = 5, group: Optional[ElectrodeGroup] = None, nwbfile: Optional[NWBFile] = None ) -> DynamicTable: - electrodes_table = ElectrodeTable() + electrodes_table = ElectrodesTable() group = group if group is not None else mock_ElectrodeGroup(nwbfile=nwbfile) for i in range(n_rows): electrodes_table.add_row( @@ -57,7 +57,7 @@ def mock_electrodes( n_electrodes: int = 5, table: Optional[DynamicTable] = None, nwbfile: Optional[NWBFile] = None ) -> DynamicTableRegion: - table = table or mock_ElectrodeTable(n_rows=5, nwbfile=nwbfile) + table = table or mock_ElectrodesTable(n_rows=5, nwbfile=nwbfile) return DynamicTableRegion( name="electrodes", data=list(range(n_electrodes)), @@ -80,7 +80,7 @@ def mock_ElectricalSeries( conversion: float = 1.0, offset: float = 0., ) -> ElectricalSeries: - + # Set a default rate if timestamps are not provided rate = 30_000.0 if (timestamps is None and rate is None) else rate diff --git a/tests/integration/hdf5/test_nwbfile.py b/tests/integration/hdf5/test_nwbfile.py index e164ec649..081cd7ea7 100644 --- a/tests/integration/hdf5/test_nwbfile.py +++ b/tests/integration/hdf5/test_nwbfile.py @@ -508,6 +508,7 @@ def getContainer(self, nwbfile): def test_roundtrip(self): super().test_roundtrip() + # When comparing the pandas dataframes for the row we drop the 'group' column since the # ElectrodeGroup object after reading will naturally have a different address pd.testing.assert_frame_equal(self.read_container[0].drop('group', axis=1), diff --git a/tests/unit/test_ecephys.py b/tests/unit/test_ecephys.py index c91593ed7..ddd5706e1 100644 --- a/tests/unit/test_ecephys.py +++ b/tests/unit/test_ecephys.py @@ -24,7 +24,7 @@ def make_electrode_table(): - table = ElectrodeTable() + table = ElectrodesTable() dev1 = Device('dev1') group = ElectrodeGroup('tetrode1', 'tetrode description', 'tetrode location', dev1) table.add_row(location='CA1', group=group, group_name='tetrode1') diff --git a/tests/unit/test_file.py b/tests/unit/test_file.py index ef7732322..43eb6f692 100644 --- a/tests/unit/test_file.py +++ b/tests/unit/test_file.py @@ -245,7 +245,7 @@ def test_add_acquisition_invalid_name(self): self.nwbfile.get_acquisition("TEST_TS") def test_set_electrode_table(self): - table = ElectrodeTable() + table = ElectrodesTable() dev1 = self.nwbfile.create_device('dev1') group = self.nwbfile.create_electrode_group('tetrode1', 'tetrode description', 'tetrode location', dev1) diff --git a/tests/unit/test_mock.py b/tests/unit/test_mock.py index 2ce777b65..2fd034a25 100644 --- a/tests/unit/test_mock.py +++ b/tests/unit/test_mock.py @@ -32,7 +32,7 @@ from pynwb.testing.mock.ecephys import ( mock_ElectrodeGroup, - mock_ElectrodeTable, + mock_ElectrodesTable, mock_ElectricalSeries, mock_SpikeEventSeries, mock_Units, @@ -70,7 +70,7 @@ mock_CompassDirection, mock_SpatialSeries, mock_ElectrodeGroup, - mock_ElectrodeTable, + mock_ElectrodesTable, mock_ElectricalSeries, mock_SpikeEventSeries, mock_Subject, @@ -121,4 +121,3 @@ def test_name_generator(): assert name_generator("TimeSeries") == "TimeSeries" assert name_generator("TimeSeries") == "TimeSeries2" -