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

Add pathway variables the proper way to the variables list

parent e896951f
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ include("components/components.jl") ...@@ -10,7 +10,7 @@ include("components/components.jl")
include("containers/containers.jl") include("containers/containers.jl")
include("pathways.jl") include("pathways.jl")
include("parts/parts.jl") include("parts/parts.jl")
#include("printing.jl") include("printing.jl")
import .BuildSequences: build_sequence, global_model, global_scanner, fixed import .BuildSequences: build_sequence, global_model, global_scanner, fixed
export build_sequence, global_model, global_scanner, fixed export build_sequence, global_model, global_scanner, fixed
......
...@@ -3,7 +3,7 @@ import LinearAlgebra: norm, tr ...@@ -3,7 +3,7 @@ import LinearAlgebra: norm, tr
import StaticArrays: SVector, SMatrix import StaticArrays: SVector, SMatrix
import ..Components: NoGradient, RFPulseComponent, ReadoutComponent, InstantGradient, GradientWaveform, DelayedEvent import ..Components: NoGradient, RFPulseComponent, ReadoutComponent, InstantGradient, GradientWaveform, DelayedEvent
import ..Containers: BaseSequence, Sequence, BaseBuildingBlock, waveform, events, waveform_sequence, start_time, AlternativeBlocks import ..Containers: BaseSequence, Sequence, BaseBuildingBlock, waveform, events, waveform_sequence, start_time, AlternativeBlocks
import ..Variables: qvec, qval, bmat_gradient, VariableType, effective_time, duration, TR, variables import ..Variables: qvec, qval, bmat_gradient, VariableType, effective_time, duration, TR, bmat, bval, area_under_curve, duration_dephase, duration_transverse
""" """
...@@ -180,7 +180,6 @@ for fn in (:qvec, :area_under_curve, :bmat, :bval, :duration_dephase, :duration_ ...@@ -180,7 +180,6 @@ for fn in (:qvec, :area_under_curve, :bmat, :bval, :duration_dephase, :duration_
end end
error("get_pathway returned unexpected type for $seq") error("get_pathway returned unexpected type for $seq")
end end
@eval variables[$(QuoteNode(fn))] = $fn
end end
......
module Printing module Printing
import JuMP: value import JuMP: value
import Printf: @sprintf import Printf: @sprintf
import ..BuildingBlocks: BuildingBlock, get_children_indices, VariableNotAvailable import ..Variables: VariableType, variables, AbstractBlock, VariableNotAvailable, alternative_variables
import ..Alternatives: AlternativeBlocks
import ..Overlapping: AbstractOverlapping, waveform, interruptions
import ..Sequences: Sequence
import ..Variables: VariableType, duration, start_time, variables, alternative_variables, effective_time, flip_angle
import ..Pulses: GenericPulse
struct BuildingBlockPrinter{T<:BuildingBlock}
bb::T
start_time::Union{Nothing, Number}
spaces::Int
end
Base.show(io::IO, block::BuildingBlock) = print(io, BuildingBlockPrinter(block, nothing, 0))
Base.show(io::IO, seq::Sequence) = print(io, BuildingBlockPrinter(seq, 0., 0))
function Base.show(io::IO, alt_printer::BuildingBlockPrinter{<:AlternativeBlocks})
block = alt_printer.bb
print(io, "AlternativeBlocks(", block.name, ", ", length(block), " options)")
end
function _robust_value(possible_number::VariableType) function _robust_value(possible_number::VariableType)
...@@ -42,21 +23,8 @@ end ...@@ -42,21 +23,8 @@ end
_robust_value(possible_tuple::Tuple) = _robust_value([possible_tuple...]) _robust_value(possible_tuple::Tuple) = _robust_value([possible_tuple...])
function Base.show(io::IO, printer::BuildingBlockPrinter) function Base.show(io::IO, block::AbstractBlock)
block = printer.bb
print(io, nameof(typeof(block)), "(") print(io, nameof(typeof(block)), "(")
printed_duration = false
if !isnothing(printer.start_time)
print(io, "t=", @sprintf("%.3g", printer.start_time))
dur = _robust_value(duration(block))
@assert !(dur isa AbstractVector)
if !isnothing(dur) && !iszero(dur)
print(io, "-", @sprintf("%.3g", printer.start_time + dur))
printed_duration = true
end
print(io, ", ")
end
for name in propertynames(block) for name in propertynames(block)
ft = fieldtype(typeof(block), name) ft = fieldtype(typeof(block), name)
if ( if (
...@@ -67,11 +35,9 @@ function Base.show(io::IO, printer::BuildingBlockPrinter) ...@@ -67,11 +35,9 @@ function Base.show(io::IO, printer::BuildingBlockPrinter)
continue continue
end end
if ( if (
block isa AbstractOverlapping && ( ft <: Union{Nothing, AbstractBlock} ||
ft <: Union{Nothing, BuildingBlock} || (ft <: AbstractVector && eltype(ft) <: AbstractBlock)
(ft <: AbstractVector && eltype(ft) <: BuildingBlock) || )
name == :interruptions
))
continue continue
end end
...@@ -79,9 +45,6 @@ function Base.show(io::IO, printer::BuildingBlockPrinter) ...@@ -79,9 +45,6 @@ function Base.show(io::IO, printer::BuildingBlockPrinter)
end end
for fn in values(variables) for fn in values(variables)
if printed_duration && fn == duration
continue
end
if fn in [fn_alt for (fn_alt, _, _, _) in values(alternative_variables)] if fn in [fn_alt for (fn_alt, _, _, _) in values(alternative_variables)]
continue continue
end end
...@@ -104,68 +67,6 @@ function Base.show(io::IO, printer::BuildingBlockPrinter) ...@@ -104,68 +67,6 @@ function Base.show(io::IO, printer::BuildingBlockPrinter)
end end
end end
print(io, ")") print(io, ")")
if block isa AbstractOverlapping
print(io, ":")
ref_start_time = isnothing(printer.start_time) ? 0. : printer.start_time
inter = copy(interruptions(block))
prev_time = 0.
for (index_grad, (time, grad)) in enumerate(waveform(block))
while length(inter) > 0 && index_grad == (inter[1].index + 1)
to_print = popfirst!(inter)
t_eff = ref_start_time + prev_time + to_print.time
as_printer = BuildingBlockPrinter(to_print.object, t_eff - effective_time(to_print.object), printer.spaces + 2)
print(io, "\n", repeat(' ', printer.spaces + 2), "- ", @sprintf("%.3g", t_eff), ": ", as_printer)
end
printed_grad = "[" * join(map(v -> @sprintf("%.3g", v), grad), ", ") * "]"
print(io, "\n", repeat(' ', printer.spaces + 2), "- ", @sprintf("%.3g", ref_start_time + time), ": ", printed_grad)
prev_time = time
end
end
end
function Base.show(io::IO, printer::BuildingBlockPrinter{<:Sequence})
seq = printer.bb
print(io, "Sequence(")
d = _robust_value(duration(seq))
if !isnothing(d)
if !isnothing(printer.start_time)
print(io, "t=", @sprintf("%.3g", printer.start_time), "-", @sprintf("%.3g", printer.start_time + d), ", ")
else
print(io, "duration=", @sprintf("%.3g", d), ",")
end
end
TR = _robust_value(seq.TR)
if !isnothing(TR) && isfinite(TR)
print(io, "TR=", Int(round(TR)))
end
print(io, "):")
for child_index in get_children_indices(seq)
child_block = seq[child_index]
child_printer = BuildingBlockPrinter(
child_block,
isnothing(printer.start_time) ? nothing : _robust_value(start_time(seq, child_index) + printer.start_time),
printer.spaces + 2
)
print(io, "\n", repeat(' ', printer.spaces + 2), "- ", child_index, ": ", child_printer)
end
end end
function Base.show(io::IO, printer::BuildingBlockPrinter{<:GenericPulse})
fp = printer.bb
pp(value::Number) = @sprintf("%.3g", value)
print(io, "GenericPulse(")
if isnothing(printer.start_time)
print(io, "duration=", pp(duration(fp)))
else
print(io, "t=", pp(printer.start_time), "-", pp(printer.start_time + duration(fp)))
end
print(io, ", flip_angle=", pp(flip_angle(fp)), ", effective_time=", pp(effective_time(fp)), ")")
end
end end
\ No newline at end of file
...@@ -36,6 +36,12 @@ all_variables_symbols = [ ...@@ -36,6 +36,12 @@ all_variables_symbols = [
:sequence => [ :sequence => [
:TR => "Time on which an MRI sequence repeats itself in ms.", :TR => "Time on which an MRI sequence repeats itself in ms.",
:Δ => "Diffusion time in ms (i.e., time between start of the diffusion-weighted gradients).", :Δ => "Diffusion time in ms (i.e., time between start of the diffusion-weighted gradients).",
:qvec => "Net dephasing due to gradients in rad/um.",
:area_under_curve => "Net dephasing due to gradients in rad/um (same as [`qvec`](@ref)).",
:bmat => "Full 3x3 diffusion-weighting matrix in ms/um^2.",
:bval => "Size of diffusion-weighting in ms/um^2 (trace of [`bmat`](@ref)).",
:duration_dephase => "Net T2' dephasing experienced over a sequence (in ms).",
:duration_transverse => "Net T2 signal loss experienced over a sequence (in ms). This is the total duration spins spent in the transverse plane.",
], ],
:pulse => [ :pulse => [
:flip_angle => "The flip angle of the RF pulse in degrees", :flip_angle => "The flip angle of the RF pulse in degrees",
...@@ -70,7 +76,7 @@ all_variables_symbols = [ ...@@ -70,7 +76,7 @@ all_variables_symbols = [
:resolution => "Number of voxels in the final readout. During the optimisation this might produce non-integer values, but this will be fixed after optimsation.", :resolution => "Number of voxels in the final readout. During the optimisation this might produce non-integer values, but this will be fixed after optimsation.",
:oversample => "How much to oversample with ([`nsamples`](@ref) / [`resolution`](@ref))", :oversample => "How much to oversample with ([`nsamples`](@ref) / [`resolution`](@ref))",
:ramp_overlap => "Fraction of overlap between ADC event and underlying gradient pulse ramp (between 0 and 1)." :ramp_overlap => "Fraction of overlap between ADC event and underlying gradient pulse ramp (between 0 and 1)."
] ],
] ]
""" """
......
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