From b5e56bee40ca6d274ff7f70be632fec37592cb46 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Fri, 17 Jan 2025 12:11:08 +0100 Subject: [PATCH 1/6] Change default `is_composable` value to `true` --- KomaMRIBase/src/motion/Action.jl | 2 +- KomaMRIBase/src/motion/actions/simpleactions/HeartBeat.jl | 2 -- KomaMRIBase/src/motion/actions/simpleactions/Rotate.jl | 2 -- KomaMRIBase/src/motion/actions/simpleactions/Translate.jl | 2 ++ 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/KomaMRIBase/src/motion/Action.jl b/KomaMRIBase/src/motion/Action.jl index a47143e49..42ce0c5d7 100644 --- a/KomaMRIBase/src/motion/Action.jl +++ b/KomaMRIBase/src/motion/Action.jl @@ -1,6 +1,6 @@ abstract type AbstractAction{T<:Real} end -is_composable(m::AbstractAction) = false +is_composable(m::AbstractAction) = true # Simple actions include("actions/SimpleAction.jl") diff --git a/KomaMRIBase/src/motion/actions/simpleactions/HeartBeat.jl b/KomaMRIBase/src/motion/actions/simpleactions/HeartBeat.jl index 92a38b9e4..433865a42 100644 --- a/KomaMRIBase/src/motion/actions/simpleactions/HeartBeat.jl +++ b/KomaMRIBase/src/motion/actions/simpleactions/HeartBeat.jl @@ -23,8 +23,6 @@ julia> heartbeat = HeartBeat(circumferential_strain=-0.3, radial_strain=-0.2, lo longitudinal_strain :: T end -is_composable(action::HeartBeat) = true - function displacement_x!(ux, action::HeartBeat, x, y, z, t) r = sqrt.(x .^ 2 + y .^ 2) θ = atan.(y, x) diff --git a/KomaMRIBase/src/motion/actions/simpleactions/Rotate.jl b/KomaMRIBase/src/motion/actions/simpleactions/Rotate.jl index c43070923..dc915f890 100644 --- a/KomaMRIBase/src/motion/actions/simpleactions/Rotate.jl +++ b/KomaMRIBase/src/motion/actions/simpleactions/Rotate.jl @@ -60,8 +60,6 @@ RotateX(pitch::T) where {T<:Real} = Rotate(pitch, zero(T), zero(T)) RotateY(roll::T) where {T<:Real} = Rotate(zero(T), roll, zero(T)) RotateZ(yaw::T) where {T<:Real} = Rotate(zero(T), zero(T), yaw) -is_composable(action::Rotate) = true - function displacement_x!(ux, action::Rotate, x, y, z, t) # Not using sind and cosd functions until bug with oneAPI is solved: # https://github.com/JuliaGPU/oneAPI.jl/issues/65 diff --git a/KomaMRIBase/src/motion/actions/simpleactions/Translate.jl b/KomaMRIBase/src/motion/actions/simpleactions/Translate.jl index 3508dc975..893df36be 100644 --- a/KomaMRIBase/src/motion/actions/simpleactions/Translate.jl +++ b/KomaMRIBase/src/motion/actions/simpleactions/Translate.jl @@ -27,6 +27,8 @@ TranslateX(dx::T) where {T<:Real} = Translate(dx, zero(T), zero(T)) TranslateY(dy::T) where {T<:Real} = Translate(zero(T), dy, zero(T)) TranslateZ(dz::T) where {T<:Real} = Translate(zero(T), zero(T), dz) +is_composable(m::Translate) = false + function displacement_x!(ux, action::Translate, x, y, z, t) ux .= t.* action.dx return nothing From 49692035e048d289abfd82c9f84e1e842d52b04c Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Fri, 17 Jan 2025 12:11:57 +0100 Subject: [PATCH 2/6] Fix calls to `unit_time` in core/simulation/Flow.jl --- KomaMRICore/src/simulation/Flow.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/KomaMRICore/src/simulation/Flow.jl b/KomaMRICore/src/simulation/Flow.jl index a9727b95d..371922ad2 100644 --- a/KomaMRICore/src/simulation/Flow.jl +++ b/KomaMRICore/src/simulation/Flow.jl @@ -19,14 +19,14 @@ function outflow_spin_reset!( spin_state_matrix::AbstractArray, t, action::FlowPath, - time_span, + time_curve, spin_span; replace_by=0, seq_t=0, add_t0=false, ) # Initialize time: add t0 and normalize - ts = KomaMRIBase.unit_time(init_time(t, seq_t, add_t0), time_span) + ts = KomaMRIBase.unit_time(init_time(t, seq_t, add_t0), time_curve.t, time_curve.t_unit, time_curve.periodic, time_curve.periods) # Get spin state range affected by the spin span idx = KomaMRIBase.get_indexing_range(spin_span) spin_state_matrix = @view(spin_state_matrix[idx, :]) @@ -43,14 +43,14 @@ function outflow_spin_reset!( M::Mag, t, action::FlowPath, - time_span, + time_curve, spin_span; replace_by=0, seq_t=0, add_t0=false, ) # Initialize time: add t0 and normalize - ts = KomaMRIBase.unit_time(init_time(t, seq_t, add_t0), time_span) + ts = KomaMRIBase.unit_time(init_time(t, seq_t, add_t0), time_curve.t, time_curve.t_unit, time_curve.periodic, time_curve.periods) # Get spin state range affected by the spin span idx = KomaMRIBase.get_indexing_range(spin_span) M = @view(M[idx]) From ce7aef0f5ab268c7c4ac0b384c956171863a9f52 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Fri, 17 Jan 2025 12:55:08 +0100 Subject: [PATCH 3/6] Add `periodic=true` in `Periodic` constructor --- KomaMRIBase/src/motion/TimeCurve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KomaMRIBase/src/motion/TimeCurve.jl b/KomaMRIBase/src/motion/TimeCurve.jl index 235f6c9ca..ff799b321 100644 --- a/KomaMRIBase/src/motion/TimeCurve.jl +++ b/KomaMRIBase/src/motion/TimeCurve.jl @@ -107,7 +107,7 @@ julia> periodic = Periodic(period=1.0, asymmetry=0.2) ``` ![Periodic](../assets/periodic.svg) """ -Periodic(period::T, asymmetry::T) where T = TimeCurve(t=[zero(T), period*asymmetry, period], t_unit=[zero(T), oneunit(T), zero(T)]) +Periodic(period::T, asymmetry::T) where T = TimeCurve(t=[zero(T), period*asymmetry, period], t_unit=[zero(T), oneunit(T), zero(T)], periodic=true) Periodic(; period=1.0, asymmetry=0.5) = Periodic(period, asymmetry) """ Compare two TimeCurves """ From 9f18312d8cac0f630eb9e8cbe4c8363798b82488 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Thu, 23 Jan 2025 11:12:12 +0100 Subject: [PATCH 4/6] Add `colorscale` keyword in `plot_image` --- KomaMRIPlots/src/ui/DisplayFunctions.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/KomaMRIPlots/src/ui/DisplayFunctions.jl b/KomaMRIPlots/src/ui/DisplayFunctions.jl index 34e4a2da6..d3f53cd20 100644 --- a/KomaMRIPlots/src/ui/DisplayFunctions.jl +++ b/KomaMRIPlots/src/ui/DisplayFunctions.jl @@ -796,6 +796,7 @@ function plot_image( zmax=maximum(image[:]), darkmode=false, title="", + colorscale="Greys" ) #Layout bgcolor, text_color, plot_bgcolor, grid_color, sep_color = theme_chooser(darkmode) @@ -825,7 +826,7 @@ function plot_image( l.width = width end #Plot - p = heatmap(; z=image, transpose=false, zmin=zmin, zmax=zmax, colorscale="Greys") + p = heatmap(; z=image, transpose=false, zmin=zmin, zmax=zmax, colorscale=colorscale) config = PlotConfig(; displaylogo=false, toImageButtonOptions=attr(; From 36ab6c6fe8ab6010e376d168e376ad998e39b0b9 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Thu, 30 Jan 2025 21:21:07 +0100 Subject: [PATCH 5/6] Add method for multiplication of a `Matrix` by an `Array{Grad}` --- KomaMRIBase/src/datatypes/sequence/Grad.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/KomaMRIBase/src/datatypes/sequence/Grad.jl b/KomaMRIBase/src/datatypes/sequence/Grad.jl index 7c1eb5c0f..c9a09600f 100644 --- a/KomaMRIBase/src/datatypes/sequence/Grad.jl +++ b/KomaMRIBase/src/datatypes/sequence/Grad.jl @@ -226,6 +226,13 @@ Base.zero(::Type{Grad}) = Grad(0.0, 0.0) # Rotation Base.zero(::Grad) = Grad(0.0, 0.0) *(α::Real, x::Grad) = Grad(α * x.A, x.T, x.rise, x.fall, x.delay) +*(α::Matrix, x::Array{Grad}) = begin + y = deepcopy(x) + for (i, g) in enumerate(y) + g.A = (α*x.A)[i] + end + return y +end +(x::Grad, y::Grad) = Grad(x.A .+ y.A, max(x.T, y.T), max(x.rise, y.rise), max(x.fall, y.fall), max(x.delay, y.delay)) #TODO: solve this in a better way (by "stacking" gradients) issue #487 # Others *(x::Grad, α::Real) = Grad(α * x.A, x.T, x.rise, x.fall, x.delay) From adce005ad47c8ec589dc651fd54f43903ace23c3 Mon Sep 17 00:00:00 2001 From: Pablo Villacorta Aylagas Date: Sat, 1 Feb 2025 13:29:28 +0100 Subject: [PATCH 6/6] Revert "Add method for multiplication of a `Matrix` by an `Array{Grad}`" This reverts commit 36ab6c6fe8ab6010e376d168e376ad998e39b0b9. --- KomaMRIBase/src/datatypes/sequence/Grad.jl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/KomaMRIBase/src/datatypes/sequence/Grad.jl b/KomaMRIBase/src/datatypes/sequence/Grad.jl index c9a09600f..7c1eb5c0f 100644 --- a/KomaMRIBase/src/datatypes/sequence/Grad.jl +++ b/KomaMRIBase/src/datatypes/sequence/Grad.jl @@ -226,13 +226,6 @@ Base.zero(::Type{Grad}) = Grad(0.0, 0.0) # Rotation Base.zero(::Grad) = Grad(0.0, 0.0) *(α::Real, x::Grad) = Grad(α * x.A, x.T, x.rise, x.fall, x.delay) -*(α::Matrix, x::Array{Grad}) = begin - y = deepcopy(x) - for (i, g) in enumerate(y) - g.A = (α*x.A)[i] - end - return y -end +(x::Grad, y::Grad) = Grad(x.A .+ y.A, max(x.T, y.T), max(x.rise, y.rise), max(x.fall, y.fall), max(x.delay, y.delay)) #TODO: solve this in a better way (by "stacking" gradients) issue #487 # Others *(x::Grad, α::Real) = Grad(α * x.A, x.T, x.rise, x.fall, x.delay)