Writing methods reports with pybids.reportsΒΆ

This tutorial

%load_ext autoreload
%autoreload 2

from bids import BIDSLayout
from bids.reports import BIDSReport
from bids.tests import get_test_data_path
import os
dataset = "synthetic"

# Here we're using an example BIDS dataset that's bundled with the pybids tests
data_path = os.path.join(get_test_data_path(), dataset)

# Load the BIDS dataset
layout = BIDSLayout(data_path)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 7
      4 data_path = os.path.join(get_test_data_path(), dataset)
      6 # Load the BIDS dataset
----> 7 layout = BIDSLayout(data_path)

File ~/work/pybids/pybids/.tox/docs/lib/python3.12/site-packages/bids/layout/layout.py:148, in BIDSLayout.__init__(self, root, validate, absolute_paths, derivatives, config, sources, regex_search, database_path, reset_database, indexer, is_derivative, **indexer_kwargs)
    145     config = info.config
    147 # Validate that a valid BIDS project exists at root
--> 148 root, description = validate_root(root, validate)
    149 if any([
    150     is_derivative,
    151     description and description.get("DatasetType") == "derivative"
    152 ]):
    153     try:

File ~/work/pybids/pybids/.tox/docs/lib/python3.12/site-packages/bids/layout/validation.py:54, in validate_root(root, validate)
     52 root = root.absolute()
     53 if not root.exists():
---> 54     raise ValueError("BIDS root does not exist: %s" % root)
     56 target = root / 'dataset_description.json'
     57 if not target.exists():

ValueError: BIDS root does not exist: /home/runner/work/pybids/pybids/.tox/docs/lib/python3.12/tests/data/synthetic
# Initialize a report for the dataset
report = BIDSReport(layout)
# Method generate returns a Counter of unique descriptions across subjects
descriptions = report.generate()
# For datasets containing a single study design, all but the most common
# description most likely reflect random missing data.
pub_description = descriptions.most_common()[0][0]
print(pub_description)