pypulseq icon indicating copy to clipboard operation
pypulseq copied to clipboard

Add information to pp.calc_duration return

Open dornstto opened this issue 10 months ago • 2 comments

I think it would be useful to have the type of event and in case of the type beeing some type of gradient the gradient channel to be returned with the duration. This makes sense to me when using pp.calc_duration with multiple blocks running at the same time and wanting to find out which one is actually responsible for the max length of the block. This could be added in the if statements without much hussle. E.g.: if event.type == "delay": duration_temp = max(duration, event.delay) if duration_temp != duration: event_info = event.type duration = duration_temp

or for gradients: elif event.type == "grad": duration_temp = max(duration, event.delay + event.shape_dur) if duration_temp != duration: event_info = (event.type, event.channel) duration = duration_temp

dornstto avatar Jan 20 '25 11:01 dornstto

I see how this could be useful in certain situations, though probably only in an interactive notebook/ipython environment while debugging. I can not think of many situations where you'd use this information as part of the actual sequence design, and where it isn't already obvious which events may be the longest: i.e. if pp.calc_duration(gx,gy)[1].channel == 'x': vs if pp.calc_duration(gx) > pp.calc_duration(gy)

We cannot just add another return value without breaking backwards compatibility though. And this a function that is very likely to be used in most sequences. To avoid this, there is the possibility of adding a keyword argument: pp.calc_duration(adc, gx, gy, return_longest=True) -> (<duration>, <event>)

FrankZijlstra avatar Jan 23 '25 16:01 FrankZijlstra

To avoid this, there is the possibility of adding a keyword argument: pp.calc_duration(adc, gx, gy, return_longest=True) -> (duration, event) <

This would also be feasible for me, my usecase was a block where a read spoiler gradient was played at the same time, in the same block as rephasing gradients and I wanted to determine which one was crucial for the block length.

dornstto avatar Jan 23 '25 17:01 dornstto