def test_espirit_maps_eig(self): mps_shape = [8, 32, 32] mps = sim.birdcage_maps(mps_shape) ksp = sp.fft(mps, axes=[-1, -2]) mps_rec, eig_val = app.EspiritCalib(ksp, output_eigenvalue=True, show_pbar=False).run() np.testing.assert_allclose(eig_val, 1, rtol=0.01, atol=0.01)
def test_espirit_maps(self): mps_shape = [8, 32, 32] mps = sim.birdcage_maps(mps_shape) ksp = sp.fft(mps, axes=[-1, -2]) mps_rec = app.EspiritCalib(ksp, show_pbar=False).run() np.testing.assert_allclose(np.abs(mps)[:, 8:24, 8:24], np.abs(mps_rec[:, 8:24, 8:24]), rtol=1e-2, atol=1e-2)
def process_slice(kspace, args, calib_method='jsense'): # get data dimensions nky, nkz, nechoes, ncoils = kspace.shape # ESPIRiT parameters nmaps = args.num_emaps calib_size = args.ncalib crop_value = args.crop_value if args.device is -1: device = sp.cpu_device else: device = sp.Device(args.device) # compute sensitivity maps (BART) #cmd = f'ecalib -d 0 -S -m {nmaps} -c {crop_value} -r {calib_size}' #maps = bart.bart(1, cmd, kspace[:,:,0,None,:]) #maps = np.reshape(maps, (nky, nkz, 1, ncoils, nmaps)) # compute sensitivity maps (SigPy) ksp = np.transpose(kspace[:, :, 0, :], [2, 1, 0]) if calib_method is 'espirit': maps = app.EspiritCalib(ksp, calib_width=calib_size, crop=crop_value, device=device, show_pbar=False).run() elif calib_method is 'jsense': maps = app.JsenseRecon(ksp, mps_ker_width=6, ksp_calib_width=calib_size, device=device, show_pbar=False).run() else: raise ValueError('%s calibration method not implemented...' % calib_method) maps = np.reshape(np.transpose(maps, [2, 1, 0]), (nky, nkz, 1, ncoils, nmaps)) # Convert everything to tensors kspace_tensor = cplx.to_tensor(kspace).unsqueeze(0) maps_tensor = cplx.to_tensor(maps).unsqueeze(0) # Do coil combination using sensitivity maps (PyTorch) A = T.SenseModel(maps_tensor) im_tensor = A(kspace_tensor, adjoint=True) # Convert tensor back to numpy array image = cplx.to_numpy(im_tensor.squeeze(0)) return image, maps