diff --git a/CHANGES.rst b/CHANGES.rst index 2d722e493ea..f0a54a4e633 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +1.7.7 (March 24, 2023) +====================== +Patch release that optimizes BIDS metadata handling by reusing cached index databases. + +* ENH: Allow passing a ``database_path`` to create a ``BIDSLayout`` (#788) + 1.7.6 (March 06, 2023) ====================== Patch release in the 1.7.x series. diff --git a/niworkflows/interfaces/bids.py b/niworkflows/interfaces/bids.py index 5fc95b90f64..d8f154f73a1 100644 --- a/niworkflows/interfaces/bids.py +++ b/niworkflows/interfaces/bids.py @@ -84,6 +84,7 @@ class _BIDSBaseInputSpec(BaseInterfaceInputSpec): (None, Directory(exists=True)), usedefault=True, desc="optional bids directory" ) bids_validate = traits.Bool(True, usedefault=True, desc="enable BIDS validator") + index_db = Directory(exists=True, desc="a PyBIDS layout cache directory") class _BIDSInfoInputSpec(_BIDSBaseInputSpec): @@ -832,7 +833,13 @@ def _outputs(self): def _run_interface(self, runtime): self.layout = self.inputs.bids_dir or self.layout self.layout = _init_layout( - self.inputs.in_file, self.layout, self.inputs.bids_validate + self.inputs.in_file, + self.layout, + self.inputs.bids_validate, + database_path=( + self.inputs.index_db if isdefined(self.inputs.index_db) + else None + ) ) # Fill in BIDS entities of the output ("*_id") diff --git a/niworkflows/utils/bids.py b/niworkflows/utils/bids.py index 3fd894f78fd..8dfb56538f2 100644 --- a/niworkflows/utils/bids.py +++ b/niworkflows/utils/bids.py @@ -280,7 +280,7 @@ def get_metadata_for_nifti(in_file, bids_dir=None, validate=True): return _init_layout(in_file, bids_dir, validate).get_metadata(str(in_file)) -def _init_layout(in_file=None, bids_dir=None, validate=True): +def _init_layout(in_file=None, bids_dir=None, validate=True, database_path=None): if isinstance(bids_dir, BIDSLayout): return bids_dir @@ -294,7 +294,11 @@ def _init_layout(in_file=None, bids_dir=None, validate=True): if bids_dir is None: raise RuntimeError("Could not infer BIDS root") - layout = BIDSLayout(str(bids_dir), validate=validate) + layout = BIDSLayout( + str(bids_dir), + validate=validate, + database_path=database_path, + ) return layout