aslprep.interfaces.bids module
Adapted interfaces from Niworkflows.
- class BIDSDataGrabber(*args, **kwargs)[source]
Bases:
SimpleInterfaceCollect files from a BIDS directory structure.
>>> bids_src = BIDSDataGrabber(anat_only=False) >>> bids_src.inputs.subject_data = bids_collect_data( ... str(datadir / 'ds114'), '01', bids_validate=False)[0] >>> bids_src.inputs.subject_id = '01' >>> res = bids_src.run() >>> res.outputs.t1w ['.../ds114/sub-01/ses-retest/anat/sub-01_ses-retest_T1w.nii.gz', '.../ds114/sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz']
- Optional Inputs:
subject_data (a dictionary with keys which are a string and with values which are any value)
subject_id (a string)
- Outputs:
asl (a list of items which are any value) – Output ASL images.
bold (a list of items which are any value) – Output functional images.
dwi (a list of items which are any value) – Output DWI images.
flair (a list of items which are any value) – Output FLAIR images.
fmap (a list of items which are any value) – Output fieldmaps.
out_dict (a dictionary with keys which are any value and with values which are any value) – Output data structure.
pet (a list of items which are any value) – Output PET images.
roi (a list of items which are any value) – Output ROI images.
sbref (a list of items which are any value) – Output sbrefs.
t1w (a list of items which are any value) – Output T1w images.
t2w (a list of items which are any value) – Output T2w images.
- class BIDSURI(numinputs=0, **inputs)[source]
Bases:
SimpleInterfaceConvert input filenames to BIDS URIs, based on links in the dataset.
This interface can combine multiple lists of inputs.
- Mandatory Inputs:
dataset_links (a dictionary with keys which are any value and with values which are any value) – Dataset links.
out_dir (a string) – Output directory.
- Optional Inputs:
field (a string) – Field to use for BIDS URIs in metadata dict. (Nipype default value:
Sources)metadata (a dictionary with keys which are any value and with values which are any value) – Metadata dictionary.
- Outputs:
metadata (a dictionary with keys which are any value and with values which are any value) – Dictionary with ‘Sources’ field.
out (a list of items which are a string) – BIDS URI(s) for file.
- class CopyAtlas(from_file=None, resource_monitor=None, **inputs)[source]
Bases:
SimpleInterfaceCopy atlas file to output directory.
- Parameters:
- Returns:
out_file – The path to the copied atlas file.
- Return type:
Notes
I can’t use DerivativesDataSink because it has a problem with dlabel CIFTI files. It gives the following error: “AttributeError: ‘Cifti2Header’ object has no attribute ‘set_data_dtype’”
I can’t override the CIFTI atlas’s data dtype ahead of time because setting it to int8 or int16 somehow converts all of the values in the data array to weird floats. This could be a version-specific nibabel issue.
I’ve also updated this function to handle JSON and TSV files as well.
- Mandatory Inputs:
atlas (a string) – The atlas name.
in_file (a pathlike object or string representing an existing file) – The atlas file to copy.
output_dir (a pathlike object or string representing an existing directory) – The output directory.
- Optional Inputs:
Sources (a list of items which are a string) – List of sources for the atlas.
meta_dict (a dictionary with keys which are any value and with values which are any value or None) – The atlas metadata dictionary.
name_source (a string) – The source file’s name.
- Outputs:
out_file (a pathlike object or string representing an existing file) – The copied atlas file.
- class CopyAtlasDescription(from_file=None, resource_monitor=None, **inputs)[source]
Bases:
SimpleInterfaceCopy atlas description file to output directory.
- Parameters:
- Returns:
out_file – The path to the copied atlas description file.
- Return type:
- Mandatory Inputs:
atlas_name (a string) – The name of the atlas.
in_dir (a pathlike object or string representing an existing directory) – The atlas directory to copy the description file from.
output_dir (a pathlike object or string representing an existing directory) – The output directory.
- Outputs:
out_file (a pathlike object or string representing an existing file) – The copied atlas file.
- class DerivativesDataSink(allowed_entities=None, out_path_base=None, **inputs)[source]
Bases:
DerivativesDataSinkStore derivative files.
A child class of the niworkflows DerivativesDataSink, using aslprep’s configuration files.
- Mandatory Inputs:
in_file (a list of items which are a pathlike object or string representing an existing file) – The object to be saved.
source_file (a list of items which are a pathlike object or string representing a file) – The source file(s) to extract entities from.
- Optional Inputs:
base_directory (a string or os.PathLike object) – Path to the base directory for storing data.
check_hdr (a boolean) – Fix headers of NIfTI outputs. (Nipype default value:
True)compress (a list of items which are a boolean or None) – Whether
in_fileshould be compressed (True), uncompressed (False) or left unmodified (None, default). (Nipype default value:[])data_dtype (a string) – NumPy datatype to coerce NIfTI data to, or source to match the input file dtype.
dismiss_entities (a list of items which are a string or None) – A list entities that will not be propagated from the source file. (Nipype default value:
[])meta_dict (a dictionary with keys which are a string and with values which are any value) – An input dictionary containing metadata.
- Outputs:
compression (a list of items which are a boolean or None) – Whether
in_fileshould be compressed (True), uncompressed (False) or left unmodified (None).fixed_hdr (a list of items which are a boolean) – Whether derivative header was fixed.
out_file (a list of items which are a pathlike object or string representing an existing file)
out_meta (a list of items which are a pathlike object or string representing an existing file)
- out_path_base = ''
- class FunctionOverrideContext(module, function_name, new_function)[source]
Bases:
objectOverride a function in imported code with a context manager.
Even though this class is currently unused, I’m keeping it around for when I need to override prepare_timing_parameters once fMRIPrep’s init_bold_surf_wf is usable (i.e., once the DerivativesDataSink import is moved out of the function).
Here’s how it worked before:
- def _fake_params(metadata): # noqa: U100
return {“SliceTimingCorrected”: False}
# init_bold_surf_wf uses prepare_timing_parameters, which uses the config object. # The uninitialized fMRIPrep config will have config.workflow.ignore set to None # instead of a list, which will raise an error. with FunctionOverrideContext(resampling, “prepare_timing_parameters”, _fake_params):
- asl_surf_wf = resampling.init_bold_surf_wf(
mem_gb=mem_gb[“resampled”], metadata=metadata, surface_spaces=freesurfer_spaces, medial_surface_nan=config.workflow.medial_surface_nan, output_dir=config.execution.aslprep_dir, name=”asl_surf_wf”,
)
- class OverrideDerivativesDataSink(module)[source]
Bases:
objectA context manager for temporarily overriding the definition of DerivativesDataSink.
- Parameters:
None
- Attributes:
original_class (type) (The original class that is replaced during the override.)