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

Treat pathway values as variables

parent 174a8f68
No related branches found
No related tags found
No related merge requests found
...@@ -27,8 +27,8 @@ export InstantPulse, ConstantPulse, SincPulse, GenericPulse, InstantGradient, Si ...@@ -27,8 +27,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 import .Containers: ContainerBlock, start_time, end_time, waveform, waveform_sequence, events, BaseBuildingBlock, BuildingBlock, Wait, BaseSequence, nrepeat, Sequence, AlternativeBlocks, match_blocks!, get_index_single_TR
export ContainerBlock, start_time, end_time, waveform, waveform_sequence, events, BaseBuildingBlock, BuildingBlock, Wait, BaseSequence, nrepeat, Sequence, AlternativeBlocks, match_blocks!, get_index_single_TR export ContainerBlock, start_time, end_time, waveform, waveform_sequence, events, BaseBuildingBlock, BuildingBlock, Wait, BaseSequence, nrepeat, Sequence, AlternativeBlocks, match_blocks!, get_index_single_TR
import .Pathways: Pathway, duration_transverse, duration_dephase, bval, bmat import .Pathways: Pathway, duration_transverse, duration_dephase, bval, bmat, get_pathway
export Pathway, duration_transverse, duration_dephase, bval, bmat export Pathway, duration_transverse, duration_dephase, bval, bmat, get_pathway
import .Parts: excitation_pulse, refocus_pulse, epi_readout, single_line_readout, Trapezoid, SliceSelect, LineReadout, opposite_kspace_lines, SpoiltSliceSelect, SliceSelectRephase, EPIReadout import .Parts: excitation_pulse, refocus_pulse, epi_readout, single_line_readout, Trapezoid, SliceSelect, LineReadout, opposite_kspace_lines, SpoiltSliceSelect, SliceSelectRephase, EPIReadout
export excitation_pulse, refocus_pulse, epi_readout, single_line_readout, Trapezoid, SliceSelect, LineReadout, opposite_kspace_lines, SpoiltSliceSelect, SliceSelectRephase, EPIReadout export excitation_pulse, refocus_pulse, epi_readout, single_line_readout, Trapezoid, SliceSelect, LineReadout, opposite_kspace_lines, SpoiltSliceSelect, SliceSelectRephase, EPIReadout
......
...@@ -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 import ..Variables: qvec, qval, bmat_gradient, VariableType, effective_time, duration, TR, variables
""" """
...@@ -112,54 +112,81 @@ end ...@@ -112,54 +112,81 @@ end
""" """
qvec(pathway::Pathway; group=nothing) qvec(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).
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.
By default gradients that have been added to a specific `group` are ignored. Returns a NamedTuple with the `qvec` for all gradient groups.
You can set `group=<name>` to consider a specific `group.
""" """
qvec(pathway::Pathway; group=nothing) = get(pathway.qvec, group, zero(SVector{3, Float64})) qvec(pathway::Pathway, group) = pathway.qvec[group]
""" """
area_under_curve(pathway::Pathway; group=nothing) area_under_curve(pathway::Pathway)
Return net displacement in k-space (i.e., spoiling) experienced by the spins following a specific [`Pathway`](@ref). Return net displacement in k-space (i.e., spoiling) experienced by the spins following a specific [`Pathway`](@ref).
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.
By default gradients that have been added to a specific `group` are ignored. Returns a NamedTuple with the `area_under_curve` for all gradient groups.
You can set `group=<name>` to consider a specific `group.
""" """
area_under_curve(pathway::Pathway; group=nothing) = qval(pathway; group=group) area_under_curve(pathway::Pathway, group) = norm(qvec(pathway, group))
""" """
bmat(pathway::Pathway; group=nothing) bmat(pathway::Pathway)
Return 3x3 diffusion-weighted matrix experienced by the spins following a specific [`Pathway`](@ref) in rad^2 ms/um^2. Return 3x3 diffusion-weighted matrix experienced by the spins following a specific [`Pathway`](@ref) in rad^2 ms/um^2.
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.
By default gradients that have been added to a specific `group` are ignored. Returns a NamedTuple with the `bmat` for all gradient groups.
You can set `group=<name>` to consider a specific `group.
""" """
bmat(pathway::Pathway; group=nothing) = get(pathway.bmat, group, zero(SMatrix{3, 3, Float64, 9})) bmat(pathway::Pathway, group) = pathway.bmat[group]
""" """
bval(pathway::Pathway; group=nothing) bval(pathway::Pathway)
Return size of diffusion-weighting experienced by the spins following a specific [`Pathway`](@ref) in rad^2 ms/um^2. Return size of diffusion-weighting experienced by the spins following a specific [`Pathway`](@ref) in rad^2 ms/um^2.
Only gradients active while the spins are in the transverse plane will contribute to the diffusion weighting. Only gradients active while the spins are in the transverse plane will contribute to the diffusion weighting.
By default gradients that have been added to a specific `group` are ignored. Returns a NamedTuple with the `bval` for all gradient groups.
You can set `group=<name>` to consider a specific `group.
""" """
bval(pathway::Pathway; group=nothing) = tr(bmat(pathway; group=group)) bval(pathway::Pathway, group) = tr(bmat(pathway, group))
"""
get_pathway(sequence)
Gets the main [`PathWay`](@ref) that spins are expected to experience in the sequence.
Multiple pathways might be returned as an array or (named)tuple.
"""
function get_pathway end
for fn in (:qvec, :area_under_curve, :bmat, :bval)
@eval function $fn(pathway::Pathway)
return NamedTuple(group => $fn(pathway, group) for group in keys(pathway.qvec))
end
end
for fn in (:qvec, :area_under_curve, :bmat, :bval, :duration_dephase, :duration_transverse)
@eval function $fn(seq::Sequence)
pathway = get_pathway(seq)
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
@eval variables[$(QuoteNode(fn))] = $fn
end
""" """
......
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