def test_wfi_dualR2s(): filename = '/Users/mnd/Projects/FatParameterEstimation/data/DiagnostikBilanz/20170609_125718_0402_ImDataParams.mat' imDataParams = h5io.load_ImDataParams_mat(filename) imDataParams = imDataParams['ImDataParams'] filename = '/Users/mnd/Projects/FatParameterEstimation/data/DiagnostikBilanz/20170609_125718_0402_WFIparams_CSS_GANDALF2D_VL.mat' wfiParams = h5io.load_WFIparams_mat(filename) fieldmap_Hz = np.transpose(wfiParams['WFIparams']['fieldmap_Hz']) fieldmap_Hz_equalized = wfi.equalize_fieldmap_periods(fieldmap_Hz, imDataParams['TE_s']) options = {'init_fieldmap_Hz': fieldmap_Hz_equalized, 'iSlice': slice(35, 37)} wfiParams = wfi.wfi_css_varpro(imDataParams, options) assert {'water', 'fat', 'fieldmap_Hz', 'R2s_Hz', 'pdff_percent'}.\ issubset(wfiParams.keys()) Cr = np.eye(len(wfiParams['Cr']), 2) Cr[1:, 1] = 1 options2 = wfiParams.copy() options2.pop('water') options2.pop('fat') options2.pop('pdff_percent') options2.pop('fieldmap_Hz') options2.pop('R2s_Hz') options2.pop('param_maps') options2.pop('resnorm') options2.pop('iterations') options2.update({'Cr': Cr}) wfiParams2 = wfi.wfi_css_varpro(imDataParams, options2) close_all() show_arr3d(np.clip(wfiParams['pdff_percent'], 0, 100)) show_arr3d(np.clip(wfiParams2['pdff_percent'], 0, 100)) close_all() show_arr3d(np.clip(wfiParams['R2s_Hz'], 0, 400)) show_arr3d(np.clip(wfiParams2['R2s_Hz'], 0, 400)) show_arr3d(np.clip(wfiParams2['param_maps'][6], 0, 400)) close_all() show_arr3d(np.clip(wfiParams['fieldmap_Hz'], -400, 200)) show_arr3d(np.clip(wfiParams2['fieldmap_Hz'], -400, 200)) close_all() show_arr3d(np.clip(wfiParams['resnorm'], 0, 1e2)) show_arr3d(np.clip(wfiParams2['resnorm'], 0, 1e2)) close_all() show_arr3d(np.clip(wfiParams['iterations'], 0, 1e2)) show_arr3d(np.clip(wfiParams2['iterations'], 0, 1e2))
def test_dualR2s_wat(): filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/BMR/BMR106_EN/20171013_131406_1302_ImDataParams.mat' imDataParams = h5io.load_ImDataParams_mat(filename) imDataParams = imDataParams['ImDataParams'] filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/BMR/BMR106_EN/20171013_131406_1302_WFIparams_GANDALF3D_VL.mat' wfiParams = h5io.load_WFIparams_mat(filename) fieldmap_Hz = np.transpose(wfiParams['WFIparams']['fieldmap_Hz']) fieldmap_Hz_equalized = wfi.equalize_fieldmap_periods(fieldmap_Hz, imDataParams['TE_s']) options = {'init_fieldmap_Hz': fieldmap_Hz_equalized, 'iSlice': slice(35, 37)} wfiParams = wfi.wfi_css_varpro(imDataParams, options) Cr = np.eye(len(wfiParams['Cr']), 2) Cr[1:, 1] = 1 wfiParams2 = wfi.wfi_css_varpro(imDataParams, options2) close_all() show_arr3d(np.clip(wfiParams['pdff_percent'], 0, 100)) show_arr3d(np.clip(wfiParams2['pdff_percent'], 0, 100)) close_all() show_arr3d(np.clip(wfiParams['R2s_Hz'], 0, 400)) show_arr3d(np.clip(wfiParams2['R2s_Hz'], 0, 400)) show_arr3d(np.clip(wfiParams2['param_maps'][6], 0, 400)) close_all() show_arr3d(np.clip(wfiParams['fieldmap_Hz'], -400, 200)) show_arr3d(np.clip(wfiParams2['fieldmap_Hz'], -400, 200)) close_all() show_arr3d(np.clip(wfiParams['resnorm'], 0, 1e2)) show_arr3d(np.clip(wfiParams2['resnorm'], 0, 1e2)) close_all() show_arr3d(np.clip(wfiParams['iterations'], 0, 1e2)) show_arr3d(np.clip(wfiParams2['iterations'], 0, 1e2))
def test_wfi_css_varpro_wuq(): filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/BMR/BMR106_EN/20171013_131406_1302_ImDataParams.mat' imDataParams = h5io.load_ImDataParams_mat(filename) imDataParams = imDataParams['ImDataParams'] filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/BMR/BMR106_EN/20171013_131406_1302_WFIparams_GANDALF3D_VL.mat' wfiParams = h5io.load_WFIparams_mat(filename) fieldmap_Hz = np.transpose(wfiParams['WFIparams']['fieldmap_Hz']) fieldmap_Hz_equalized = wfi.equalize_fieldmap_periods(fieldmap_Hz, imDataParams['TE_s']) options = {'init_fieldmap_Hz': fieldmap_Hz_equalized, 'iSlice': slice(35, 37), 'iTE': slice(2, 20), 'uncertainty_quant': True} wfiParams = wfi.wfi_css_varpro(imDataParams, options) show_arr3d(wfi.calculate_echoMIP(imDataParams['signal'])) print(wfiParams.keys()) crlb = wfiParams['CRLBs'][0] assert len(wfiParams['CRLBs']) == 6 close_all() show_arr3d(np.log(wfiParams['CRLBs'][0])) show_arr3d(np.log(wfiParams['CRLBs'][1])) show_arr3d(np.log(wfiParams['CRLBs'][2])) show_arr3d(np.log(wfiParams['CRLBs'][3])) show_arr3d(np.log(wfiParams['CRLBs'][4])) show_arr3d(np.log(wfiParams['CRLBs'][5])) close_all() show_arr3d(wfiParams['NSAs'][0]) show_arr3d(wfiParams['NSAs'][1]) show_arr3d(wfiParams['NSAs'][2]) show_arr3d(wfiParams['NSAs'][3]) show_arr3d(wfiParams['NSAs'][4]) show_arr3d(wfiParams['NSAs'][5]) trF = wfiParams['trFIM'] trInvF = wfiParams['trInvFIM'] detF = wfiParams['detFIM'] detInvF = np.divide(1, detF, out=-np.ones_like(detF), where=detF!=0) close_all() show_arr3d(np.log(trF)) show_arr3d(-np.log(trInvF)) show_arr3d(np.log(detF)) show_arr3d(-np.log(detInvF))
def test_wfi_css_varpro(): filename = '/Users/mnd/Projects/FatParameterEstimation/data/DiagnostikBilanz/20170609_125718_0402_ImDataParams.mat' imDataParams = h5io.load_ImDataParams_mat(filename) imDataParams = imDataParams['ImDataParams'] filename = '/Users/mnd/Projects/FatParameterEstimation/data/DiagnostikBilanz/20170609_125718_0402_WFIparams_CSS_GANDALF2D_VL.mat' wfiParams = h5io.load_WFIparams_mat(filename) fieldmap_Hz = np.transpose(wfiParams['WFIparams']['fieldmap_Hz']) fieldmap_Hz_equalized = wfi.equalize_fieldmap_periods(fieldmap_Hz, imDataParams['TE_s']) options = {'init_fieldmap_Hz': fieldmap_Hz_equalized, 'iSlice': slice(35, 37)} wfiParams = wfi.wfi_css_varpro(imDataParams, options) assert {'water', 'fat', 'fieldmap_Hz', 'R2s_Hz', 'pdff_percent'}.\ issubset(wfiParams.keys()) close_all() show_arr3d(np.clip(wfiParams['pdff_percent'], 0, 100))
def test_fucl_bat(): filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/BMR/BMR106_EN/20171013_124742_0502_ImDataParams.mat' imDataParams = h5io.load_ImDataParams_mat(filename) imDataParams = imDataParams['ImDataParams'] filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/BMR/BMR106_EN/20171013_124742_0502_WFIparams_GANDALF3D_VL.mat' wfiParams = h5io.load_WFIparams_mat(filename) for k in wfiParams['WFIparams'].keys(): print(k) fieldmap_Hz = np.transpose(wfiParams['WFIparams']['fieldmap_Hz']) echoMIP = wfi.calculate_echoMIP(imDataParams['signal']) options = {'init_fieldmap_Hz': fieldmap_Hz, 'iSlice': slice(17, 21), 'fatmodel': 'Hamilton sSAT', 'tol': 1e-3, 'itermax': 20} F = Fatmodel(modelname='Berglund 10 peaks') F.compute_fatmodel(cl=18.5, ndb=2.73, nmidb=0.76) F.set_constraints_matrices() Cm = np.array([[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 2/3, 0, 0, 0], [0, 0, 0, 1, 0], [0, 2/3, 0, 0, 0], [0, 0, 0, 0, 1], [0, 2/9, 0, 0, 0], [0, 2/9, 0, 0, 0], [0, 1/9, 0, 0, 0], [0, 0, 0, 1/2, 1]]) Cp = (Cm > 0).astype(float) options['fatmodel'] = 'Berglund 10 peaks' options['Cm'] = Cm options['Cp'] = Cp fuclParams = wfi.wfi_css_varpro(imDataParams, options) close_all() show_arr3d(echoMIP) W = fuclParams['param_maps'][0] * np.exp(1.j * fuclParams['param_maps'][5]) F1 = fuclParams['param_maps'][1] * np.exp(1.j * fuclParams['param_maps'][6]) F2 = fuclParams['param_maps'][2] * np.exp(1.j * fuclParams['param_maps'][7]) F3 = fuclParams['param_maps'][3] * np.exp(1.j * fuclParams['param_maps'][8]) F4 = fuclParams['param_maps'][4] * np.exp(1.j * fuclParams['param_maps'][9]) show_arr3d(np.abs(W)) show_arr3d(np.abs(F1)) show_arr3d(np.abs(F2)) show_arr3d(np.abs(F3)) show_arr3d(np.abs(F4)) fieldmap_Hz = fuclParams['param_maps'][10] R2s_Hz = fuclParams['param_maps'][11] show_arr3d(fieldmap_Hz) show_arr3d(R2s_Hz) show_arr3d(fuclParams['resnorm']) show_arr3d(fuclParams['iterations']) F1nonzero = F1 != 0 null = np.zeros_like(F1nonzero, dtype=np.complex128) CL = 4 + np.abs(np.divide((F2 + 4 * F3 + 3 * F4) / 3, F1, out=null, where=F1nonzero)) UD = np.abs(np.divide(F3 + F4, F1, out=null, where=F1nonzero)) SF = 1 - np.abs(np.divide(F3 / 3, F1, out=null, where=F1nonzero)) PUD = np.abs(np.divide(F4, F1, out=null, where=F1nonzero)) PUF = PUD / 3 UF = np.abs(np.divide(F3 / 3, F1, out=null, where=F1nonzero)) MUF = UF - PUF show_arr3d(CL) show_arr3d(UD) show_arr3d(SF) show_arr3d(PUD) show_arr3d(PUF) show_arr3d(UF) show_arr3d(MUF)
def test_contrainedPhase(): filename = '/Users/mnd/Projects/FatParameterEstimation/data/DiagnostikBilanz/20170609_125718_0402_ImDataParams.mat' imDataParams = h5io.load_ImDataParams_mat(filename) imDataParams = imDataParams['ImDataParams'] filename = '/Users/mnd/Projects/FatParameterEstimation/data/DiagnostikBilanz/20170609_125718_0402_WFIparams_CSS_GANDALF2D_VL.mat' wfiParams = h5io.load_WFIparams_mat(filename) fieldmap_Hz = np.transpose(wfiParams['WFIparams']['fieldmap_Hz']) fieldmap_Hz_equalized = wfi.equalize_fieldmap_periods(fieldmap_Hz, imDataParams['TE_s']) options = {'init_fieldmap_Hz': fieldmap_Hz_equalized, 'iSlice': slice(35, 37)} wfiParams = wfi.wfi_css_varpro(imDataParams, options) assert {'water', 'fat', 'fieldmap_Hz', 'R2s_Hz', 'pdff_percent'}.\ issubset(wfiParams.keys()) options2 = options.copy() Cp = np.zeros((10, 1)) Cp[:, 0] = 1. options2['Cp'] = Cp wfiParams2 = wfi.wfi_css_varpro(imDataParams, options2) close_all() show_arr3d(np.clip(wfiParams['pdff_percent'], 0, 100)) show_arr3d(np.clip(wfiParams2['pdff_percent'], 0, 100)) show_arr3d(np.clip(wfiParams2['pdff_percent'], 0, 100) - \ np.clip(wfiParams['pdff_percent'], 0, 100)) close_all() show_arr3d(np.angle(wfiParams['water'])) show_arr3d(np.angle(wfiParams['fat'])) show_arr3d(np.angle(wfiParams2['water'])) show_arr3d(np.angle(wfiParams2['fat'])) assert ~np.allclose(np.angle(wfiParams['water']), np.angle(wfiParams['fat'])) assert np.allclose(np.angle(wfiParams2['water']), np.angle(wfiParams2['fat'])) close_all() show_arr3d(np.clip(wfiParams['R2s_Hz'], 0, 400)) show_arr3d(np.clip(wfiParams2['R2s_Hz'], 0, 400)) show_arr3d(np.clip(wfiParams2['R2s_Hz'], 0, 400) - \ np.clip(wfiParams['R2s_Hz'], 0, 400)) close_all() show_arr3d(np.clip(wfiParams['fieldmap_Hz'], -400, 200)) show_arr3d(np.clip(wfiParams2['fieldmap_Hz'], -400, 200)) show_arr3d(np.clip(wfiParams2['R2s_Hz'], -400, 200) - \ np.clip(wfiParams['R2s_Hz'], -400, 200)) close_all() show_arr3d(np.clip(wfiParams['resnorm'], 0, 1e2)) show_arr3d(np.clip(wfiParams2['resnorm'], 0, 1e2)) close_all() show_arr3d(wfiParams['iterations'], ) show_arr3d(wfiParams2['iterations'])
def test_wfi_css_varpro_wuq_dualR2s(): filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/BMR/BMR106_EN/20171013_131406_1302_ImDataParams.mat' imDataParams = h5io.load_ImDataParams_mat(filename) imDataParams = imDataParams['ImDataParams'] imDataParams['TE_s'] = imDataParams['TE_s'].ravel() filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/BMR/BMR106_EN/20171013_131406_1302_WFIparams_GANDALF3D_VL.mat' wfiParams = h5io.load_WFIparams_mat(filename) fieldmap_Hz = np.transpose(wfiParams['WFIparams']['fieldmap_Hz']) fieldmap_Hz_equalized = wfi.equalize_fieldmap_periods(fieldmap_Hz, imDataParams['TE_s']) options = {'init_fieldmap_Hz': fieldmap_Hz_equalized, 'iSlice': slice(35, 37), 'iTE': slice(4, 16), 'uncertainty_quant': True} wfiParams = wfi.wfi_css_varpro(imDataParams, options) options2 = options.copy() options2.update({'Cr': np.array([[1., 0.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.], [0., 1.]])}) wfiParams2 = wfi.wfi_css_varpro(imDataParams, options2) FIMparams = css.compute_FIMmaps(imDataParams['TE_s'], wfiParams['params_matrices'], wfiParams['Cm'], wfiParams['Cp'], wfiParams['Cf'], wfiParams['Cr'], wfiParams['mask']) FIMparams2 = css.compute_FIMmaps(imDataParams['TE_s'], wfiParams['params_matrices'], wfiParams['Cm'], wfiParams['Cp'], wfiParams['Cf'], wfiParams2['Cr'], wfiParams['mask']) close_all() show_arr3d(np.log(FIMparams['CRLBs'][0])) show_arr3d(np.log(FIMparams2['CRLBs'][0])) close_all() show_arr3d(np.log(FIMparams['trFIM'])) show_arr3d(np.log(FIMparams2['trFIM'])) show_arr3d(np.log(FIMparams['trFIM']) - np.log(FIMparams2['trFIM'])) echoMIP = wfi.calculate_echoMIP(imDataParams['signal'][:, :, 35:37, 4:16]) diff_dict = {} for k in ['CRLBs', 'NSAs']: diff_dict[k] = np.array(wfiParams[k]) - np.array(wfiParams2[k][:-1]) for k in ['trFIM', 'trInvFIM', 'detFIM']: diff_dict[k] = np.array(wfiParams[k]) - np.array(wfiParams2[k]) show_arr3d(diff_dict['CRLBs'][0]) show_arr3d(diff_dict['CRLBs'][1]) show_arr3d(diff_dict['CRLBs'][2]) show_arr3d(diff_dict['CRLBs'][3]) show_arr3d(diff_dict['CRLBs'][4]) show_arr3d(diff_dict['CRLBs'][5]) show_arr3d(diff_dict['trFIM']) close_all() maptofuse = 'pdff_percent' # maptofuse = 'fieldmap_Hz' vmin, vmax = 0, 100 # vmin, vmax = -400, 200 wheretofuse = FIMparams['trFIM'] >= FIMparams2['trFIM'] # wheretofuse = FIMparams['detFIM'] >= FIMparams2['detFIM'] # wheretofuse = FIMparams['trInvFIM'] <= FIMparams2['trInvFIM'] # wheretofuse = FIMparams['detInvFIM'] <= FIMparams2['detInvFIM'] # wheretofuse = FIMparams['NSAs'][5] >= FIMparams2['NSAs'][5] frankenstein = np.where(wheretofuse, wfiParams[maptofuse], wfiParams2[maptofuse]) show_arr3d(wfiParams[maptofuse]) show_arr3d(wfiParams2[maptofuse]) show_arr3d(wheretofuse * echoMIP) show_arr3d(np.clip(frankenstein, vmin, vmax)) show_arr3d(np.clip(frankenstein, vmin, vmax) - np.clip(wfiParams[maptofuse], vmin, vmax)) show_arr3d(wfiParams['resnorm']) close_all() maptofuse = 'fat' vmin, vmax = 0, 200 wheretofuse = FIMparams['detFIM'] >= FIMparams2['detFIM'] frankenstein = np.where(wheretofuse, wfiParams[maptofuse], wfiParams2[maptofuse]) show_arr3d(wheretofuse * echoMIP) show_arr3d(np.clip(wfiParams[maptofuse], vmin, vmax)) show_arr3d(np.clip(frankenstein, vmin, vmax)) show_arr3d(np.clip(frankenstein, vmin, vmax) - np.clip(wfiParams[maptofuse], vmin, vmax)) close_all() maptofuse = 'R2s_Hz' maptofuse2 = 'waterR2s_Hz' vmin, vmax = 0, 200 wheretofuse = FIMparams['detFIM'] >= FIMparams2['detFIM'] frankenstein = np.where(wheretofuse, wfiParams[maptofuse], wfiParams2[maptofuse2]) show_arr3d(wheretofuse * echoMIP) show_arr3d(np.clip(wfiParams[maptofuse], vmin, vmax)) show_arr3d(np.clip(frankenstein, vmin, vmax)) show_arr3d(np.clip(frankenstein, vmin, vmax) - np.clip(wfiParams[maptofuse], vmin, vmax)) close_all() maptofuse = 'R2s_Hz' maptofuse2 = 'fatR2s_Hz' vmin, vmax = 0, 200 wheretofuse = FIMparams['detFIM'] >= FIMparams2['detFIM'] frankenstein = np.where(wheretofuse, wfiParams[maptofuse], wfiParams2[maptofuse2]) show_arr3d(wheretofuse * echoMIP) show_arr3d(np.clip(wfiParams[maptofuse], vmin, vmax)) show_arr3d(np.clip(frankenstein, vmin, vmax)) show_arr3d(np.clip(frankenstein, vmin, vmax) - np.clip(wfiParams[maptofuse], vmin, vmax)) close_all() show_arr3d(np.log(FIMparams['detFIM'])) show_arr3d(np.log(FIMparams2['detFIM'])) show_arr3d(np.log(FIMparams['detFIM']) - np.log(FIMparams2['detFIM'])) show_arr3d(np.log(FIMparams['trFIM']) - np.log(FIMparams2['trFIM'])) show_arr3d(np.log(FIMparams['trInvFIM']) - np.log(FIMparams2['trInvFIM'])) show_arr3d(FIMparams['NSAs'][0] - FIMparams2['NSAs'][0]) show_arr3d(FIMparams['NSAs'][1] - FIMparams2['NSAs'][1]) show_arr3d(FIMparams['NSAs'][4] - FIMparams2['NSAs'][4]) show_arr3d(wfiParams['fieldmap_Hz'] - wfiParams2['fieldmap_Hz'])
echoMIP = wfi.calculate_echoMIP(imDataParams['signal']) filename = '/Users/mnd/Projects/FatParameterEstimation/data/FatParamEstimation/DiagnostikBilanz/20170609_125718_0402_WFIparams_CSS_GANDALF2D_VL.mat' wfiParams = h5io.load_WFIparams_mat(filename) fieldmap_Hz = np.transpose(wfiParams['WFIparams']['fieldmap_Hz']) fieldmap_Hz_equalized = wfi.equalize_fieldmap_periods(fieldmap_Hz, imDataParams['TE_s']) # single R2* options = { 'init_fieldmap_Hz': fieldmap_Hz_equalized, 'iSlice': slice(35, 36), 'uncertainty_quant': True } wfiParams = wfi.wfi_css_varpro(imDataParams, options) dd.io.save('wfiParams.h5', wfiParams) # wfiParams = dd.io.load('wfiParams.h5') # show_arr3d(np.clip(wfiParams['pdff_percent'], 0, 100)) # double R2* Cr = np.eye(len(wfiParams['Cr']), 2) Cr[1:, 1] = 1 options['Cr'] = Cr wfiParams2 = wfi.wfi_css_varpro(imDataParams, options) dd.io.save('wfiParams2.h5', wfiParams2) # wfiParams2 = dd.io.load('wfiParams2.h5') plt.close('all') fig, axs = plt.subplots(4, 2)