Skip to content

Commit

Permalink
Add jump times to discrete sequence in discretize
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillacorta committed Dec 10, 2024
1 parent 85fd5da commit a3f66ce
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion KomaMRIBase/src/datatypes/simulation/DiscreteSequence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ based on simulation parameters.
# Returns
- `seqd`: (`::DiscreteSequence`) DiscreteSequence struct
"""
function discretize(seq::Sequence; sampling_params=default_sampling_params())
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!(unique!(append!(t, add_times)))
B1, Δf = get_rfs(seq, t)
Gx, Gy, Gz = get_grads(seq, t)
tadc = get_adc_sampling_times(seq)
Expand Down
4 changes: 3 additions & 1 deletion KomaMRIBase/src/motion/Motion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,6 @@ end

# Auxiliary functions
times(m::Motion) = times(m.time)
is_composable(m::Motion) = is_composable(m.action)
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) = []
10 changes: 9 additions & 1 deletion KomaMRIBase/src/motion/MotionList.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include("Action.jl")
include("SpinSpan.jl")
include("TimeSpan.jl")
include("Action.jl")
include("Motion.jl")

"""
Expand Down Expand Up @@ -202,3 +202,11 @@ function sort_motions!(m::MotionList)
sort!(m.motions; by=m -> times(m)[1])
return nothing
end

function get_jump_times(ml::MotionList{T}) where {T<:Real}
jump_times = T[]
for m in ml.motions
append!(jump_times, get_jump_times(m))
end
return jump_times
end
1 change: 1 addition & 0 deletions KomaMRIBase/src/motion/NoMotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ function get_spin_coords(
) where {T<:Real}
return x, y, z
end
get_jump_times(::NoMotion) = []
3 changes: 2 additions & 1 deletion KomaMRIBase/src/motion/actions/arbitraryactions/FlowPath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ julia> flowpath = FlowPath(
dy::AbstractArray{T}
dz::AbstractArray{T}
spin_reset::AbstractArray{Bool}
end
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
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) # Sampling of Sequence waveforms
seqd = discretize(seq; sampling_params=sim_params, add_times=KomaMRIBase.get_jump_times(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 a3f66ce

Please sign in to comment.