def export_nii(ary2dNii, lstNiiNames, aryLgcMsk, aryLgcVar, tplNiiShp, aryAff,<EOL>hdrMsk, outFormat='<STR_LIT>'):
<EOL>varNumVoxMsk = np.sum(aryLgcMsk)<EOL>varNumMaps = ary2dNii.shape[-<NUM_LIT:1>]<EOL>aryPrfRes01 = np.zeros((varNumVoxMsk, varNumMaps), dtype=np.float32)<EOL>for indMap in range(varNumMaps):<EOL><INDENT>aryPrfRes01[aryLgcVar, indMap] = ary2dNii[:, indMap]<EOL><DEDENT>varNumVoxTlt = (tplNiiShp[<NUM_LIT:0>] * tplNiiShp[<NUM_LIT:1>] * tplNiiShp[<NUM_LIT:2>])<EOL>aryPrfRes02 = np.zeros((varNumVoxTlt, aryPrfRes01.shape[-<NUM_LIT:1>]),<EOL>dtype=np.float32)<EOL>for indDim in range(aryPrfRes01.shape[-<NUM_LIT:1>]):<EOL><INDENT>aryPrfRes02[aryLgcMsk, indDim] = aryPrfRes01[:, indDim]<EOL><DEDENT>aryPrfRes = np.reshape(aryPrfRes02,<EOL>[tplNiiShp[<NUM_LIT:0>],<EOL>tplNiiShp[<NUM_LIT:1>],<EOL>tplNiiShp[<NUM_LIT:2>],<EOL>aryPrfRes01.shape[-<NUM_LIT:1>]])<EOL>if outFormat == '<STR_LIT>':<EOL><INDENT>for idxOut in range(<NUM_LIT:0>, aryPrfRes.shape[-<NUM_LIT:1>]):<EOL><INDENT>niiOut = nb.Nifti1Image(aryPrfRes[..., idxOut],<EOL>aryAff,<EOL>header=hdrMsk<EOL>)<EOL>strTmp = lstNiiNames[idxOut]<EOL>nb.save(niiOut, strTmp)<EOL><DEDENT><DEDENT>elif outFormat == '<STR_LIT>':<EOL><INDENT>hdrMsk.set_data_shape(aryPrfRes.shape)<EOL>niiOut = nb.Nifti1Image(aryPrfRes,<EOL>aryAff,<EOL>header=hdrMsk<EOL>)<EOL>strTmp = lstNiiNames[<NUM_LIT:0>]<EOL>nb.save(niiOut, strTmp)<EOL><DEDENT>
Export nii file(s).

Parameters
----------
ary2dNii : numpy array
    Numpy array with results to be exported to nii.
lstNiiNames : list
    List that contains strings with the complete file names.
aryLgcMsk : numpy array
    If the nii file is larger than this threshold (in MB), the file is
    loaded volume-by-volume in order to prevent memory overflow. Default
    threshold is 1000 MB.
aryLgcVar : 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.
tplNiiShp : tuple
    Tuple that describes the 3D shape of the output volume
aryAff : np.array
    Array containing 'affine', i.e. information about spatial positioning
    of nii data.
hdrMsk : nibabel-header-object
    Nii header of mask.
outFormat : string, either '3D' or '4D'
    String specifying whether images will be saved as seperate 3D nii
    files or one 4D nii file

Notes
-----
[1] This function does not return any arrays but instead saves to disk.
[2] Depending on whether outFormat is '3D' or '4D' images will be saved as
    seperate 3D nii files or one 4D nii file.