Skip to content

Commit

Permalink
Add temporal test for comparing read RF
Browse files Browse the repository at this point in the history
  • Loading branch information
beorostica committed Mar 28, 2024
1 parent ddc6d93 commit d3cc103
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion KomaMRIBase/src/timing/KeyValuesCalculation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ get_theo_A(r::RF; off_val=0, max_rf_samples=Inf) = begin
freq = exp.(1im*2π*cumsum(r.Δf.*dt)) # exp(i ∫ᵗw(t)dt)
added_phase = transpose([freq freq])[:]
A = A .* added_phase
A[abs.(A).<=1e-10] .= 0 #Remove small values
#A[abs.(A).<=1e-10] .= 0 #Remove small values
#Output
aux = [off_val; 0; A; 0]
end
Expand Down
13 changes: 8 additions & 5 deletions KomaMRIFiles/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ end
using KomaMRIBase, MAT, PrettyTables
TOLERANCE = 1e-6

get_theo_A_helper(r::RF) = sum(abs.(r.A)) == 0 ? [0; 0; zeros(2*length(r.A)); 0] : [0; 0; transpose([r.A r.A])[:]; 0]

# Auxiliar functions
function get_theo_t_aux(rf::RF)
Namp, Ntim = length(rf.A), length(rf.T)
Expand All @@ -68,9 +70,9 @@ end
function get_theo_A_aux(rf::RF)
Namp, Ntim = length(rf.A), length(rf.T)
if Namp == 1 && Ntim == 1
return γ*KomaMRIBase.get_theo_A(rf; off_val=NaN, max_rf_samples=Inf)[2:end]
return γ*get_theo_A_helper(rf)[2:end]
elseif Namp > 1 && Ntim == 1
amps = γ*KomaMRIBase.get_theo_A(rf; off_val=NaN, max_rf_samples=Inf)[2:end]
amps = γ*get_theo_A_helper(rf)[2:end]
return [amps[1]; amps[2:end-1][[i for i in 1:length(amps)-1 if i % 2 == 0]]; amps[end]]
end
return []#γ*KomaMRIBase.get_theo_A(rf; off_val=NaN, max_rf_samples=Inf)[2:end]
Expand Down Expand Up @@ -198,15 +200,16 @@ end
for i in 1:length(seq_pulseq[event]["blocks"])
samples_koma = seq_koma[event][sample][i]
samples_pulseq = seq_pulseq[event][sample][i]
same_points = all(.≈(samples_koma, samples_pulseq, atol=TOLERANCE))
same_points = all(.≈(abs.(samples_koma .- samples_pulseq), 0, atol=TOLERANCE))
@test same_points
if !same_points
println("Mismatch for $(event) $(sample). Block $(seq_pulseq[event]["blocks"][i])")
data = [samples_koma samples_pulseq]
pretty_table(data; header=["koma", "pulseq"])
# This is just an example about how to debug locally when there are problems
#if event == "gx" && sample == "amplitudes" && seq_pulseq[event]["blocks"][i] == 3
# pretty_table(data[end-10:end,:]; header=["koma", "pulseq"])
#if event == "rf" && sample == "amplitudes" #&& seq_pulseq[event]["blocks"][i] == 3
# pretty_table(data[1:10,:]; header=["koma", "pulseq"])
# #pretty_table(data[end-10:end,:]; header=["koma", "pulseq"])
#end
end
end
Expand Down
Binary file modified KomaMRIFiles/test/test_files/pulseq_read_comparison/spiral.mat
Binary file not shown.

0 comments on commit d3cc103

Please sign in to comment.