def save_results(respfile, Yhat, S2, maskvol, Z=None, outputsuffix=None, results=None, save_path=''): print("Writing outputs ...") if respfile is None: exfile = None file_ext = '.pkl' else: if fileio.file_type(respfile) == 'cifti' or \ fileio.file_type(respfile) == 'nifti': exfile = respfile else: exfile = None file_ext = fileio.file_extension(respfile) if outputsuffix is not None: ext = str(outputsuffix) + file_ext else: ext = file_ext fileio.save(Yhat, os.path.join(save_path, 'yhat' + ext), example=exfile, mask=maskvol) fileio.save(S2, os.path.join(save_path, 'ys2' + ext), example=exfile, mask=maskvol) if Z is not None: fileio.save(Z, os.path.join(save_path, 'Z' + ext), example=exfile, mask=maskvol) if results is not None: for metric in list(results.keys()): fileio.save(results[metric], os.path.join(save_path, metric + ext), example=exfile, mask=maskvol)
def load_response_vars(datafile, maskfile=None, vol=True): """ load response variables (of any data type)""" if fileio.file_type(datafile) == 'nifti': dat = fileio.load_nifti(datafile, vol=vol) volmask = fileio.create_mask(dat, mask=maskfile) Y = fileio.vol2vec(dat, volmask).T else: Y = fileio.load(datafile) volmask = None if fileio.file_type(datafile) == 'cifti': Y = Y.T return Y, volmask