Skip to content

Commit

Permalink
add 'first' and 'last' arg to make_arbitrary_grad
Browse files Browse the repository at this point in the history
  • Loading branch information
schuenke authored and FrankZijlstra committed Aug 29, 2024
1 parent c6d4eff commit 6d4f59b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pypulseq/make_arbitrary_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
def make_arbitrary_grad(
channel: str,
waveform: np.ndarray,
first: Union[float, None] = None,
last: Union[float, None] = None,
delay: float = 0,
max_grad: Union[float, None] = None,
max_slew: Union[float, None] = None,
Expand All @@ -30,6 +32,12 @@ def make_arbitrary_grad(
Orientation of gradient event of arbitrary shape. Must be one of `x`, `y` or `z`.
waveform : numpy.ndarray
Arbitrary waveform.
first : float
Gradient value at the start of the gradient event. (t=0)
Will default to a linear extrapolated value if not provided.
last : float
Gradient value at the end of the gradient event. (t=duration)
Will default to a linear extrapolated value if not provided.
system : Opts
System limits.
Will default to `pypulseq.opts.default` if not provided.
Expand Down Expand Up @@ -72,15 +80,21 @@ def make_arbitrary_grad(
if max(abs(waveform)) >= max_grad:
raise ValueError(f"Gradient amplitude violation {max(abs(waveform)) / max_grad * 100}")

if not first:
first = (3 * waveform[0] - waveform[1]) * 0.5 # linear extrapolation

if not last:
last = (3 * waveform[-1] - waveform[-2]) * 0.5 # linear extrapolation

grad = SimpleNamespace()
grad.type = "grad"
grad.channel = channel
grad.waveform = waveform
grad.delay = delay
grad.tt = (np.arange(len(waveform)) + 0.5) * system.grad_raster_time
grad.shape_dur = len(waveform) * system.grad_raster_time
grad.first = (3 * waveform[0] - waveform[1]) * 0.5 # Extrapolate by 1/2 gradient raster
grad.last = (waveform[-1] * 3 - waveform[-2]) * 0.5 # Extrapolate by 1/2 gradient raster
grad.first = first
grad.last = last
grad.area = (waveform * system.grad_raster_time).sum()

return grad

0 comments on commit 6d4f59b

Please sign in to comment.