Skip to content
Snippets Groups Projects
Verified Commit 8fcd0756 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Get GenericPulse as subset of larger pulse

parent 540aede8
No related branches found
No related tags found
No related merge requests found
Pipeline #23625 passed
...@@ -41,6 +41,35 @@ function GenericPulse(time::AbstractVector{<:Number}, amplitude::AbstractVector{ ...@@ -41,6 +41,35 @@ function GenericPulse(time::AbstractVector{<:Number}, amplitude::AbstractVector{
return GenericPulse(time, amplitude, (time .- time[1]) .* (frequency * 360) .+ phase, effective_time) return GenericPulse(time, amplitude, (time .- time[1]) .* (frequency * 360) .+ phase, effective_time)
end end
"""
GenericPulse(pulse, t1, t2)
Creates a new [`GenericPulse`](@ref) by slicing another pulse between `t1` and `t2`
"""
function GenericPulse(pulse::GenericPulse, t1::Number, t2::Number)
if t1 < pulse.time[1] || t2 > pulse.time[end]
error("Cannot extrapolate GenericPulse")
end
use = t1 .<= pulse.time .<= t2
tnew = pulse.time[use]
anew = pulse.amplitude[use]
pnew = pulse.phase[use]
@show tnew[end], anew[end]
if !(t1 tnew[1])
pushfirst!(tnew, t1)
pushfirst!(anew, amplitude(pulse, t1))
pushfirst!(pnew, phase(pulse, t1))
elseif !(t2 tnew[end])
push!(tnew, t2)
push!(anew, amplitude(pulse, t2))
push!(pnew, phase(pulse, t2))
end
@show tnew[end], anew[end]
return GenericPulse(tnew .- t1, anew, pnew, pulse.effective_time - t1)
end
GenericPulse(pulse::RFPulseComponent, t1::Number, t2::Number) = GenericPulse(make_generic(pulse), t1, t2)
duration(fp::GenericPulse) = maximum(fp.time) duration(fp::GenericPulse) = maximum(fp.time)
amplitude(fp::GenericPulse) = maximum(abs.(fp.amplitude)) amplitude(fp::GenericPulse) = maximum(abs.(fp.amplitude))
effective_time(pulse::GenericPulse) = pulse.time[findmax(abs.(pulse.amplitude))] effective_time(pulse::GenericPulse) = pulse.time[findmax(abs.(pulse.amplitude))]
......
...@@ -114,6 +114,10 @@ ...@@ -114,6 +114,10 @@
@test flip_angle(pulse) 90. @test flip_angle(pulse) 90.
@test iszero(phase(pulse)) @test iszero(phase(pulse))
@test isnothing(get_pulse(seq, 10.)) @test isnothing(get_pulse(seq, 10.))
gp = GenericPulse(pulse, 0., 1.)
@test gp.amplitude[1] 0. atol=1e-8
@test gp.amplitude[end] amplitude(pulse, 1.) rtol=1e-2
@test all(iszero.(gp.phase))
(pulse, t_pulse) = get_pulse(seq, 35.) (pulse, t_pulse) = get_pulse(seq, 35.)
@test 1.1 < t_pulse < 1.2 @test 1.1 < t_pulse < 1.2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment