Skip to content

scope not assigned when loading a derivative directory directly #1129

@eric-d-knowles

Description

@eric-d-knowles

When loading a BIDS derivative directory directly using BIDSLayout, files are not assigned a .scope attribute, even though a valid dataset_description.json with a "Name" field is present and correctly parsed.

This behavior prevents scope-based filtering (e.g., scope='cleaned') from working when derivative layouts are loaded independently or added via add_derivatives().

Given this structure:

/path/to/dataset/
├── dataset_description.json
└── derivatives/
    └── cleaned/
        ├── dataset_description.json  # "Name": "cleaned"
        └── sub-001/
            └── func/
                ├── sub-001_task-test_run-1_desc-cleaned_bold.nii.gz
                └── sub-001_task-test_run-1_desc-resampled_bold.nii.gz

dataset_description.json:

{
"Name": "cleaned",
"BIDSVersion": "1.6.0",
"DatasetType": "derivative"
}

Python code:

from bids import BIDSLayout

layout = BIDSLayout('/path/to/dataset/derivatives/cleaned', validate=False, derivatives=False)
files = layout.get(suffix='bold', extension='nii.gz', return_type='obj')

print(files[0].path)
print("scope:", getattr(files[0], 'scope', 'NO_SCOPE'))

Expected behavior:

scope: cleaned

Actual behavior:

scope: NO_SCOPE

Environment:

PyBIDS version: 0.19.0
Python version: 3.11.11
Platform: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions