Skip to content

Commit 8fabbb5

Browse files
authored
Merge pull request #762 from tsalo/datasink-config
REF: Store global variables as DerivativesDataSink attributes
2 parents a75d9c9 + 1b1fd05 commit 8fabbb5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

niworkflows/interfaces/bids.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,15 @@ class DerivativesDataSink(SimpleInterface):
498498
output_spec = _DerivativesDataSinkOutputSpec
499499
out_path_base = "niworkflows"
500500
_always_run = True
501-
_allowed_entities = set(BIDS_DERIV_ENTITIES)
501+
_config_entities = BIDS_DERIV_ENTITIES
502+
_standard_spaces = STANDARD_SPACES
503+
_file_patterns = BIDS_DERIV_PATTERNS
504+
_default_dtypes = DEFAULT_DTYPES
502505

503506
def __init__(self, allowed_entities=None, out_path_base=None, **inputs):
504507
"""Initialize the SimpleInterface and extend inputs with custom entities."""
505508
self._allowed_entities = set(allowed_entities or []).union(
506-
self._allowed_entities
509+
set(self._config_entities)
507510
)
508511
if out_path_base:
509512
self.out_path_base = out_path_base
@@ -585,7 +588,7 @@ def _run_interface(self, runtime):
585588
space = out_entities.get("space")
586589
if resolution:
587590
# Standard spaces
588-
if space in STANDARD_SPACES:
591+
if space in self._standard_spaces:
589592
res = _get_tf_resolution(space, resolution)
590593
else: # TODO: Nonstandard?
591594
res = "Unknown"
@@ -595,8 +598,8 @@ def _run_interface(self, runtime):
595598
out_entities["extension"] = out_entities["extension"][0]
596599

597600
# Insert custom (non-BIDS) entities from allowed_entities.
598-
custom_entities = set(out_entities.keys()) - set(BIDS_DERIV_ENTITIES)
599-
patterns = BIDS_DERIV_PATTERNS
601+
custom_entities = set(out_entities) - set(self._config_entities)
602+
patterns = self._file_patterns
600603
if custom_entities:
601604
# Example: f"{key}-{{{key}}}" -> "task-{task}"
602605
custom_pat = "_".join(f"{key}-{{{key}}}" for key in sorted(custom_entities))
@@ -648,7 +651,7 @@ def _run_interface(self, runtime):
648651
is_nifti = out_file.name.endswith(
649652
(".nii", ".nii.gz")
650653
) and not out_file.name.endswith((".dtseries.nii", ".dtseries.nii.gz"))
651-
data_dtype = self.inputs.data_dtype or DEFAULT_DTYPES[self.inputs.suffix]
654+
data_dtype = self.inputs.data_dtype or self._default_dtypes[self.inputs.suffix]
652655
if is_nifti and any((self.inputs.check_hdr, data_dtype)):
653656
nii = nb.load(orig_file)
654657

@@ -667,7 +670,7 @@ def _run_interface(self, runtime):
667670
xcodes = (1, 1) # Derivative in its original scanner space
668671
if self.inputs.space:
669672
xcodes = (
670-
(4, 4) if self.inputs.space in STANDARD_SPACES else (2, 2)
673+
(4, 4) if self.inputs.space in self._standard_spaces else (2, 2)
671674
)
672675

673676
curr_zooms = zooms = hdr.get_zooms()

0 commit comments

Comments
 (0)