Skip to content

Commit

Permalink
Change epoch tags to property (#1935)
Browse files Browse the repository at this point in the history
* make epoch_tags a property

* remove epoch tags from fields dict

* remove epoch_tags from print assertion

* add test for single string tags

* add test for no epochs table

* update CHANGELOG.md
  • Loading branch information
stephprince authored Jul 18, 2024
1 parent a9f6332 commit fcd7008
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### Bug fixes
- Fixed `can_read` method to return False if no nwbfile version can be found @stephprince [#1934](https://github.com/NeurodataWithoutBorders/pynwb/pull/1934)
- Changed `epoch_tags` to be a NWBFile property instead of constructor argument. @stephprince [#1935](https://github.com/NeurodataWithoutBorders/pynwb/pull/1935)

## PyNWB 2.8.1 (July 3, 2024)

Expand Down
11 changes: 4 additions & 7 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ class NWBFile(MultiContainerInterface, HERDManager):
{'name': 'subject', 'child': True, 'required_name': 'subject'},
{'name': 'sweep_table', 'child': True, 'required_name': 'sweep_table'},
{'name': 'invalid_times', 'child': True, 'required_name': 'invalid_times'},
'epoch_tags',
# icephys_filtering is temporary. /intracellular_ephys/filtering dataset will be deprecated
{'name': 'icephys_filtering', 'settable': False},
{'name': 'intracellular_recordings', 'child': True,
Expand Down Expand Up @@ -362,8 +361,6 @@ class NWBFile(MultiContainerInterface, HERDManager):
'doc': 'Stimulus template TimeSeries objects belonging to this NWBFile', 'default': None},
{'name': 'epochs', 'type': TimeIntervals,
'doc': 'Epoch objects belonging to this NWBFile', 'default': None},
{'name': 'epoch_tags', 'type': (tuple, list, set),
'doc': 'A sorted list of tags used across all epochs', 'default': set()},
{'name': 'trials', 'type': TimeIntervals,
'doc': 'A table containing trial data', 'default': None},
{'name': 'invalid_times', 'type': TimeIntervals,
Expand Down Expand Up @@ -426,7 +423,6 @@ def __init__(self, **kwargs):
'stimulus_template',
'keywords',
'processing',
'epoch_tags',
'electrodes',
'electrode_groups',
'devices',
Expand Down Expand Up @@ -555,6 +551,10 @@ def modules(self):
warn("NWBFile.modules has been replaced by NWBFile.processing.", DeprecationWarning)
return self.processing

@property
def epoch_tags(self):
return set(self.epochs.tags[:]) if self.epochs is not None else set()

@property
def ec_electrode_groups(self):
warn("NWBFile.ec_electrode_groups has been replaced by NWBFile.electrode_groups.", DeprecationWarning)
Expand Down Expand Up @@ -616,7 +616,6 @@ def add_epoch_column(self, **kwargs):
See :py:meth:`~hdmf.common.table.DynamicTable.add_column` for more details
"""
self.__check_epochs()
self.epoch_tags.update(kwargs.pop('tags', list()))
self.epochs.add_column(**kwargs)

def add_epoch_metadata_column(self, *args, **kwargs):
Expand All @@ -638,8 +637,6 @@ def add_epoch(self, **kwargs):
enclosure versus sleeping between explorations)
"""
self.__check_epochs()
if kwargs['tags'] is not None:
self.epoch_tags.update(kwargs['tags'])
self.epochs.add_interval(**kwargs)

def __check_electrodes(self):
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ def test_print_file(self):
name1 <class 'pynwb\.base\.TimeSeries'>,
name2 <class 'pynwb\.base\.TimeSeries'>
}
epoch_tags: {
tag1,
tag2
}
epochs: epochs <class 'pynwb.epoch.TimeIntervals'>
file_create_date: \[datetime.datetime\(.*\)\]
identifier: identifier
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ def test_epoch_tags(self):
tags = self.nwbfile.epoch_tags
self.assertEqual(set(expected_tags), set(tags))

def test_epoch_tags_single_string(self):
tags1 = 't1'
tags2 = 't2'
expected_tags = set([tags1, tags2])
self.nwbfile.add_epoch(0.0, 1.0, tags=tags1)
self.nwbfile.add_epoch(1.0, 2.0, tags=tags2)
tags = self.nwbfile.epoch_tags
self.assertEqual(expected_tags, tags)

def test_epoch_tags_no_table(self):
self.assertEqual(set(), self.nwbfile.epoch_tags)

def test_add_acquisition(self):
self.nwbfile.add_acquisition(TimeSeries('test_ts', [0, 1, 2, 3, 4, 5],
'grams', timestamps=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5]))
Expand Down

0 comments on commit fcd7008

Please sign in to comment.