def prep_func(strPathNiiMask, lstPathNiiFunc, varAvgThr=<NUM_LIT>,<EOL>varVarThr=<NUM_LIT>, strPrePro='<STR_LIT>'):
print('<STR_LIT>')<EOL>aryMask, hdrMsk, aryAff = load_nii(strPathNiiMask)<EOL>aryMask = np.array(aryMask).astype(np.int16)<EOL>tplNiiShp = aryMask.shape<EOL>varNumVoxTlt = (tplNiiShp[<NUM_LIT:0>] * tplNiiShp[<NUM_LIT:1>] * tplNiiShp[<NUM_LIT:2>])<EOL>aryMask = np.reshape(aryMask, varNumVoxTlt)<EOL>lstFunc = []<EOL>lstFuncAvg = []<EOL>lstFuncVar = []<EOL>varNumRun = len(lstPathNiiFunc)<EOL>for idxRun in range(varNumRun):<EOL><INDENT>print(('<STR_LIT>' + str(idxRun + <NUM_LIT:1>)))<EOL>aryTmpFunc, _, _ = load_nii(lstPathNiiFunc[idxRun])<EOL>tplNiiShp = aryTmpFunc.shape<EOL>aryTmpFunc = np.reshape(aryTmpFunc, [varNumVoxTlt, tplNiiShp[<NUM_LIT:3>]])<EOL>print('<STR_LIT>')<EOL>aryLgcMsk = np.greater(aryMask.astype(np.int16),<EOL>np.array([<NUM_LIT:0>], dtype=np.int16)[<NUM_LIT:0>])<EOL>aryTmpFunc = aryTmpFunc[aryLgcMsk, :]<EOL>lstFuncAvg.append(np.mean(aryTmpFunc, axis=<NUM_LIT:1>, dtype=np.float32))<EOL>lstFuncVar.append(np.var(aryTmpFunc, axis=<NUM_LIT:1>, dtype=np.float32))<EOL>if strPrePro == '<STR_LIT>':<EOL><INDENT>print('<STR_LIT>')<EOL>aryTmpFunc = np.subtract(aryTmpFunc,<EOL>np.mean(aryTmpFunc,<EOL>axis=<NUM_LIT:1>,<EOL>dtype=np.float32)[:, None])<EOL><DEDENT>elif strPrePro == '<STR_LIT>':<EOL><INDENT>print('<STR_LIT>')<EOL>aryTmpFunc = np.subtract(aryTmpFunc,<EOL>np.mean(aryTmpFunc,<EOL>axis=<NUM_LIT:1>,<EOL>dtype=np.float32)[:, None])<EOL>aryTmpStd = np.std(aryTmpFunc, axis=-<NUM_LIT:1>)<EOL>aryTmpLgc = np.greater(aryTmpStd, np.array([<NUM_LIT:0.0>]))<EOL>aryTmpFunc[aryTmpLgc, :] = np.divide(aryTmpFunc[aryTmpLgc, :],<EOL>aryTmpStd[aryTmpLgc, None])<EOL><DEDENT>lstFunc.append(aryTmpFunc)<EOL>del(aryTmpFunc)<EOL><DEDENT>aryFunc = np.concatenate(lstFunc, axis=<NUM_LIT:1>).astype(np.float32, copy=False)<EOL>del(lstFunc)<EOL>aryFuncAvg = np.stack(lstFuncAvg, axis=<NUM_LIT:1>).astype(np.float32, copy=False)<EOL>del(lstFuncAvg)<EOL>aryFuncVar = np.stack(lstFuncVar, axis=<NUM_LIT:1>).astype(np.float32, copy=False)<EOL>del(lstFuncVar)<EOL>aryLgcAvg = np.greater(aryFuncAvg,<EOL>np.array([varAvgThr]).astype(np.float32)[<NUM_LIT:0>])<EOL>vecLgcAvg = np.all(aryLgcAvg, axis=<NUM_LIT:1>)<EOL>aryLgcVar = np.greater(aryFuncVar,<EOL>np.array([varVarThr]).astype(np.float32)[<NUM_LIT:0>])<EOL>vecLgcVar = np.all(aryLgcVar, axis=<NUM_LIT:1>)<EOL>vecLgcNan = np.invert(np.any(np.isnan(aryFunc), axis=<NUM_LIT:1>))<EOL>vecLgcIncl = np.logical_and(vecLgcAvg, vecLgcVar)<EOL>vecLgcIncl = np.logical_and(vecLgcIncl, vecLgcNan)<EOL>aryFunc = aryFunc[vecLgcIncl, :]<EOL>print('<STR_LIT>' +<EOL>str(varAvgThr))<EOL>print('<STR_LIT>' +<EOL>str(varVarThr))<EOL>print('<STR_LIT>' +<EOL>str(np.sum(np.invert(vecLgcIncl))))<EOL>return aryLgcMsk, vecLgcIncl, hdrMsk, aryAff, aryFunc, tplNiiShp<EOL>
Load & prepare functional data.

Parameters
----------
strPathNiiMask: str
    Path to mask used to restrict pRF model finding. Only voxels with
    a value greater than zero in the mask are considered.
lstPathNiiFunc : list
    List of paths of functional data (nii files).
varAvgThr : float, positive, default = 100.
    Float. Voxels that have at least one run with a mean lower than this
    (before demeaning) will be excluded from model fitting.
varVarThr : float, positive, default = 0.0001
    Float. Voxels that have at least one run with a variance lower than
    this (after demeaning) will be excluded from model fitting.
strPrePro : string, default 'demean'
    Preprocessing that will be applied to the data.
    By default they are demeaned.

Returns
-------
aryLgcMsk : np.array
    3D numpy array with logial values. Externally supplied mask (e.g grey
    matter mask). Voxels that are `False` in the mask are excluded.
vecLgcIncl : np.array
    1D numpy array containing logical values. One value per voxel after
    mask has been applied. If `True`, the variance and mean of the voxel's
    time course are greater than the provided thresholds in all runs and
    the voxel is included in the output array (`aryFunc`). If `False`, the
    variance or mean of the voxel's time course is lower than threshold in
    at least one run and the voxel has been excluded from the output
    (`aryFunc`). This is to avoid problems in the subsequent model fitting.
    This array is necessary to put results into original dimensions after
    model fitting.
hdrMsk : nibabel-header-object
    Nii header of mask.
aryAff : np.array
    Array containing 'affine', i.e. information about spatial positioning
    of mask nii data.
aryFunc : np.array
    2D numpy array containing prepared functional data, of the form
    aryFunc[voxelCount, time].
tplNiiShp : tuple
    Spatial dimensions of input nii data (number of voxels in x, y, z
    direction). The data are reshaped during preparation, this
    information is needed to fit final output into original spatial
    dimensions.

Notes
-----
Functional data is loaded from disk. The functional data is reshaped, into
the form aryFunc[voxel, time]. A mask is applied (externally supplied, e.g.
a grey matter mask). Subsequently, the functional data is de-meaned.