Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to find objects of a given neurodata type / pynwb class #1737

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,30 @@
self.all_children()
return self.__obj

@docval({'name': 'neurodata_types', 'type': (type, str),
'doc': ('The PyNWB container class to search for instances of, or the string with the name of '
'the neurodata_type')},)
def find_all(self, neurodata_type):
"""Return all PyNWB objects in the file that are instances of the neurodata_type class.

This includes objects that are instances of a subclass of the class. A string with the name of the
neurodata_type can also be passed in.

.. code-block:: python

from pynwb import ImageSeries
obj_list = find_all(nwbfile, ImageSeries)
obj_list = find_all(nwbfile, "EcephysSpecimen") # EcephysSpecimen is defined in a loaded extension

"""
if isinstance(neurodata_type, str):
pynwb_cls = self.io.manager.type_map.get_dt_container_cls(neurodata_type)

Check warning on line 569 in src/pynwb/file.py

View check run for this annotation

Codecov / codecov/patch

src/pynwb/file.py#L569

Added line #L569 was not covered by tests
else:
pynwb_cls = neurodata_type

Check warning on line 571 in src/pynwb/file.py

View check run for this annotation

Codecov / codecov/patch

src/pynwb/file.py#L571

Added line #L571 was not covered by tests

ret = [obj for obj in self.objects.values() if isinstance(obj, pynwb_cls)]
return ret

Check warning on line 574 in src/pynwb/file.py

View check run for this annotation

Codecov / codecov/patch

src/pynwb/file.py#L574

Added line #L574 was not covered by tests

@property
def modules(self):
warn("NWBFile.modules has been replaced by NWBFile.processing.", DeprecationWarning)
Expand Down