Skip to content
Snippets Groups Projects
Unverified Commit 44a2dffe authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Update pathways to use @defvar

parent 25a97cb0
No related branches found
No related tags found
1 merge request!2Define variables through new @defvar macro
...@@ -8,7 +8,7 @@ include("build_sequences.jl") ...@@ -8,7 +8,7 @@ include("build_sequences.jl")
include("variables.jl") include("variables.jl")
include("components/components.jl") 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("post_hoc.jl") #include("post_hoc.jl")
#include("sequences/sequences.jl") #include("sequences/sequences.jl")
...@@ -31,8 +31,8 @@ export InstantPulse, ConstantPulse, SincPulse, GenericPulse, InstantGradient, Si ...@@ -31,8 +31,8 @@ export InstantPulse, ConstantPulse, SincPulse, GenericPulse, InstantGradient, Si
import .Containers: ContainerBlock, start_time, end_time, waveform, waveform_sequence, events, BaseBuildingBlock, BuildingBlock, Wait, BaseSequence, nrepeat, Sequence, AlternativeBlocks, match_blocks!, get_index_single_TR, readout_times, iter_blocks, iter_instant_gradients, iter_instant_pulses import .Containers: ContainerBlock, start_time, end_time, waveform, waveform_sequence, events, BaseBuildingBlock, BuildingBlock, Wait, BaseSequence, nrepeat, Sequence, AlternativeBlocks, match_blocks!, get_index_single_TR, readout_times, iter_blocks, iter_instant_gradients, iter_instant_pulses
export ContainerBlock, start_time, end_time, waveform, waveform_sequence, events, BaseBuildingBlock, BuildingBlock, Wait, BaseSequence, nrepeat, Sequence, AlternativeBlocks, match_blocks!, get_index_single_TR, readout_times, iter_blocks, iter_instant_gradients, iter_instant_pulses export ContainerBlock, start_time, end_time, waveform, waveform_sequence, events, BaseBuildingBlock, BuildingBlock, Wait, BaseSequence, nrepeat, Sequence, AlternativeBlocks, match_blocks!, get_index_single_TR, readout_times, iter_blocks, iter_instant_gradients, iter_instant_pulses
#import .Pathways: Pathway, duration_transverse, duration_dephase, bval, bmat, get_pathway import .Pathways: Pathway, duration_transverse, duration_dephase, bval, bmat, get_pathway
#export Pathway, duration_transverse, duration_dephase, bval, bmat, get_pathway export Pathway, duration_transverse, duration_dephase, bval, bmat, get_pathway
#import .Parts: dwi_gradients, readout_event, excitation_pulse, refocus_pulse, Trapezoid, SliceSelect, LineReadout, opposite_kspace_lines, SpoiltSliceSelect, SliceSelectRephase, EPIReadout, interpret_image_size #import .Parts: dwi_gradients, readout_event, excitation_pulse, refocus_pulse, Trapezoid, SliceSelect, LineReadout, opposite_kspace_lines, SpoiltSliceSelect, SliceSelectRephase, EPIReadout, interpret_image_size
#export dwi_gradients, readout_event, excitation_pulse, refocus_pulse, Trapezoid, SliceSelect, LineReadout, opposite_kspace_lines, SpoiltSliceSelect, SliceSelectRephase, EPIReadout, interpret_image_size #export dwi_gradients, readout_event, excitation_pulse, refocus_pulse, Trapezoid, SliceSelect, LineReadout, opposite_kspace_lines, SpoiltSliceSelect, SliceSelectRephase, EPIReadout, interpret_image_size
......
...@@ -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 import ..Components: NoGradient, RFPulseComponent, ReadoutComponent, InstantGradient, GradientWaveform
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, qval3, bmat_gradient, VariableType, effective_time, duration, TR, bmat, bval, area_under_curve, duration_dephase, duration_transverse, VariableNotAvailable import ..Variables: VariableType, get_pathway, variables, @defvar
""" """
...@@ -71,6 +71,9 @@ function Pathway(sequence::Sequence, pulse_effects::AbstractVector, readout_inde ...@@ -71,6 +71,9 @@ function Pathway(sequence::Sequence, pulse_effects::AbstractVector, readout_inde
) )
end end
@defvar function duration_state(pathway::Pathway, transverse, positive)
return pathway.duration_states[duration_state_index(transverse, positive)]
end
""" """
duration_state(pathway::Pathway, transverse::Bool, positive::Bool) duration_state(pathway::Pathway, transverse::Bool, positive::Bool)
...@@ -83,10 +86,11 @@ The requested state can be set using `transverse` and `positive` as follows: ...@@ -83,10 +86,11 @@ The requested state can be set using `transverse` and `positive` as follows:
- `transverse=false`, `positive=false`: -longitudinal - `transverse=false`, `positive=false`: -longitudinal
- `transverse=true`, `positive=false`: -transverse - `transverse=true`, `positive=false`: -transverse
""" """
function duration_state(pathway::Pathway, transverse, positive) duration_state
return pathway.duration_states[duration_state_index(transverse, positive)]
end
@defvar function duration_transverse(pathway::Pathway)
return duration_state(pathway, true, true) + duration_state(pathway, true, false)
end
""" """
duration_transverse(pathway::Pathway) duration_transverse(pathway::Pathway)
...@@ -95,10 +99,11 @@ This determines the amount of T2-weighting as ``e^{t/T_2}``, where ``t`` is the ...@@ -95,10 +99,11 @@ This determines the amount of T2-weighting as ``e^{t/T_2}``, where ``t`` is the
Also see [`duration_dephase`](@ref) for T2'-weighting. Also see [`duration_dephase`](@ref) for T2'-weighting.
""" """
function duration_transverse(pathway::Pathway) duration_transverse
return duration_state(pathway, true, true) + duration_state(pathway, true, false)
end
@defvar function duration_dephase(pathway::Pathway)
return duration_state(pathway, true, true) - duration_state(pathway, true, false)
end
""" """
duration_dephase(pathway::Pathway) duration_dephase(pathway::Pathway)
...@@ -107,23 +112,23 @@ This determines the amount of T2'-weighting as ``e^{t/T_2'}``, where ``t`` is th ...@@ -107,23 +112,23 @@ This determines the amount of T2'-weighting as ``e^{t/T_2'}``, where ``t`` is th
Also see [`duration_transverse`](@ref) for T2-weighting. Also see [`duration_transverse`](@ref) for T2-weighting.
""" """
function duration_dephase(pathway::Pathway) duration_dephase
return duration_state(pathway, true, true) - duration_state(pathway, true, false)
end
@defvar net_dephasing(pathway::Pathway) = pathway.qvec
""" """
qvec(pathway::Pathway) net_dephasing(pathway::Pathway)
Return net displacement vector in k-space/q-space experienced by the spins following a specific [`Pathway`](@ref). Return net displacement vector in k-space/q-space experienced by the spins following a specific [`Pathway`](@ref) in kHz/um.
Only gradients active while the spins are in the transverse plane are considered. Only gradients active while the spins are in the transverse plane are considered.
Returns a NamedTuple with the `qvec` for all gradient groups. Returns a NamedTuple with the `qvec` for all gradient groups.
""" """
qvec(pathway::Pathway) = pathway.qvec net_dephasing
@defvar area_under_curve(pathway::Pathway) = norm(qvec(pathway))
""" """
area_under_curve(pathway::Pathway) area_under_curve(pathway::Pathway)
...@@ -133,9 +138,10 @@ Only gradients active while the spins are in the transverse plane are considered ...@@ -133,9 +138,10 @@ Only gradients active while the spins are in the transverse plane are considered
Returns a NamedTuple with the `area_under_curve` for all gradient groups. Returns a NamedTuple with the `area_under_curve` for all gradient groups.
""" """
area_under_curve(pathway::Pathway) = norm(qvec(pathway)) area_under_curve
@defvar bmat(pathway::Pathway) = pathway.bmat
""" """
bmat(pathway::Pathway) bmat(pathway::Pathway)
...@@ -145,8 +151,9 @@ Only gradients active while the spins are in the transverse plane are considered ...@@ -145,8 +151,9 @@ Only gradients active while the spins are in the transverse plane are considered
Returns a NamedTuple with the `bmat` for all gradient groups. Returns a NamedTuple with the `bmat` for all gradient groups.
""" """
bmat(pathway::Pathway) = pathway.bmat bmat
@defvar bval(pathway::Pathway) = tr(bmat(pathway))
""" """
bval(pathway::Pathway) bval(pathway::Pathway)
...@@ -156,7 +163,7 @@ Only gradients active while the spins are in the transverse plane will contribut ...@@ -156,7 +163,7 @@ Only gradients active while the spins are in the transverse plane will contribut
Returns a NamedTuple with the `bval` for all gradient groups. Returns a NamedTuple with the `bval` for all gradient groups.
""" """
bval(pathway::Pathway) = tr(bmat(pathway)) bval
""" """
...@@ -168,27 +175,6 @@ Multiple pathways might be returned as an array or (named)tuple. ...@@ -168,27 +175,6 @@ Multiple pathways might be returned as an array or (named)tuple.
""" """
function get_pathway end function get_pathway end
for fn in (:qvec, :area_under_curve, :bmat, :bval, :duration_dephase, :duration_transverse)
@eval function $fn(seq::Sequence)
pathway = try
get_pathway(seq)
catch e
if e isa MethodError
throw(VariableNotAvailable(typeof(seq), $fn))
end
rethrow()
end
if pathway isa Pathway
return $fn(pathway)
elseif pathway isa AbstractVector || pathway isa Tuple
return $fn.(pathway)
elseif pathway isa NumedTuple
return NamedTuple(k => $fn(v) for (k, v) in pairs(pathway))
end
error("get_pathway returned unexpected type for $seq")
end
end
""" """
interpret_pulse_effects(number_or_symbol) interpret_pulse_effects(number_or_symbol)
......
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