Skip to content

Conversation

@gsahonero
Copy link
Member

No description provided.

@gsahonero gsahonero requested a review from cncastillo as a code owner December 3, 2025 16:40
Copy link
Member

@cncastillo cncastillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR. I see some problems with the code, in general you need to take advantage of multiple dispatch. You can change RFs to be a parametric type RF{RFUse} for this and specialized functions based on the type of RFUse. We want to force the user to use Pulseq RFUse if they don't want us to guess the use of each RF with heuristics like alpha > 90.

Look at MATLAB's Pulseq code to check how they deal with this for the calculation of k-space, so we can match behavior.

Comment on lines 191 to 200
get_RF_center(x::RF) = begin
t = times(x)
B1 = ampls(x)
t_center = sum(abs.(B1) .* t) ./ sum(abs.(B1))
if x.use != Undefined() && x.center != 0.0
t_center = x.center
else
t = times(x)
B1 = ampls(x)
t_center = sum(abs.(B1) .* t) ./ sum(abs.(B1))
end
return t_center
end
Copy link
Member

@cncastillo cncastillo Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is to dispatch based on the RF{RFUse}, and do exactly what we are doing now if the use is Undefined(), and return r.center otherwise. Here you are doing extra computations for the case that the RF center is defined.

function get_RF_types(seq, t)
α = get_flip_angles(seq)
function get_RF_types(seq, t; ex_rf_th = 90.01)
α = get_flip_angles(seq)
Copy link
Member

@cncastillo cncastillo Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add ex_rf_th, we need to force people to use the RFUse. The same logic as before, if RFUse is undefined, we need to do exactly what we were doing before.

Also, the computation of

RF_ex =.<= ex_rf_th) .* RF_mask
RF_rf =.>  ex_rf_th) .* RF_mask

doesnt make sense if the RFUse is defined, and its being computed for all RFs.

RF_rf =.> ex_rf_th) .* RF_mask
rf_idx = Int[]
rf_type = Int[] #cambiar a tipo RFUse
rf_type = Vector{Any}()#Int[] #cambiar a tipo RFUse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using containers of type any is a very bad practice, as it generates inefficient code. Please use RFUse, if RFUse is undefined we do the same as before but replacing the ints 0 and 1 by Excitation() and Refocusing()).

Comment on lines +494 to 506
if rf_type[rf-1] != Undefined()
if rf_type[rf-1] == Excitation() # Explicit Excitation
mk[p,i] .-= 0
elseif rf_type[rf-1] == Refocusing() # Explicit Refocuse
mk[p,i] .-= mkf
else
mk[p,i] .+= mkf
end
elseif rf_type[rf-1] == 0 # Excitation
mk[p,i] .-= 0
elseif rf_type[rf-1] == 1 # Refocuse
mk[p,i] .-= mkf
#end
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the logic repeated twice, this doesn't make sense, please only use an rf_type::Vector{RFUse} (like explained in previous comment).

@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.83%. Comparing base (f9636ae) to head (20d148b).

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##           pulseq1.5.0     #658      +/-   ##
===============================================
- Coverage        90.01%   87.83%   -2.18%     
===============================================
  Files               57       57              
  Lines             3366     3355      -11     
===============================================
- Hits              3030     2947      -83     
- Misses             336      408      +72     
Flag Coverage Δ
core 76.95% <ø> (-12.79%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
KomaMRIBase/src/KomaMRIBase.jl 100.00% <ø> (ø)
KomaMRIBase/src/datatypes/Sequence.jl 91.93% <ø> (-0.23%) ⬇️
KomaMRIBase/src/datatypes/sequence/RF.jl 72.00% <ø> (-1.59%) ⬇️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants