From 516b909eefb5b1a2f0f356e985bb0325e8098786 Mon Sep 17 00:00:00 2001 From: Carlos Castillo Passi Date: Thu, 4 Apr 2024 15:15:06 -0300 Subject: [PATCH 1/3] Removed unecessary functions --- KomaMRIBase/src/datatypes/Sequence.jl | 92 ++------------------------- 1 file changed, 7 insertions(+), 85 deletions(-) diff --git a/KomaMRIBase/src/datatypes/Sequence.jl b/KomaMRIBase/src/datatypes/Sequence.jl index 719cfb164..463ca10ca 100644 --- a/KomaMRIBase/src/datatypes/Sequence.jl +++ b/KomaMRIBase/src/datatypes/Sequence.jl @@ -356,50 +356,6 @@ get_samples(seq::Sequence; off_val=0, max_rf_samples=Inf) = begin ) end -""" - y = ⏢(A, t, ΔT, ζ1, ζ2, delay) - -Generates a trapezoidal waveform vector. - -# Arguments -- `A`: (`::Real`) amplitude -- `t`: (`::Vector{Float64}`, `[s]`) times to evaluate (actually it's a `1-row - ::Matrix{Float64}`) -- `ΔT`: (`::Real`, `[s]`) time duration of the top-flat -- `ζ1`: (`::Real`, `[s]`) rise time duration -- `ζ2`: (`::Real`, `[s]`) fall time duration -- `delay`: (`::Real`, `[s]`) delay time - -# Returns -- `y`: (`::Vector{Float64}`) trapezoidal waveform (actually it's a `1-row - ::Matrix{Float64}`) -""" -⏢(A, t, ΔT, ζ1, ζ2, delay) = begin - if sum(abs.(A)) != 0 && ΔT+ζ1+ζ2 != 0 # If no event just ignore calculations - #Getting amplitudes, only supports uniformly sampled waveforms for now - if length(A) != 1 - grad_raster = ΔT / length(A) - idx = ceil.(Int, (t .- delay .- ζ1) ./ grad_raster ) #Time to integer index - valid = 1 .<= idx .<= length(A) - idx[(!).(valid)] .= 1 - B = A[idx] .* valid - else - B = A - end - #Trapezoidal waveform - aux = (ζ1 .< t .- delay .< ζ1+ΔT) .* B - if ζ1 != 0 - aux .+= (0 .< t .- delay .<= ζ1) .* A[1] .* (t .- delay)./ζ1 - end - if ζ2 !=0 - aux .+= (ζ1+ΔT .<= t .- delay .< ζ1+ΔT+ζ2) .* A[end] .* (1 .- (t.-delay.-ζ1.-ΔT)./ζ2) - end - else - aux = zeros(size(t)) - end - aux -end - """ Gx, Gy, Gz = get_grads(seq, t::Vector) Gx, Gy, Gz = get_grads(seq, t::Matrix) @@ -418,41 +374,15 @@ Get the gradient array from sequence `seq` evaluated in time points `t`. - `Gz`: (`Vector{Float64}` or `1-row ::Matrix{Float64}`, `[T]`) gradient vector values in the z direction """ -function get_grads(seq, t::Vector) +function get_grads(seq, t::Union{Vector, Matrix}) gx = get_theo_Gi(seq, 1) gy = get_theo_Gi(seq, 2) gz = get_theo_Gi(seq, 3) - Gx = linear_interpolation(gx..., extrapolation_bc=0)(t) - Gy = linear_interpolation(gy..., extrapolation_bc=0)(t) - Gz = linear_interpolation(gz..., extrapolation_bc=0)(t) + Gx = linear_interpolation(gx..., extrapolation_bc=0).(t) + Gy = linear_interpolation(gy..., extrapolation_bc=0).(t) + Gz = linear_interpolation(gz..., extrapolation_bc=0).(t) (Gx, Gy, Gz) end -function get_grads(seq, t::Matrix) - t_vec = t[:] - gx = get_theo_Gi(seq, 1) - gy = get_theo_Gi(seq, 2) - gz = get_theo_Gi(seq, 3) - Gx = linear_interpolation(gx..., extrapolation_bc=0)(t_vec) - Gy = linear_interpolation(gy..., extrapolation_bc=0)(t_vec) - Gz = linear_interpolation(gz..., extrapolation_bc=0)(t_vec) - (Gx', Gy', Gz') -end -# hold_interpolation(range::AbstractVector, vs::AbstractVector; extrapolation_bc = Throw()) = -# extrapolate(interpolate((range, ), vs, Gridded(Constant{Previous}())), 0) -# get_grads(seq::Sequence,t) = begin -# #Amplitude -# A = seq.GR.A -# #Grad Timings -# T = seq.GR.T -# ζ1 = seq.GR.rise -# ζ2 = seq.GR.fall -# delay = seq.GR.delay -# #Sequence timings -# ΔT = durs(seq) #Duration of sequence block -# T0 = cumsum([0; ΔT[:]]) #Start time of each block -# #Waveforms -# (sum([⏢(A[j,i],t.-T0[i],T[j,i],ζ1[j,i],ζ2[j,i],delay[j,i]) for i=1:length(seq)]) for j=1:3) -# end """ B1, Δf_rf = get_rfs(seq::Sequence, t) @@ -467,21 +397,13 @@ Returns the RF pulses and the delta frequency. - `B1`: (`1-row ::Matrix{ComplexF64}`, `[T]`) vector of RF pulses - `Δf_rf`: (`1-row ::Matrix{Float64}`, `[Hz]`) delta frequency vector """ -function get_rfs(seq, t::Vector) +function get_rfs(seq, t::Union{Vector, Matrix}) r = get_theo_RF(seq, :A) df = get_theo_RF(seq, :Δf) - R = linear_interpolation(r..., extrapolation_bc=0)(t) - DF = linear_interpolation(df..., extrapolation_bc=0)(t) + R = linear_interpolation(r..., extrapolation_bc=0).(t) + DF = linear_interpolation(df..., extrapolation_bc=0).(t) (R, DF) end -function get_rfs(seq, t::Matrix) - t_vec = t[:] - r = get_theo_RF(seq, :A) - df = get_theo_RF(seq, :Δf) - R = linear_interpolation(r..., extrapolation_bc=0)(t_vec) - DF = linear_interpolation(df..., extrapolation_bc=0)(t_vec) - (transpose(R), transpose(DF)) -end """ y = get_flip_angles(x::Sequence) From ed884c9fe4d73625e484c32b83f2871ee1cbde23 Mon Sep 17 00:00:00 2001 From: Carlos Castillo Passi Date: Thu, 4 Apr 2024 15:26:45 -0300 Subject: [PATCH 2/3] Removed print in test --- KomaMRICore/test/runtests.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/KomaMRICore/test/runtests.jl b/KomaMRICore/test/runtests.jl index 3341140e5..72330bf2a 100644 --- a/KomaMRICore/test/runtests.jl +++ b/KomaMRICore/test/runtests.jl @@ -395,9 +395,6 @@ end raw1 = @suppress simulate(obj, seq1, sys; sim_params) raw2 = @suppress simulate(obj, seq2, sys; sim_params) - println(raw1.profiles[1].data) - println(raw2.profiles[1].data) - @test raw1.profiles[1].data ≈ raw2.profiles[1].data end From 8d6f08f4d84bb63b8ffe22056ae166f025f0ab0e Mon Sep 17 00:00:00 2001 From: Carlos Castillo Passi Date: Thu, 4 Apr 2024 15:28:17 -0300 Subject: [PATCH 3/3] Added missing @suppress in tests --- KomaMRICore/test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KomaMRICore/test/runtests.jl b/KomaMRICore/test/runtests.jl index 72330bf2a..37a1051f3 100644 --- a/KomaMRICore/test/runtests.jl +++ b/KomaMRICore/test/runtests.jl @@ -410,7 +410,7 @@ end sig = @suppress simulate(obj, seq, sys; sim_params) sig = sig / prod(size(obj)) sim_params["sim_method"] = KomaMRICore.BlochDict() - sig2 = simulate(obj, seq, sys; sim_params) + sig2 = @suppress simulate(obj, seq, sys; sim_params) sig2 = sig2 / prod(size(obj)) @test sig ≈ sig2 @@ -436,7 +436,7 @@ end # Simulate the slice profile sim_params = Dict{String, Any}("Δt_rf" => Trf / length(seq.RF.A[1])) - M = simulate_slice_profile(seq; z, sim_params) + M = @suppress simulate_slice_profile(seq; z, sim_params) # For the time being, always pass the test @test true