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

Support for building-block containing just single EventComponent

parent 045c71c9
No related branches found
No related tags found
No related merge requests found
module BuildingBlocks
import LinearAlgebra: norm
import ..BaseBuildingBlocks: BaseBuildingBlock, events, waveform_sequence
import ...Variables: VariableType, duration, make_generic
import ...Components: BaseComponent, DelayedEvent
import ...Variables: VariableType, duration, make_generic, get_pulse, get_readout
import ...Components: BaseComponent, DelayedEvent, RFPulseComponent, ReadoutComponent
import ...Readouts: InstantReadout, ADC
import ...Pulses: RFPulseBlock
import ...Gradients: GradientBlock
......@@ -70,6 +70,28 @@ make_generic(other_block::BaseBuildingBlock) = BuildingBlock(duration(other_bloc
Base.keys(bb::BuildingBlock) = 1:length(bb.parts)
Base.getindex(bb::BuildingBlock, i::Integer) = bb.parts[i]
duration(go::BuildingBlock) = go.duration
duration(bb::BuildingBlock) = sum(duration, waveform_sequence(bb); init=0.)
function get_pulse(bb::BuildingBlock)
pulses = [p for p in events(bb) if p isa RFPulseComponent]
if length(pulses) == 0
error("BuildingBlock does not contain any pulses.")
end
if length(pulses) == 1
return pulses[1]
else
error("BuildingBlock contains more than one pulse. Not sure which one to return.")
end
function get_readout(bb::BuildingBlock)
readouts = [r for r in events(bb) if r isa ReadoutComponent]
if length(readouts) == 0
error("BuildingBlock does not contain any readouts.")
end
if length(readouts) == 1
return readouts[1]
else
error("BuildingBlock contains more than one readout. Not sure which one to return.")
end
end
\ No newline at end of file
......@@ -2,8 +2,9 @@ module Sequences
import StaticArrays: SVector
import JuMP: @constraint
import ...Variables: get_free_variable, TR, VariableType
import ...BuildingBlocks: WaitBlock
import ...BuildingBlocks: WaitBlock, BuildingBlock
import ...BuildSequences: get_global_model
import ...Components: EventComponent
import ..BaseSequences: ContainerBlock, BaseSequence, nrepeat
"""
......@@ -42,11 +43,12 @@ Base.getindex(s::Sequence, i::Integer) = s.blocks[i]
Converst object into something that can be included in the sequence:
- :min/:max/number/variable/nothing => [`WaitBlock`](@ref).
- `building_block` or `sequence` => no change.
- RF pulse/readout => will be embedded within a [`BuildingBlock`](@ref).
"""
to_block(cb::ContainerBlock) = cb
to_block(s::Symbol) = to_block(Val(s))
to_block(s::Union{VariableType, Nothing, Val{:min}, Val{:max}}) = WaitBlock(s)
to_block(ec::EventComponent) = BuildingBlock([], [(0, ec)]; duration=duration(ec))
end
\ No newline at end of file
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