Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes in make_extended_trapezoid and add_gradients #167

Merged
merged 6 commits into from
Feb 7, 2024
Merged
4 changes: 2 additions & 2 deletions pypulseq/add_gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def add_gradients(
else:
times.extend(g.delay + g.tt)

times = np.sort(np.unique(times))
times = np.unique(times)
dt = times[1:] - times[:-1]
ieps = np.flatnonzero(dt < eps)
if np.any(ieps):
Expand Down Expand Up @@ -140,7 +140,7 @@ def add_gradients(
if abs(waveform[0]) > eps and tt[0] > eps:
tt[0] += eps

amplitudes += np.interp(xp=tt, fp=waveform, x=times)
amplitudes += np.interp(xp=tt, fp=waveform, x=times, left=0, right=0)

grad = make_extended_trapezoid(
channel=channel, amplitudes=amplitudes, times=times, system=system
Expand Down
7 changes: 6 additions & 1 deletion pypulseq/event_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ def update(
data_type : str, default=str()
"""
if key_id in self.data:
del self.keymap[self.data[key_id]]
# TODO: When reading a sequence file we can end up with duplicate
# events due to rounding to 6 digits. update() calls to both
# duplicates would give a key error here on the second
# duplicate. Ideally no duplicates should exist though...
if self.data[key_id] in self.keymap:
del self.keymap[self.data[key_id]]

self.insert(key_id, new_data, data_type)

Expand Down
5 changes: 2 additions & 3 deletions pypulseq/make_extended_trapezoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ def make_extended_trapezoid(
round(times[0] / system.grad_raster_time) * system.grad_raster_time
)
grad.tt = times - grad.delay
grad.shape_dur = (
round(times[-1] / system.grad_raster_time) * system.grad_raster_time
)
grad.shape_dur = grad.tt[-1]
grad.area = 0.5 * ((grad.tt[1:] - grad.tt[:-1]) * (grad.waveform[1:] + grad.waveform[:-1])).sum()

grad.first = amplitudes[0]
grad.last = amplitudes[-1]
Expand Down
4 changes: 2 additions & 2 deletions pypulseq/opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ def __init__(

if max_grad != None:
max_grad = convert(
from_value=max_grad, from_unit=grad_unit, to_unit="Hz/m", gamma=gamma
from_value=max_grad, from_unit=grad_unit, to_unit="Hz/m", gamma=abs(gamma)
)
else:
max_grad = Opts.default.max_grad

if max_slew != None:
max_slew = convert(
from_value=max_slew, from_unit=slew_unit, to_unit="Hz/m", gamma=gamma
from_value=max_slew, from_unit=slew_unit, to_unit="Hz/m", gamma=abs(gamma)
)
else:
max_slew = Opts.default.max_slew
Expand Down
Loading