Skip to content
Snippets Groups Projects
Verified Commit cc85b512 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Apply consistent normalisation across RF and grad

parent 85366df5
No related branches found
No related tags found
No related merge requests found
module MakieMRIBuilder
using Makie
import MakieCore
import MRIBuilder.Plot: Plot_Sequence, SequenceDiagram, range_line
import MRIBuilder.Plot: Plot_Sequence, SequenceDiagram, range_line, normalise
import MRIBuilder: BaseSequence, BaseBuildingBlock
function Makie.plot!(scene:: Plot_Sequence)
......@@ -20,19 +20,17 @@ function Makie.plot!(scene:: Plot_Sequence)
instant_width = map((a, c) -> a * c, scene[:linewidth], scene[:instant_width])
lift(scene[:sequence]) do sequence
sequence_diagram = SequenceDiagram(sequence)
sequence_diagram = normalise(SequenceDiagram(sequence))
current_y = 0.
for label in (:ADC, :Gz, :Gy, :Gx, :G, :RFy, :RFx)
line = getproperty(sequence_diagram, label)
full_range = range_line(line)
norm = max(abs.(full_range)...)
(lower, upper) = full_range ./ norm
if norm > 0
(lower, upper) = range_line(line)
if !(lower upper)
shift = current_y - lower
Makie.text!(scene, string(label) * " "; position=(0., shift), align=(:right, :center), text_kwargs..., kwargs...)
Makie.lines!(scene, line.times, line.amplitudes ./ norm .+ shift; color=line_color, linewidth=scene[:linewidth], kwargs...)
Makie.lines!(scene, line.times, line.amplitudes .+ shift; color=line_color, linewidth=scene[:linewidth], kwargs...)
for (time, amplitude) in zip(line.event_times, line.event_amplitudes)
Makie.lines!([time, time], [0., amplitude / norm] .+ shift; color=line_color, linewidth=instant_width, kwargs...)
Makie.lines!([time, time], [0., amplitude] .+ shift; color=line_color, linewidth=instant_width, kwargs...)
end
current_y += (upper - lower) + 0.1
end
......
......@@ -56,6 +56,8 @@ range_line(spl::SinglePlotLine) = (
max(maximum(spl.amplitudes; init=0.), maximum(spl.event_amplitudes; init=0.)),
)
normalise(spl::SinglePlotLine, value) = iszero(value) ? spl : SinglePlotLine(spl.times, spl.amplitudes ./ value, spl.event_times, spl.event_amplitudes ./ value)
"""
SequenceDiagram(; RFx, RFy, Gx, Gy, Gz, ADC)
......@@ -138,6 +140,25 @@ function SequenceDiagram(seq::BaseSequence)
for symbol in [:RFx, :RFy, :G, :Gx, :Gy, :Gz, :ADC]]...)
end
function normalise(sd::SequenceDiagram)
rf_norm = max(abs.(range_line(sd.RFx))..., abs.(range_line(sd.RFy))...)
grad_norm = max(
abs.(range_line(sd.G))...,
abs.(range_line(sd.Gx))...,
abs.(range_line(sd.Gy))...,
abs.(range_line(sd.Gz))...,
)
SequenceDiagram(
normalise(sd.RFx, rf_norm),
normalise(sd.RFy, rf_norm),
normalise(sd.G, grad_norm),
normalise(sd.Gx, grad_norm),
normalise(sd.Gy, grad_norm),
normalise(sd.Gz, grad_norm),
sd.ADC
)
end
"""
plot(sequence; kwargs...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment