Cannot generate trapezoidal gradient only specifying amplitude and duration.
wtclarke opened this issue · comments
William T Clarke commented
Describe the bug
If you run make_trapezoid(channel='x', amplitude=1, duration=1)
(ignore the not sensible values) an unhandled exception is thrown.
if rise_time == 0:
rise_time = (
> math.ceil(abs(amplitude2) / max_slew / system.grad_raster_time)
* system.grad_raster_time
)
E UnboundLocalError: cannot access local variable 'amplitude2' where it is not associated with a value
pypulseq/make_trapezoid.py:174: UnboundLocalError
This is because within the if statement elif duration > 0:
on line 146 there is a case for amplitude == 0
line 147 but not an else
( for amplitude !=0
). Within this statement amplitude2
is declared.
To Reproduce
- Run
make_trapezoid(channel='x', amplitude=1, duration=1)
Expected behavior
It's indicated in the documentation that this should work and it isn't handled explicitly.
Additional context
I'll make a PR with a fix and some tests.
William T Clarke commented
Fixed with the merge of #146