traj_to_grad#
- pypulseqpp.traj_to_grad()[source]#
Convert a k-space trajectory to gradient and slew-rate waveforms.
By default, samples describe geometry and MRArbGrad chooses the timing within vector gradient and slew limits; output length can differ from input length. With
time_optimal=False, samples already lie on the raster and are differentiated without limit enforcement.- Parameters:
k (numpy.ndarray) – K-space trajectory, time last: shape
(n,),(2, n)or(3, n), in 1/m.raster_time (float, default=None) – Gradient raster (s). Defaults to the system’s.
time_optimal (bool, default=True) – Re-parameterise the path within the limits rather than differentiate it.
system (pypulseqpp.Opts, default=None) – System limits; supplies
max_grad,max_slewand the raster.oversampling (int, default=8) – Path-resampling factor the solver works at.
start_at_zero (bool, default=True) – Ramp the waveform up from and back down to zero amplitude.
end_at_zero (bool, default=True) – Ramp the waveform up from and back down to zero amplitude.
- Returns:
g (numpy.ndarray) – Gradient waveform (Hz/m), same axis convention as
k.slew (numpy.ndarray) – Slew rate (Hz/m/s), one value per gradient sample.
Examples
An analytic spiral becomes a playable gradient:
>>> import numpy as np >>> import pypulseqpp as pp >>> system = pp.Opts(max_grad=40, grad_unit="mT/m", max_slew=150, slew_unit="T/m/s") >>> theta = np.linspace(0, 8 * np.pi, 2000) >>> radius = np.linspace(0, 250.0, 2000) >>> k = np.stack([radius * np.cos(theta), radius * np.sin(theta)]) >>> g, slew = pp.traj_to_grad(k, system=system) >>> bool(np.abs(np.linalg.norm(g, axis=0)).max() <= system.max_grad * 1.001) True
Then hand it to a factory per axis:
gx = pp.make_arbitrary_grad("x", g[0], system=system)
Differentiating instead, for a path already on the raster:
>>> g, slew = pp.traj_to_grad(k, system=system, time_optimal=False) >>> g.shape[1] == k.shape[1] - 1 True
See also
make_arbitrary_gradwrap one axis of the result as an event.