Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 = espirit.espirit_maps(ksp,
output_eigenvalue=True)
np.testing.assert_allclose(eig_val, 1, rtol=0.01, atol=0.01)
def test_noncart_sense_model_batch(self):
img_shape = [16, 16]
mps_shape = [8, 16, 16]
img = sp.randn(img_shape, dtype=np.complex)
mps = sp.randn(mps_shape, dtype=np.complex)
y, x = np.mgrid[:16, :16]
coord = np.stack([np.ravel(y - 8), np.ravel(x - 8)], axis=1)
coord = coord.astype(np.float)
A = linop.Sense(mps, coord=coord, coil_batch_size=1)
check_linop_adjoint(A, dtype=np.complex)
npt.assert_allclose(sp.fft(img * mps, axes=[-1, -2]).ravel(),
(A * img).ravel(), atol=0.1, rtol=0.1)
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 shepp_logan_setup(self):
img_shape = [6, 6]
mps_shape = [4, 6, 6]
img = sp.shepp_logan(img_shape)
mps = sim.birdcage_maps(mps_shape)
mask = np.zeros(img_shape)
mask[:, ::2] = 1
ksp = mask * sp.fft(mps * img, axes=[-2, -1])
return img, mps, ksp
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 = espirit.espirit_maps(ksp)
np.testing.assert_allclose(np.abs(mps)[:, 8:24, 8:24],
np.abs(mps_rec[:, 8:24, 8:24]),
rtol=1e-3, atol=1e-3)
def test_ones_JsenseRecon(self):
img_shape = [6, 6]
mps_shape = [4, 6, 6]
img = np.ones(img_shape, dtype=np.complex)
mps = sim.birdcage_maps(mps_shape)
ksp = sp.fft(mps * img, axes=[-2, -1])
_app = app.JsenseRecon(ksp, mps_ker_width=6, ksp_calib_width=6,
show_pbar=False)
mps_rec = _app.run()
npt.assert_allclose(mps, mps_rec, atol=1e-2, rtol=1e-2)
else:
ones[idx] = weights**0.5
psf = sp.ifft(ones)
else:
coord2 = coord * 2
ones = xp.ones(coord.shape[:-1], dtype=dtype)
if weights is not None:
ones *= weights**0.5
psf = sp.nufft_adjoint(ones, coord2, img2_shape)
p_inv = 0
for mps_i in mps:
mps_i = sp.to_device(mps_i, device)
xcorr_fourier = xp.abs(sp.fft(xp.conj(mps_i), img2_shape))**2
xcorr = sp.ifft(xcorr_fourier)
xcorr *= psf
p_inv_i = sp.fft(xcorr)
p_inv_i = p_inv_i[idx]
p_inv_i *= scale
if weights is not None:
p_inv_i *= weights**0.5
p_inv += p_inv_i
p_inv += lamda
p_inv[p_inv == 0] = 1
p = 1 / p_inv
return p.astype(dtype)
def time_fft(self):
y = sp.fft(self.x)
def __getitem__(self, slc):
with self.device:
if isinstance(slc, int):
mps_c = sp.fft.ifft(
self.mps_ker[slc], oshape=self.img_mask.shape)
mps_c *= self.img_mask
return mps_c
elif isinstance(slc, slice):
return SenseMaps(self.mps_ker[slc], self.img_mask, device=self.device)
elif isinstance(slc, tuple) or isinstance(slc, list):
if isinstance(slc[0], int):
mps = sp.fft.ifft(
self.mps_ker[slc[0]], oshape=self.img_mask.shape)
mps *= self.img_mask
return mps[slc[1:]]
def time_fft_non_centered(self):
y = sp.fft(self.x, center=False)