Skip to content

Commit

Permalink
draft complete
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Oct 1, 2024
1 parent c97a0df commit 64ad906
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
31 changes: 19 additions & 12 deletions src/pynwb/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -62,7 +62,6 @@ def __init__(self, **kwargs):

# optional fields
keys_to_set = (
'group_name',
'x',
'y',
'z',
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions src/pynwb/io/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check warning on line 191 in src/pynwb/io/file.py

View check run for this annotation

Codecov / codecov/patch

src/pynwb/io/file.py#L190-L191

Added lines #L190 - L191 were not covered by tests

new_container = manager.construct(electrodes_builder, True)
# mapper = manager.get_map(electrodes_builder)
breakpoint()
return new_container

Check warning on line 194 in src/pynwb/io/file.py

View check run for this annotation

Codecov / codecov/patch

src/pynwb/io/file.py#L193-L194

Added lines #L193 - L194 were not covered by tests
else:
return None
Expand Down
8 changes: 4 additions & 4 deletions src/pynwb/testing/mock/ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)),
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions tests/integration/hdf5/test_nwbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from pynwb.testing.mock.ecephys import (
mock_ElectrodeGroup,
mock_ElectrodeTable,
mock_ElectrodesTable,
mock_ElectricalSeries,
mock_SpikeEventSeries,
mock_Units,
Expand Down Expand Up @@ -70,7 +70,7 @@
mock_CompassDirection,
mock_SpatialSeries,
mock_ElectrodeGroup,
mock_ElectrodeTable,
mock_ElectrodesTable,
mock_ElectricalSeries,
mock_SpikeEventSeries,
mock_Subject,
Expand Down Expand Up @@ -121,4 +121,3 @@ def test_name_generator():

assert name_generator("TimeSeries") == "TimeSeries"
assert name_generator("TimeSeries") == "TimeSeries2"

0 comments on commit 64ad906

Please sign in to comment.