From bf8df82b3aa54f657ddff58dc2d8d60b7f8e6f76 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:30:21 -0700 Subject: [PATCH 1/6] make epoch_tags a property --- src/pynwb/file.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pynwb/file.py b/src/pynwb/file.py index 0b294e873..c08c5478d 100644 --- a/src/pynwb/file.py +++ b/src/pynwb/file.py @@ -362,8 +362,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 +424,6 @@ def __init__(self, **kwargs): 'stimulus_template', 'keywords', 'processing', - 'epoch_tags', 'electrodes', 'electrode_groups', 'devices', @@ -526,6 +523,9 @@ def __init__(self, **kwargs): for key, val in args_to_set.items(): setattr(self, key, val) + # set epoch_tags to set() on initialization + self.fields['epoch_tags'] = self.epoch_tags + self.__obj = None def all_children(self): @@ -555,6 +555,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 +620,7 @@ 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.fields['epoch_tags'].update(kwargs.pop('tags', list())) self.epochs.add_column(**kwargs) def add_epoch_metadata_column(self, *args, **kwargs): @@ -639,7 +643,7 @@ def add_epoch(self, **kwargs): """ self.__check_epochs() if kwargs['tags'] is not None: - self.epoch_tags.update(kwargs['tags']) + self.fields['epoch_tags'].update(kwargs['tags']) self.epochs.add_interval(**kwargs) def __check_electrodes(self): From 57a738081e90c54f3ee519ec392963d1b004b30e Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:59:30 -0700 Subject: [PATCH 2/6] remove epoch tags from fields dict --- src/pynwb/file.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/pynwb/file.py b/src/pynwb/file.py index c08c5478d..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, @@ -523,9 +522,6 @@ def __init__(self, **kwargs): for key, val in args_to_set.items(): setattr(self, key, val) - # set epoch_tags to set() on initialization - self.fields['epoch_tags'] = self.epoch_tags - self.__obj = None def all_children(self): @@ -620,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.fields['epoch_tags'].update(kwargs.pop('tags', list())) self.epochs.add_column(**kwargs) def add_epoch_metadata_column(self, *args, **kwargs): @@ -642,8 +637,6 @@ def add_epoch(self, **kwargs): enclosure versus sleeping between explorations) """ self.__check_epochs() - if kwargs['tags'] is not None: - self.fields['epoch_tags'].update(kwargs['tags']) self.epochs.add_interval(**kwargs) def __check_electrodes(self): From 074f6b90d0407bf35a6cb207cf0e239656bb30d3 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 17 Jul 2024 18:17:39 -0700 Subject: [PATCH 3/6] remove epoch_tags from print assertion --- tests/unit/test_core.py | 4 ---- 1 file changed, 4 deletions(-) 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 From f7a56c4be8f099cd6c8c23489ed9688ccf885578 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 17 Jul 2024 18:17:51 -0700 Subject: [PATCH 4/6] add test for single string tags --- tests/unit/test_file.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit/test_file.py b/tests/unit/test_file.py index 98446fa46..a6938a9c3 100644 --- a/tests/unit/test_file.py +++ b/tests/unit/test_file.py @@ -142,6 +142,15 @@ 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_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])) From 0c910ad4548996bab9682c4fcfe425d63d58294c Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 17 Jul 2024 18:39:23 -0700 Subject: [PATCH 5/6] add test for no epochs table --- tests/unit/test_file.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/test_file.py b/tests/unit/test_file.py index a6938a9c3..8cb3415d9 100644 --- a/tests/unit/test_file.py +++ b/tests/unit/test_file.py @@ -151,6 +151,9 @@ def test_epoch_tags_single_string(self): 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])) From bc716a941d62c37569e4b969542c5dc733f0a36c Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 17 Jul 2024 19:21:51 -0700 Subject: [PATCH 6/6] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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)