def load_nii(strPathIn, varSzeThr=<NUM_LIT>):
<EOL>objNii = nb.load(strPathIn)<EOL>varNiiSze = os.path.getsize(strPathIn)<EOL>varNiiSze = np.divide(float(varNiiSze), <NUM_LIT>)<EOL>if np.greater(varNiiSze, float(varSzeThr)):<EOL><INDENT>print(('<STR_LIT>'<EOL>+ str(np.around(varNiiSze))<EOL>+ '<STR_LIT>'))<EOL>tplSze = objNii.shape<EOL>aryNii = np.zeros(tplSze, dtype=np.float32)<EOL>for idxVol in range(tplSze[<NUM_LIT:3>]):<EOL><INDENT>aryNii[..., idxVol] = np.asarray(<EOL>objNii.dataobj[..., idxVol]).astype(np.float32)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>objNii = nb.load(strPathIn)<EOL>aryNii = np.asarray(objNii.dataobj).astype(np.float32)<EOL><DEDENT>objHdr = objNii.header<EOL>aryAff = objNii.affine<EOL>return aryNii, objHdr, aryAff<EOL>
Load nii file.

Parameters
----------
strPathIn : str
    Path to nii file to load.
varSzeThr : float
    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.

Returns
-------
aryNii : np.array
    Array containing nii data. 32 bit floating point precision.
objHdr : header object
    Header of nii file.
aryAff : np.array
    Array containing 'affine', i.e. information about spatial positioning
    of nii data.

Notes
-----
If the nii file is larger than the specified threshold (`varSzeThr`), the
file is loaded volume-by-volume in order to prevent memory overflow. The
reason for this is that nibabel imports data at float64 precision, which
can lead to a memory overflow even for relatively small files.