# something other than the image we're going to reconstruct, but # since this is just proof of concept, we'll go ahead cx = kx.copy() cy = ky.copy() calib = k.copy() # calib = np.tile(calib[:, None, :], (1, 2, 1)) calib = calib[:, None, :] # middle axis is the through-time dim # Undersample: R=2 k[::2] = 0 # Reconstruct with Non-Cartesian GRAPPA res = ttgrappa( kx, ky, k, cx, cy, calib, kernel_size=25, coil_axis=-1) # Let's take a look sos = lambda x0: np.sqrt(np.sum(np.abs(x0)**2, axis=-1)) gridder0 = lambda x0: gridder(kx, ky, x0, sx=sx, sy=sx) plt.subplot(1, 3, 1) plt.imshow(sos(gridder0(k))) plt.title('Undersampled') plt.subplot(1, 3, 2) plt.imshow(sos(gridder0(kspace.reshape((-1, nc))))) plt.title('True') plt.subplot(1, 3, 3) plt.imshow(sos(gridder0(res))) plt.title('Through-time GRAPPA') plt.show()
# Do the thing t0 = time() bart_imspace = bart_nufft(bart_k) bart_time = time() - t0 # Check it out plt.figure() plt.imshow(sos(bart_imspace)) plt.title('BART NUFFT') plt.xlabel('Recon: %g sec' % bart_time) plt.show(block=False) # The phantominator module also supports arbitrary kspace # sampling for multiple coils: kx, ky = radial(sx, spokes) k = kspace_shepp_logan(kx, ky, ncoil=nc) # We will prefer a gridding approach to keep things simple. The # helper function gridder wraps scipy.interpolate.griddata(): t0 = time() grid_imspace = gridder(kx, ky, k, sx, sx, os=os, method=method) grid_time = time() - t0 # Take a gander plt.figure() plt.imshow(sos(grid_imspace)) plt.title('scipy.interpolate.griddata') plt.xlabel('Recon: %g sec' % grid_time) plt.show()
t0 = time() res_cart = grog(kx, ky, k, 2 * N, 2 * N, Gx, Gy) print('Gridded in %g seconds' % (time() - t0)) # Now back to radial (inverse GROG) res_radial = grog(kx, ky, np.reshape(res_cart, (-1, nc), order='F'), 2 * N, 2 * N, Gx, Gy, inverse=True) # Make sure we gridded something recognizable nx, ny = 1, 3 plt.subplot(nx, ny, 1) plt.imshow(sos(gridder(kx, ky, k, N, N))) plt.title('Radial Truth') plt.subplot(nx, ny, 2) N2 = int(N / 2) plt.imshow(sos(ifft(res_cart))[N2:-N2, N2:-N2]) plt.title('GROG Cartesian') plt.subplot(nx, ny, 3) plt.imshow(sos(gridder(kx, ky, res_radial, N, N))) plt.title('GROG Radial (Inverse)') plt.show()
hysplit_file_list = utils.get_hysplit_files(run_date=run_date, run_hours=hours) utils.write_control_file(start_time=run_date, coords=location_list, hyfile_list=hysplit_file_list, hours=hours, vertical_type=vertical_type, init_height=init_height, tdumpdir=utils.trajectory_dir) print 'calling HYSPLIT' call(utils.HYSPLIT_call, shell=False, cwd=utils.HYSPLIT_workdir) if __name__ == "__main__": grid_coords = utils.gridder([27, -130], [36, -137], [41, -128], [32, -121], numlats=5, numlons=6) # utils.plot_gridpoints(grid_coords) date_list = [dt.datetime(2015, 7, 01) + dt.timedelta(x) for x in range(0, 60)] loop = lt(len(date_list)) fig, ax, m_ax = utils.make_map_plot() # date_list = [dt.datetime(2015, 8, 19) + dt.timedelta(x) for x in range(0, 2)] for i, date in enumerate(date_list): loop.update(i) if False: run_trajectories(date, grid_coords) if True: t_name = os.path.join(utils.trajectory_dir, 'tdump'+date.strftime('%Y%m%dH%H%M'))
sx, spokes, nc = 256, 256, 8 traj = bart(1, 'traj -r -x%d -y%d' % (sx, spokes)) kx, ky = traj[0, ...].real.flatten(), traj[1, ...].real.flatten() # Use BART to get Shepp-Logan and sensitivity maps t0 = time() k = bart(1, 'phantom -k -s%d -t' % nc, traj).reshape((-1, nc)) print('Took %g seconds to simulate %d coils' % (time() - t0, nc)) sens = bart(1, 'phantom -S%d -x%d' % (nc, sx)).squeeze() # Undersample ku = k.copy() ku[::2] = 0 # Take a looksie sos = lambda x0: np.sqrt(np.sum(np.abs(x0)**2, axis=-1)) plt.subplot(1, 3, 1) plt.imshow(sos(gridder(kx, ky, k, sx, sx))) plt.title('Truth') plt.subplot(1, 3, 2) plt.imshow(sos(gridder(kx, ky, ku, sx, sx))) plt.title('Undersampled') plt.subplot(1, 3, 3) res = pars(kx, ky, ku, sens, kernel_radius=.8) plt.imshow(sos(res)) plt.title('PARS') plt.show()
def _gridder0(x0): return gridder(kx, ky, x0, sx=sx, sy=sx)