Skip to content

Commit f73379d

Browse files
committed
add 'self' option to _get_layouts_in_scope
1 parent 5860e4f commit f73379d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

bids/layout/layout.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ def _in_scope(self, scope):
364364
def _get_layouts_in_scope(self, scope):
365365
''' Return all layouts in the passed scope. '''
366366

367+
if scope == 'self':
368+
return [self]
369+
367370
def collect_layouts(layout):
368371
''' Recursively build a list of layouts '''
369372
children = list(layout.derivatives.values())
@@ -623,6 +626,7 @@ def get(self, return_type='object', target=None, scope='all',
623626
'all' (default): search all available directories.
624627
'derivatives': search all derivatives directories
625628
'raw': search only BIDS-Raw directories
629+
'self': search only the directly called BIDSLayout
626630
<PipelineName>: the name of a BIDS-Derivatives pipeline
627631
regex_search (bool or None): Whether to require exact matching
628632
(False) or regex search (True) when comparing the query string
@@ -844,8 +848,9 @@ def get_metadata(self, path, include_entities=False, scope='all'):
844848
from the filename (rather than JSON sidecars) are included in
845849
the returned metadata dictionary.
846850
scope (str, list): The scope of the search space. Each element must
847-
be one of 'all', 'raw', 'derivatives', or a BIDS-Derivatives
848-
pipeline name. Defaults to searching all available datasets.
851+
be one of 'all', 'raw', 'self', 'derivatives', or a
852+
BIDS-Derivatives pipeline name. Defaults to searching all
853+
available datasets.
849854
850855
Returns: A dictionary of key/value pairs extracted from all of the
851856
target file's associated JSON sidecars.
@@ -872,7 +877,6 @@ def get_metadata(self, path, include_entities=False, scope='all'):
872877

873878
return {}
874879

875-
876880
def get_nearest(self, path, return_type='filename', strict=True,
877881
all_=False, ignore_strict_entities='extension',
878882
full_search=False, **filters):

bids/layout/tests/test_layout.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ def test_get_layouts_in_scope(layout_ds005_multi_derivs):
490490
assert len(l._get_layouts_in_scope(['events', 'dummy'])) == 2
491491
assert len(l._get_layouts_in_scope(['derivatives'])) == 2
492492
assert len(l._get_layouts_in_scope('raw')) == 1
493+
self_scope = l._get_layouts_in_scope('self')
494+
assert len(self_scope) == 1
495+
assert self_scope == [l]
493496

494497

495498
def test_indexed_file_associations(layout_7t_trt):

0 commit comments

Comments
 (0)