pynwb icon indicating copy to clipboard operation
pynwb copied to clipboard

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

Open rly opened this issue 1 year ago • 3 comments

Motivation

A common feature request is to find objects of a given neurodata type or pynwb class.

For example:

  • get all objects with the neurodata type "EcephysSpecimen" from the namespace "ndx-aibs-ecephys"
  • get all objects with the neurodata type "Subject" from the namespace "core" including subclasses/subtypes such as "EcephysSpecimen" from the namespace "ndx-aibs-ecephys"
  • get all objects that are instances of a PyNWB class such as pynwb.file.Subject

Fix #560

TODO

  • [ ] Make tests

Checklist

  • [ ] Did you update CHANGELOG.md with your changes?
  • [x] Have you checked our Contributing document?
  • [x] Have you ensured the PR clearly describes the problem and the solution?
  • [x] Is your contribution compliant with our coding style? This can be checked running flake8 from the source directory.
  • [x] Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • [x] Have you included the relevant issue number using "Fix #XXX" notation where XXX is the issue number? By including "Fix #XXX" you allow GitHub to close issue #XXX when the PR is merged.

rly avatar Jul 25 '23 14:07 rly

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (7c6868b) 91.99% compared to head (46e8878) 91.82%.

Files Patch % Lines
src/pynwb/file.py 28.57% 5 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1737      +/-   ##
==========================================
- Coverage   91.99%   91.82%   -0.17%     
==========================================
  Files          27       27              
  Lines        2623     2630       +7     
  Branches      685      688       +3     
==========================================
+ Hits         2413     2415       +2     
- Misses        138      143       +5     
  Partials       72       72              
Flag Coverage Δ
integration 70.98% <28.57%> (-0.12%) :arrow_down:
unit 83.53% <28.57%> (-0.15%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 25 '23 14:07 codecov[bot]

Idea LGTM, just needs a quick test or two

CodyCBakerPhD avatar Jul 26 '23 02:07 CodyCBakerPhD

I'm wondering whether it would be simpler from a user perspective to have this part of the existing all_children method. I.e., we could add the query parameters for the types (with default value of None) to all_children. If the query parameters are set to None then all_children behaves as is and returns all the children and if the parameters are set then it would use the new logic to filter for types.

https://github.com/NeurodataWithoutBorders/pynwb/blob/46e8878b9d9bd908dd3cd0715769ce08329531d0/src/pynwb/file.py#L530

oruebel avatar Jan 24 '24 17:01 oruebel