9.1.3. Pre-processing#

Provide imports for preprocess sub-package.

class junifer.preprocess.BOLDWarper(reference)#

Class for warping BOLD NIfTI images.

Parameters:
referencestr

The data type to use as reference for warping.

Initialize the class.

get_output_type(input)#

Get output type.

Parameters:
inputlist of str

The input to the preprocessor. The list must contain the available Junifer Data dictionary keys.

Returns:
list of str

The updated list of available Junifer Data object keys after the pipeline step.

get_valid_inputs()#

Get valid data types for input.

Returns:
list of str

The list of data types that can be used as input for this preprocessor.

preprocess(input, extra_input=None)#

Preprocess.

Parameters:
inputdict

The BOLD input from the Junifer Data object.

extra_inputdict, optional

The other fields in the Junifer Data object. Must include the Warp and ref value’s keys.

Returns:
str

The key to store the output in the Junifer Data object.

dict

The computed result as dictionary. This will be stored in the Junifer Data object under the key data of the data type.

Raises:
ValueError

If extra_input is None.

RuntimeError

If warp / transformation file extension is not “.mat” or “.h5”.

class junifer.preprocess.BasePreprocessor(on=None, required_data_types=None)#

Provide abstract base class for all preprocessors.

Parameters:
onstr or list of str, optional

The kind of data to apply the preprocessor to. If None, will work on all available data (default None).

required_data_typesstr or list of str, optional

The kind of data types needed for computation. If None, will be equal to on (default None).

Raises:
ValueError

If required input data type(s) is(are) not found.

Initialize the class.

abstract get_output_type(input)#

Get output type.

Parameters:
inputlist of str

The input to the preprocessor. The list must contain the available Junifer Data dictionary keys.

Returns:
list of str

The updated list of available Junifer Data object keys after the pipeline step.

abstract get_valid_inputs()#

Get valid data types for input.

Returns:
list of str

The list of data types that can be used as input for this preprocessor.

abstract preprocess(input, extra_input=None)#

Preprocess.

Parameters:
inputdict

A single input from the Junifer Data object to preprocess.

extra_inputdict, optional

The other fields in the Junifer Data object. Useful for accessing other data kind that needs to be used in the computation. For example, the confound removers can make use of the confounds if available (default None).

Returns:
str

The key to store the output in the Junifer Data object.

dict

The computed result as dictionary. This will be stored in the Junifer Data object under the key data of the data type.

validate_input(input)#

Validate input.

Parameters:
inputlist of str

The input to the pipeline step. The list must contain the available Junifer Data dictionary keys.

Returns:
list of str

The actual elements of the input that will be processed by this pipeline step.

Raises:
ValueError

If the input does not have the required data.

class junifer.preprocess.fMRIPrepConfoundRemover(strategy=None, spike=None, detrend=True, standardize=True, low_pass=None, high_pass=None, t_r=None, masks=None)#

Class for confound removal using fMRIPrep confounds format.

Read confound files and select columns according to a pre-defined strategy.

Confound removal is based on nilearn.image.clean_img().

Parameters:
strategydict, optional

The strategy to use for each component. If None, will use the full strategy for all components (default None). The keys of the dictionary should correspond to names of noise components to include:

  • motion

  • wm_csf

  • global_signal

The values of dictionary should correspond to types of confounds extracted from each signal:

  • basic : only the confounding time series

  • power2 : signal + quadratic term

  • derivatives : signal + derivatives

  • full : signal + deriv. + quadratic terms + power2 deriv.

spikefloat, optional

If None, no spike regressor is added. If spike is a float, it will add a spike regressor for every point at which framewise displacement exceeds the specified float (default None).

detrendbool, optional

If True, detrending will be applied on timeseries, before confound removal (default True).

standardizebool, optional

If True, returned signals are set to unit variance (default True).

low_passfloat, optional

Low cutoff frequencies, in Hertz. If None, no filtering is applied (default None).

high_passfloat, optional

High cutoff frequencies, in Hertz. If None, no filtering is applied (default None).

t_rfloat, optional

Repetition time, in second (sampling period). If None, it will use t_r from nifti header (default None).

masksstr, dict or list of dict or str, optional

The specification of the masks to apply to regions before extracting signals. Check Using Masks for more details. If None, will not apply any mask (default None).

Initialize the class.

get_output_type(input)#

Get output type.

Parameters:
inputlist of str

The input to the preprocessor. The list must contain the available Junifer Data dictionary keys.

Returns:
list of str

The updated list of available Junifer Data object keys after the pipeline step.

get_valid_inputs()#

Get valid data types for input.

Returns:
list of str

The list of data types that can be used as input for this preprocessor.

preprocess(input, extra_input=None)#

Preprocess.

Parameters:
inputdict

A single input from the Junifer Data object to preprocess.

extra_inputdict, optional

The other fields in the Junifer Data object. Must include the BOLD_confounds key.

Returns:
str

The key to store the output in the Junifer Data object.

dict

The computed result as dictionary. This will be stored in the Junifer Data object under the key data of the data type.