Add get_structures_at_hierarchy_level method to Atlas class #665
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements method to query brain structures at specific hierarchy levels within descendants of a given structure. The method finds all leaf nodes in a structure's subtree and extracts structures at the specified level from their paths.
Features:
Closes #623
Description
What is this PR
Why is this PR needed?
Filter anatomical structures by their depth in the hierarchy tree. Currently, there's no built-in method to query structures at a specific hierarchy level within a given structure's descendants. This method addresses issue #623 and enables more flexible structure queries for neuroscience data analysis.
What does this PR do?
Adds a new
get_structures_at_hierarchy_levelmethod to theAtlasclass that:as_acronymparameterhierarchy_level=Noneto return all structures in paths to leavesReferences
Closes #623
How has this PR been tested?
Testing performed:
Added 6 comprehensive unit tests in
tests/atlasapi/test_core_atlas.py:test_get_structures_at_hierarchy_level- Basic functionality with acronyms, IDs, multiple levelstest_get_structures_at_hierarchy_level_none- Testshierarchy_level=Nonebehaviortest_get_structures_at_hierarchy_level_invalid_structure- KeyError handlingtest_get_structures_at_hierarchy_level_negative_level- ValueError for negative levelstest_get_structures_at_hierarchy_level_wrong_type- ValueError for wrong typestest_get_structures_at_hierarchy_level_too_deep- ValueError for levels exceeding depthAll tests pass (28/28 tests in test_core_atlas.py)
Test coverage for
core.pyincreased to 99%Verified no existing functionality is broken - all 22 pre-existing tests continue to pass
Manual testing with the example_mouse_100um atlas confirmed correct behavior
Is this a breaking change?
No. This PR only adds a new method and does not modify any existing functionality. All existing APIs remain unchanged.
Does this PR require an update to the documentation?
The method includes comprehensive docstrings with:
If the project maintains separate user-facing API documentation, the new method should be added there. I can create a follow-up PR for documentation updates if needed.
Checklist: