Skip to content

calculate_shortest_params_for_area double rounding causes longer duration #301

@nathanielatom

Description

@nathanielatom

Bug Description
The helper function calculate_shortest_params_for_area raises an AssertionError for a shortest possible trapezoid (well triangle) when make_trapezoid is given area and duration that is the shortest possible.

To Reproduce
Use the EPI example in the documentation, https://github.com/imr-framework/pypulseq/blob/master/examples/scripts/write_epi.py
and only change the FOV to fov = 240e-3 m and max slew rate to max_slew=200 T/m/s. With just these two reasonable changes, the calculate_shortest_params_for_area raises an AssertionError:

Requested area is too large for this gradient. Minimum required duration is 60 us. The passed duration is 50 us.

Expected behavior
The EPI example calculates the shorted possible gradient triangle using the same method as the calculate_shortest_params_for_area, however it only rounds the duration up to system.grad_raster_time once, at the end of the calculation for total duration of the triangle; whereas calculate_shortest_params_for_area rounds up the rise_time on its own, then sets the fall_time equal to the rise_time, effectively rounding up twice, and leading to a longer than shortest possible duration and the error.

Desktop (please complete the following information):

  • OS: macOS Sequoia
  • OS Version: 15.3.1 (24D70)
  • python version: 3.9.10
  • pypulseq version: 1.4.2.post1

I'd be happy to help with a PR at some point when I have availability, but not sure the preferred approach.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions