Skip to content

Commit

Permalink
Adding argument for metadata indexing by generate_inputs (#367)
Browse files Browse the repository at this point in the history
Argument passed transparently on to pybids BIDSLayout
  • Loading branch information
myousif9 authored Feb 2, 2024
1 parent 5acabfd commit 998cca2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion snakebids/core/input_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def generate_inputs(
participant_label: Iterable[str] | str | None = ...,
exclude_participant_label: Iterable[str] | str | None = ...,
use_bids_inputs: Literal[True] | None = ...,
index_metadata: bool = ...,
validate: bool = ...,
pybids_database_dir: Path | str | None = ...,
pybids_reset_database: bool = ...,
Expand All @@ -75,6 +76,7 @@ def generate_inputs(
participant_label: Iterable[str] | str | None = ...,
exclude_participant_label: Iterable[str] | str | None = ...,
use_bids_inputs: Literal[False] = ...,
index_metadata: bool = ...,
validate: bool = ...,
pybids_database_dir: Path | str | None = ...,
pybids_reset_database: bool = ...,
Expand All @@ -93,6 +95,7 @@ def generate_inputs(
participant_label: Iterable[str] | str | None = None,
exclude_participant_label: Iterable[str] | str | None = None,
use_bids_inputs: bool | None = None,
index_metadata: bool = False,
validate: bool = False,
pybids_database_dir: Path | str | None = None,
pybids_reset_database: bool | None = None,
Expand Down Expand Up @@ -163,6 +166,10 @@ def generate_inputs(
:class`BidsDataset`. Setting to True is deprecated as of v0.8, as this is now
the default behaviour
index_metadata
If True indexes metadata of BIDS directory using pybids, otherwise skips
indexing.
validate
If True performs validation of BIDS directory using pybids, otherwise
skips validation.
Expand Down Expand Up @@ -277,6 +284,7 @@ def generate_inputs(
pybids_config=pybids_config,
pybidsdb_dir=pybidsdb_dir,
pybidsdb_reset=pybidsdb_reset,
index_metadata=index_metadata,
validate=validate,
)
if not _all_custom_paths(pybids_inputs)
Expand Down Expand Up @@ -392,6 +400,7 @@ def _gen_bids_layout(
pybidsdb_dir: Path | str | None,
pybidsdb_reset: bool,
pybids_config: Path | str | None = None,
index_metadata: bool = False,
validate: bool = False,
) -> BIDSLayout:
"""Create (or reindex) the BIDSLayout.
Expand All @@ -414,6 +423,9 @@ def _gen_bids_layout(
A boolean that determines whether to reset / overwrite
existing database.
index_metadata
A boolen that determines whether to parse and index metadata
validate
A boolean that determines whether to validate the bids dataset
Expand All @@ -438,7 +450,7 @@ def _gen_bids_layout(
config=pybids_config,
database_path=pybidsdb_dir,
reset_database=pybidsdb_reset,
indexer=BIDSLayoutIndexer(validate=False, index_metadata=False),
indexer=BIDSLayoutIndexer(validate=False, index_metadata=index_metadata),
)


Expand Down
21 changes: 21 additions & 0 deletions snakebids/tests/test_generate_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,27 @@ def test_nonstandard_custom_pybids_config(tmpdir: Path):
)


def test_index_metadata(mocker: MockerFixture):
from snakebids.core import input_generation

spy = mocker.spy(input_generation, "BIDSLayoutIndexer")
mocker.patch.object(input_generation, "BIDSLayout", side_effect=ValueError)

# Simplest case -- one input type, using pybids
with pytest.raises(ValueError): # noqa
generate_inputs(
pybids_inputs={"foo": {}},
bids_dir=..., # type: ignore
derivatives=..., # type: ignore
index_metadata=True,
)

spy.assert_called_once_with(
validate=False,
index_metadata=True,
)


def test_t1w():
# create config
real_bids_dir = "snakebids/tests/data/bids_t1w"
Expand Down

0 comments on commit 998cca2

Please sign in to comment.