diff --git a/src/all_building_blocks/building_blocks.jl b/src/all_building_blocks/building_blocks.jl index 843b0f72b50d5b656164b1e2a14e180abab7483d..8f9252159e4626cb5a4fc39d2261b853bb1f4460 100644 --- a/src/all_building_blocks/building_blocks.jl +++ b/src/all_building_blocks/building_blocks.jl @@ -1,8 +1,8 @@ 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 diff --git a/src/all_sequences/sequences.jl b/src/all_sequences/sequences.jl index 423950e49c313367003e050dff5eb4fbfb5829e6..3abf1eea847f80b48a20a8b99f83944ce8e4115e 100644 --- a/src/all_sequences/sequences.jl +++ b/src/all_sequences/sequences.jl @@ -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