pypulseq icon indicating copy to clipboard operation
pypulseq copied to clipboard

block duration rounding assertion test

Open L2roche opened this issue 1 year ago • 1 comments

Describe the bug When running example sequences such as write_3Dt1_mprage.py, an error arises: ...write_seq.py", line 92, in write assert abs(block_duration_rounded - block_duration) < 1e-6 indeed, an event lasts 13585.5 [seq.add_block(pp.make_delay(delay_TI))] line 92 of the write function in the write_seq.py file

To Reproduce

  • install pypulseq on windows/wsl
  • run write_3Dt1_mprage.py

Expected behavior This behavior is expected given the code. However, the assertion test that comes after having computed the block duration in units of raster duration. Shouldn't this line just be "assert abs(block_duration_rounded - block_duration) <= 0.5" The 'error' also comes from the fact that make_delay does not check for system.grad_raster_time. Another patch could be to make sure beforehand that TI is adjusted such that delay_TI is a multiple of system.grad_raster_time [delay_TI = TI - pp.calc_duration(rf_prep) / 2 - pp.calc_duration(gx_spoil)]

L2roche avatar Jul 12 '24 09:07 L2roche

Shouldn't this line just be "assert abs(block_duration_rounded - block_duration) <= 0.5"

No, the block duration needs to be an exact multiple of the block_duration_raster specified in the system object. This statement would simply always be True.

Another patch could be to make sure beforehand that TI is adjusted such that delay_TI is a multiple of system.grad_raster_time

This is the correct solution, using this scheme: np.ceil(x * raster_time) / raster_time. Many examples use it, but also many examples are outdated and not using best practices, which is a problem...

FrankZijlstra avatar Jul 18 '24 11:07 FrankZijlstra