From 008e1602bcee259295ca5e27c805d8b409ec6454 Mon Sep 17 00:00:00 2001 From: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk> Date: Thu, 21 Mar 2024 13:52:16 +0000 Subject: [PATCH] Call sequence with time rather than index --- src/containers/base_sequences.jl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/containers/base_sequences.jl b/src/containers/base_sequences.jl index 67dfe5d..1ff4215 100644 --- a/src/containers/base_sequences.jl +++ b/src/containers/base_sequences.jl @@ -33,18 +33,19 @@ function Base.getindex(bs::BaseSequence{N}, index::Integer) where {N} base_index = ((index - 1) % N) + 1 return get_index_single_TR(bs, base_index) end -function Base.getindex(sequence::BaseSequence{N}, time::AbstractFloat) where {N} - time_orig = time + +function (sequence::BaseSequence{N})(time::AbstractFloat) where {N} + var_time = mod(time, duration(sequence)) for block in sequence - time -= duration(block) - if time < 0 - return (time + duration(block), block) + var_time -= duration(block) + if var_time < 0 + return (var_time + duration(block), block) end end - if abs(time) <= 1e-6 - return (duration(sequence[N]) + time, sequence[N]) + if abs(var_time) <= 1e-6 + return (duration(sequence[N]) + var_time, sequence[N]) end - error("Requested time $time_orig is more than the sequence TR ($(TR(sequence)))") + error("Total duration of building blocks does not match duration of the sequence.") end Base.iterate(bs::BaseSequence) = Base.iterate(bs, 1) @@ -117,7 +118,7 @@ end for fn in (:gradient_strength, :amplitude, :phase, :gradient_strength3) @eval function $fn(sequence::BaseSequence, time::AbstractFloat) - (block_time, block) = sequence[time] + (block_time, block) = sequence(time) return $fn(block, block_time) end end -- GitLab