Skip to content

Commit

Permalink
Custom range function for keeping type matching
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillacorta committed Jun 19, 2024
1 parent 079a84c commit c9a4dbb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions KomaMRIBase/src/datatypes/phantom/motion/ArbitraryMotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ function GriddedInterpolation(nodes, A, ITP)
return Interpolations.GriddedInterpolation{eltype(A), length(nodes), typeof(A), typeof(ITP), typeof(nodes)}(nodes, A, ITP)
end

function rangeT(start::T, stop::T, length::Int) where {T<:Real}
return StepRangeLen{T,T,T}(T(start), T(stop), length)
end

function interpolate(motion::ArbitraryMotion{T}, Ns::Val{1}) where {T<:Real}
_, Nt = size(motion.dx)
t = range(zero(T), oneunit(T), Nt)
t = rangeT(zero(T), oneunit(T), Nt)
itpx = GriddedInterpolation((t, ), motion.dx[:], (Gridded(Linear()), ))
itpy = GriddedInterpolation((t, ), motion.dy[:], (Gridded(Linear()), ))
itpz = GriddedInterpolation((t, ), motion.dz[:], (Gridded(Linear()), ))
Expand All @@ -103,8 +107,8 @@ end

function interpolate(motion::ArbitraryMotion{T}, Ns::Val) where {T<:Real}
Ns, Nt = size(motion.dx)
id = oneunit(T):Ns
t = range(zero(T), oneunit(T), Nt)
id = rangeT(oneunit(T), T(Ns), Ns)
t = rangeT(zero(T), oneunit(T), Nt)
itpx = GriddedInterpolation((id, t), motion.dx, (NoInterp(), Gridded(Linear())))
itpy = GriddedInterpolation((id, t), motion.dy, (NoInterp(), Gridded(Linear())))
itpz = GriddedInterpolation((id, t), motion.dz, (NoInterp(), Gridded(Linear())))
Expand Down

0 comments on commit c9a4dbb

Please sign in to comment.