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

Add split_gradient function

parent 5bcb18de
No related branches found
No related tags found
No related merge requests found
module ChangingGradientBlocks module ChangingGradientBlocks
import StaticArrays: SVector import StaticArrays: SVector
import ...Variables: VariableType, variables
import ...BuildingBlocks: GradientBlock
import JuMP: @constraint, @variable, Model, owner_model import JuMP: @constraint, @variable, Model, owner_model
import ...Variables: VariableType, variables, get_free_variable
import ...BuildingBlocks: GradientBlock
import ...Variables: qvec, bmat_gradient, gradient_strength, slew_rate, duration, variables, VariableType import ...Variables: qvec, bmat_gradient, gradient_strength, slew_rate, duration, variables, VariableType
import ...BuildingBlocks: GradientBlock, fixed, RFPulseBlock import ...BuildingBlocks: GradientBlock, fixed, RFPulseBlock
""" """
ChangingGradientBlock(grad1, slew_rate, duration, rotate, scale) ChangingGradientBlock(model, grad1, slew_rate, duration, rotate, scale)
Underlying type for any linearly changing part in a gradient waveform. Underlying type for any linearly changing part in a gradient waveform.
...@@ -18,6 +18,7 @@ Usually, you do not want to create this object directly, use a gradient waveform ...@@ -18,6 +18,7 @@ Usually, you do not want to create this object directly, use a gradient waveform
- `scale`: with which user-set parameter will this gradient be scaled (e.g., :bval). Default is no scaling. - `scale`: with which user-set parameter will this gradient be scaled (e.g., :bval). Default is no scaling.
""" """
struct ChangingGradientBlock <: GradientBlock struct ChangingGradientBlock <: GradientBlock
model :: Model
gradient_strength_start :: SVector{3, <:VariableType} gradient_strength_start :: SVector{3, <:VariableType}
slew_rate :: SVector{3, <:VariableType} slew_rate :: SVector{3, <:VariableType}
duration :: VariableType duration :: VariableType
...@@ -66,4 +67,21 @@ end ...@@ -66,4 +67,21 @@ end
variables(::Type{<:ChangingGradientBlock}) = [duration, slew_rate, gradient_strength, qvec] variables(::Type{<:ChangingGradientBlock}) = [duration, slew_rate, gradient_strength, qvec]
"""
split_gradient(constant/changing_gradient_block, times...)
Split a single gradient at a given times.
All times are relative to the start of the gradient block (in ms).
Times are assumed to be in increasing order and between 0 and the duration of the gradient block.
For N times this returns a vector with the N+1 replacement [`ConstantGradientBlock`](@ref) or [`ChangingGradientBlock`](@ref) objects.
"""
function split_gradient(cgb::ChangingGradientBlock, times...::VariableType)
all_times = [0., times...]
durations = [times[1], t[2] - t[1] for t in zip(times[1:end-1], times[2:end]), duration(cgb) - times[end]]
return [ChangingGradientBlock(cgb.gradient_strength .+ cgb.slew_rate .* t, cgb.slew_rate, d, cgb.rotate, cgb.scale) for (t, d) in zip(all_times, durations)]
end
end end
...@@ -5,6 +5,7 @@ import ...BuildingBlocks: GradientBlock ...@@ -5,6 +5,7 @@ import ...BuildingBlocks: GradientBlock
import JuMP: @constraint, @variable, Model, owner_model import JuMP: @constraint, @variable, Model, owner_model
import ...Variables: qvec, bmat_gradient, gradient_strength, slew_rate, duration, variables, VariableType import ...Variables: qvec, bmat_gradient, gradient_strength, slew_rate, duration, variables, VariableType
import ...BuildingBlocks: GradientBlock, fixed, RFPulseBlock import ...BuildingBlocks: GradientBlock, fixed, RFPulseBlock
import ..ChangingGradientBlocks: split_gradient
""" """
ConstantGradientBlock(gradient_strength, duration, rotate, scale) ConstantGradientBlock(gradient_strength, duration, rotate, scale)
...@@ -59,4 +60,9 @@ end ...@@ -59,4 +60,9 @@ end
variables(::Type{<:ConstantGradientBlock}) = [duration, gradient_strength, qvec] variables(::Type{<:ConstantGradientBlock}) = [duration, gradient_strength, qvec]
function split_gradient(cgb::ConstantGradientBlock, times...::VariableType)
durations = [times[1], t[2] - t[1] for t in zip(times[1:end-1], times[2:end]), duration(cgb) - times[end]]
return [ConstantGradientBlock(cgb.gradient_strength, d, cgb.rotate, cgb.scale) for d in durations]
end
end end
...@@ -14,8 +14,8 @@ They are still included here for clarity: ...@@ -14,8 +14,8 @@ They are still included here for clarity:
""" """
module Gradients module Gradients
include("constant_gradient_blocks.jl")
include("changing_gradient_blocks.jl") include("changing_gradient_blocks.jl")
include("constant_gradient_blocks.jl")
include("slice_selects.jl") include("slice_selects.jl")
#include("integrate_gradients.jl") #include("integrate_gradients.jl")
......
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