Repository navigation
[v1.5.x] Add calc_rf_power() - #347
Conversation
…o feat_calc_rf_power
|
hey @mcencini I started reviewing this PR as well and noticed a few bugs already that I will fix. Furthermore, there are a few things to discuss:
I will probably start implementing it locally as suggested above, but it would be great to get your feedback on this as soon as possible. |
|
hi @schuenke, thanks for looking into this!
|
Yeah, we should definitely do that for the existing code base, but for new implementations (like this one), I would prefer to adjust to Matlab already and, if possible, allow PyPulseq-like arguments (e.g. time_range) optionally. Long term the goal is to bring Matlab and Python closer together and if we introduce new functionality that deviates from Matlab, we have to adjust it at some point in the future leading to the same issues we currently have with seq.plot(), rotate(), make_trapezoid() etc... |
|
agreed - let's use |
- replace np.trapezoid with manual calc for numpy<2.0 compatibility - change dt default from None to 1e-6 to match MATLAB - always use rf.shape_dur instead of t[-1] - t[0], which was one dwell time short for arb rf pulses
|
I replaced the |
- added block_range support to match Matlab implementation keeping time_range as alternative - add comprehensive input validation for block_range and time_range - fix bug leading to IndexError if a window had to slide past a non-RF block, e.g. RF block + delay, window < delay - use self.block_duration instead of calc_duration(get_block(...)) for compatibility with soft delays - support empty sequences
|
This was also tested against MATLAB for various cases (single block/sinc/gauss pulses. different dt, full sequences, different block_ranges, different window_durations. Everything matching perfectly. A comparison against MATLAB using different time_range values is not possible, because this is currently a Python-only feature. |
That's ok - IMO at some point we should let end-of-life python versions and numpy 1.x go, but that probably deserve some long-term planning |
schuenke
left a comment
There was a problem hiding this comment.
@mcencini: Same as for #341 , it would be great if you would review my changes again.
@sairamgeethanath @btasdelen @ckolbPTB @fzimmermann89 maybe one of you also wanna have a quick look at this? I tried to provide helpful infos in the comments.
|
@schuenke it is ok to be merged to me, unless someone else wants to review it again as well. |
|
Hi! concerning one of the comments above:
The challenge in the Matlab's code that the function The only reasonable fix in this direction is to make sure that the function Should we do it this way? --M. |
This PR adds standalone
pypulseq.calc_rf_power()and the correspondingpypulseq.Sequence.calc_rf_power()method.Compared to upstream MATLAB repository, this function by default directly uses explicitly the rf time vector to handle cases where pulse has not an uniform raster equal to rf raster (e.g., for block pulses). In addition, the Sequence method uses
time_rangeinstead ofblock_rangeto align with the other PyPulseq functions (e.g.,plot().This does not rely on any v1.5.1 features and can fit v1.5.0.