From 0c7ca1a10dfbddfb1b7e0c99abb0bec6ea349de2 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Mon, 9 Dec 2024 23:17:58 +0100 Subject: [PATCH 1/4] Solve bug in `get_spin_coords` for a single motion --- KomaMRIBase/src/motion/Motion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KomaMRIBase/src/motion/Motion.jl b/KomaMRIBase/src/motion/Motion.jl index 6dd7548e4..d5ced6c23 100644 --- a/KomaMRIBase/src/motion/Motion.jl +++ b/KomaMRIBase/src/motion/Motion.jl @@ -191,7 +191,7 @@ end function get_spin_coords( m::Motion{T}, x::AbstractVector{T}, y::AbstractVector{T}, z::AbstractVector{T}, t ) where {T<:Real} - ux, uy, uz = x .+ 0*t, y .+ 0*t, z .+ 0*t # Buffers for displacements + ux, uy, uz = x .* 0*t, y .* 0*t, z .* 0*t # Buffers for displacements t_unit = unit_time(t, m.time) idx = get_indexing_range(m.spins) displacement_x!(@view(ux[idx, :]), m.action, @view(x[idx]), @view(y[idx]), @view(z[idx]), t_unit) From 818d4b1a9e10a36b59036c8898bc106f11126297 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Mon, 9 Dec 2024 23:18:47 +0100 Subject: [PATCH 2/4] Add methods of `intersect_idx` when the indexing range is a bitvector --- KomaMRIBase/src/motion/SpinSpan.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/KomaMRIBase/src/motion/SpinSpan.jl b/KomaMRIBase/src/motion/SpinSpan.jl index 21d1a7396..fab1b9787 100644 --- a/KomaMRIBase/src/motion/SpinSpan.jl +++ b/KomaMRIBase/src/motion/SpinSpan.jl @@ -69,3 +69,5 @@ Base.length(sr::SpinRange) = length(sr.range) get_indexing_range(spins::SpinRange) = spins.range expand(sr::SpinRange, Ns::Int) = sr intersect_idx(a, b) = findall(x -> x in a, b) +intersect_idx(a, b::BitVector) = findall(x -> x in a, findall(x->x==true, b)) +intersect_idx(a::BitVector, b) = findall(x -> x in findall(x->x==true, a), b) From 39a0e835d48d7e2862d1567557c538755812e60d Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Mon, 9 Dec 2024 23:56:45 +0100 Subject: [PATCH 3/4] Add test for the new `intersect_idx` methods --- KomaMRIBase/test/runtests.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/KomaMRIBase/test/runtests.jl b/KomaMRIBase/test/runtests.jl index 902a6927a..2ed71555f 100644 --- a/KomaMRIBase/test/runtests.jl +++ b/KomaMRIBase/test/runtests.jl @@ -400,7 +400,6 @@ end t_end = 1.0 arbitrarymotion = Path(0.01 .* rand(Ns, Nt), 0.01 .* rand(Ns, Nt), 0.01 .* rand(Ns, Nt), TimeRange(t_start, t_end), SpinRange(2:2:4)) - # Test phantom subset obs1 = Phantom( name, x, @@ -416,6 +415,8 @@ end Dθ, simplemotion ) + + # Test phantom subset (simple range) rng = 1:2:5 obs2 = Phantom( name, @@ -457,6 +458,15 @@ end ) @test obs1 + obs2 == oba + # Test phantom subset (BitVector range) + obs3 = copy(obs1) + obs4 = copy(obs1) + rng = obs3.x .> 0 + obs3.motion = Translate(5e-4, 6e-4, 7e-4, TimeRange(0.0, 1.0), SpinRange(rng)) + obs4.motion = Translate(5e-4, 6e-4, 7e-4, TimeRange(0.0, 1.0), SpinRange(1:length(obs4))) + @test obs3[rng] == obs4[rng] + @test obs3[rng].motion == obs4.motion[rng] + # Test scalar multiplication of a phantom c = 7 obc = Phantom(name=name, x=x, y=y, z=z, ρ=c*ρ, T1=T1, T2=T2, T2s=T2s, Δw=Δw, Dλ1=Dλ1, Dλ2=Dλ2, Dθ=Dθ) From 00eee39f680ceca4605150938a4687383b0820a7 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Tue, 10 Dec 2024 00:22:02 +0100 Subject: [PATCH 4/4] Add parenthesis --- KomaMRIBase/src/motion/Motion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KomaMRIBase/src/motion/Motion.jl b/KomaMRIBase/src/motion/Motion.jl index d5ced6c23..916e04e7d 100644 --- a/KomaMRIBase/src/motion/Motion.jl +++ b/KomaMRIBase/src/motion/Motion.jl @@ -191,7 +191,7 @@ end function get_spin_coords( m::Motion{T}, x::AbstractVector{T}, y::AbstractVector{T}, z::AbstractVector{T}, t ) where {T<:Real} - ux, uy, uz = x .* 0*t, y .* 0*t, z .* 0*t # Buffers for displacements + ux, uy, uz = x .* (0*t), y .* (0*t), z .* (0*t) # Buffers for displacements t_unit = unit_time(t, m.time) idx = get_indexing_range(m.spins) displacement_x!(@view(ux[idx, :]), m.action, @view(x[idx]), @view(y[idx]), @view(z[idx]), t_unit)