diff --git a/CHANGELOG.md b/CHANGELOG.md index 9762bf20d..3d3dae88c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/pynwb/file.py b/src/pynwb/file.py index 0b294e873..7621df2ac 100644 --- a/src/pynwb/file.py +++ b/src/pynwb/file.py @@ -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, @@ -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, @@ -426,7 +423,6 @@ def __init__(self, **kwargs): 'stimulus_template', 'keywords', 'processing', - 'epoch_tags', 'electrodes', 'electrode_groups', 'devices', @@ -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) @@ -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): @@ -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): diff --git a/tests/unit/test_core.py b/tests/unit/test_core.py index e2a060d20..5a564f975 100644 --- a/tests/unit/test_core.py +++ b/tests/unit/test_core.py @@ -135,10 +135,6 @@ def test_print_file(self): name1 , name2 } - epoch_tags: { - tag1, - tag2 - } epochs: epochs file_create_date: \[datetime.datetime\(.*\)\] identifier: identifier diff --git a/tests/unit/test_file.py b/tests/unit/test_file.py index 98446fa46..8cb3415d9 100644 --- a/tests/unit/test_file.py +++ b/tests/unit/test_file.py @@ -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]))