Skip to content

Commit

Permalink
Add jump times inside get_variable_times
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillacorta committed Dec 10, 2024
1 parent df42cfd commit 385e4ce
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
5 changes: 2 additions & 3 deletions KomaMRIBase/src/datatypes/simulation/DiscreteSequence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ based on simulation parameters.
# Returns
- `seqd`: (`::DiscreteSequence`) DiscreteSequence struct
"""
function discretize(seq::Sequence; sampling_params=default_sampling_params(), add_times=[])
t, Δt = get_variable_times(seq; Δt=sampling_params["Δt"], Δt_rf=sampling_params["Δt_rf"])
sort!(append!(t, add_times))
function discretize(seq::Sequence; sampling_params=default_sampling_params(), motion=NoMotion())
t, Δt = get_variable_times(seq; Δt=sampling_params["Δt"], Δt_rf=sampling_params["Δt_rf"], motion=motion)
B1, Δf = get_rfs(seq, t)
Gx, Gy, Gz = get_grads(seq, t)
tadc = get_adc_sampling_times(seq)
Expand Down
4 changes: 2 additions & 2 deletions KomaMRIBase/src/motion/Motion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,5 @@ end
# Auxiliary functions
times(m::Motion) = times(m.time)
is_composable(m::Motion) = is_composable(m.action)
get_jump_times(m::Motion) = get_jump_times(m.action, m.time)
get_jump_times(::AbstractAction, ::AbstractTimeSpan) = []
add_jump_times!(t, m::Motion) = add_jump_times!(t, m.action, m.time)
add_jump_times!(t, ::AbstractAction, ::AbstractTimeSpan) = nothing
6 changes: 2 additions & 4 deletions KomaMRIBase/src/motion/MotionList.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ function sort_motions!(m::MotionList)
return nothing
end

function get_jump_times(ml::MotionList{T}) where {T<:Real}
jump_times = T[]
function add_jump_times!(t, ml::MotionList)
for m in ml.motions
append!(jump_times, get_jump_times(m))
add_jump_times!(t, m)
end
return jump_times
end
2 changes: 1 addition & 1 deletion KomaMRIBase/src/motion/NoMotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ function get_spin_coords(
) where {T<:Real}
return x, y, z
end
get_jump_times(::NoMotion) = []
add_jump_times!(t, ::NoMotion) = nothing
6 changes: 5 additions & 1 deletion KomaMRIBase/src/motion/actions/arbitraryactions/FlowPath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ julia> flowpath = FlowPath(
dz::AbstractArray{T}
spin_reset::AbstractArray{Bool}
end
get_jump_times(a::FlowPath, t::AbstractTimeSpan) = (times(t)[end] - times(t)[1])/(size(a.spin_reset)[2]-1) * (getindex.(findall(a.spin_reset .== 1), 2) .- 1) .- 1e-6

function add_jump_times!(t, a::FlowPath, time_span::AbstractTimeSpan)
jump_times = (times(time_span)[end] - times(time_span)[1])/(size(a.spin_reset)[2]-1) * (getindex.(findall(a.spin_reset .== 1), 2) .- 1) .- 1e-6
append!(t, jump_times)
end
5 changes: 4 additions & 1 deletion KomaMRIBase/src/timing/TimeStepCalculation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ This function returns non-uniform time points that are relevant in the sequence
samples for RF excitation (by nominal we mean that the time separation should be at most
`Δt_rf` when the samples are regarded by [`KomaMRI.is_RF_on`](@ref), otherwise the time
points are not necessary and the separation will be bigger)
- `motion`: (`::Union{NoMotion, Motion, MotionList}`, `=NoMotion()`) phantom motion,
from which it may be necessary to extract key time points relevant for the simulation
# Returns
- `t`: (`::Vector{Float64}`, `[s]`) time array with non-uniform time values
- `Δt`: (`::Vector{Float64}`, `[s]`) delta time array with the separation between two
adjacent time points of the `t` time array
"""
function get_variable_times(seq; Δt=1e-3, Δt_rf=1e-5)
function get_variable_times(seq; Δt=1e-3, Δt_rf=1e-5, motion=NoMotion())
t = Float64[]
ϵ = MIN_RISE_TIME # Small Float64
T0 = get_block_start_times(seq)
Expand Down Expand Up @@ -120,6 +122,7 @@ function get_variable_times(seq; Δt=1e-3, Δt_rf=1e-5)
end
append!(t, t_block)
end
add_jump_times!(t, motion)
# Removing repeated points
sort!(unique!(t))
# Fixes a problem with ADC at the start and end of the seq
Expand Down
2 changes: 1 addition & 1 deletion KomaMRICore/src/simulation/SimulatorCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function simulate(
""" maxlog=1
end
# Simulation init
seqd = discretize(seq; sampling_params=sim_params, add_times=KomaMRIBase.get_jump_times(obj.motion)) # Sampling of Sequence waveforms
seqd = discretize(seq; sampling_params=sim_params, motion=obj.motion) # Sampling of Sequence waveforms
parts, excitation_bool = get_sim_ranges(seqd; Nblocks=sim_params["Nblocks"]) # Generating simulation blocks
t_sim_parts = [seqd.t[p[1]] for p in parts]
append!(t_sim_parts, seqd.t[end])
Expand Down

0 comments on commit 385e4ce

Please sign in to comment.