imr-framework / pypulseq

Pulseq in Python
https://pypulseq.readthedocs.io
GNU Affero General Public License v3.0
117 stars 63 forks source link

Cannot generate trapezoidal gradient only specifying amplitude and duration. #145

Closed wtclarke closed 10 months ago

wtclarke commented 11 months ago

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

Additional context I'll make a PR with a fix and some tests.

wtclarke commented 10 months ago

Fixed with the merge of #146