-
Notifications
You must be signed in to change notification settings - Fork 68
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
Rounding error in add_gradients leads to incorrect gradient waveforms #186
Comments
Hi @felixlandmeyer. Thanks for your example snippet and pointers, I was able to reproduce and understand the bug quickly.
a. Using b. Using I am more inclined towards b. |
Hi @btasdelen, thank you for the quick reply! I used solution c: I was a little confused by the original version because it adds a time array (t_delay) to a gradient amplitude array (waveform). |
You are totally right, I missed what the code tries to do as I focused on the single line. I tracked the reason for the issue to here in Matlab Pulseq: t_delay = 0:opt.system.gradRasterTime:g.delay-common_delay-opt.system.gradRasterTime;
waveforms{ii} = [t_delay*0 waveforms{ii}]; Python version mimicked that, but there is a missing |
Describe the bug
(Note: This is my first issue report in a public repository, I apologise in advance for any mistakes.)
1.
Line 205 in add_gradients returns an error because of dimension inconsistency.
I changed line 205 from
waveforms[ii] = np.concatenate(([t_delay], waveforms[ii]))
to
waveforms[ii] = np.concatenate((t_delay, waveforms[ii]))
to resolve the error (waveforms[ii] should always have shape (N,) - I think-)
When adding gradients, sometimes too many gradient raster times are added as a delay in add_gradients.
The returned gradient waveform has a jump to zero and back when connecting the individual gradients.
With add_gradients():
Gradients in single blocks:
To Reproduce
run this script:
Expected behavior
Added gradients without a jump at the connection point.
Desktop (please complete the following information):
pypulseq
version: 1.4.2 and 1.4.0Additional context
The numpy.arange() can add one zero too many to the gradient waveform in some cases due to rounding errors.
In the script above, this happens to some of the readouts (e.g. readout two and five).
I'm still kind of a newbie to pulseq so it might be an issue with my code instead of pypulseq itself.
Other than that, I have fixed the rounding issue in my pypulseq installation and can create a PR if you want.
The text was updated successfully, but these errors were encountered: