Skip to content
Snippets Groups Projects

Define variables through new @defvar macro

Merged Michiel Cottaar requested to merge new_variables into main
12 files
+ 100
91
Compare changes
  • Side-by-side
  • Inline
Files
12
+ 11
9
@@ -2,7 +2,7 @@ module EPIReadouts
import ...Containers: BaseSequence, get_index_single_TR
import ..Trapezoids: Trapezoid, opposite_kspace_lines, LineReadout
import ...Components: ADC
import ...Variables: get_free_variable, VariableType, qval, qval3, set_simple_constraints!, resolution, inverse_voxel_size, inverse_fov, resolution, get_readout, apply_simple_constraint!, effective_time, voxel_size, ramp_overlap, oversample, dwell_time
import ...Variables: get_free_variable, VariableType, set_simple_constraints!, get_readout, apply_simple_constraint!, variables, @defvar
import ...Pathways: PathwayWalker, update_walker_till_time!, walk_pathway!
"""
@@ -49,10 +49,10 @@ function EPIReadout(; resolution::AbstractVector{<:Integer}, recenter=false, gro
get_free_variable(nothing),
ky_lines
)
apply_simple_constraint!(qval3(res.start_gradient), VariableType[-qval(pos)/2, ky_lines[1] * res.ky_step, 0.])
apply_simple_constraint!(variables.qval3(res.start_gradient), VariableType[-variables.qval(pos)/2, ky_lines[1] * res.ky_step, 0.])
if recenter
sign = isodd(length(ky_lines)) ? -1 : 1
apply_simple_constraint!(qval3(res.recenter_gradient), VariableType[sign * qval(pos)/2, -ky_lines[end] * res.ky_step, 0.])
apply_simple_constraint!(variables.qval3(res.recenter_gradient), VariableType[sign * variables.qval(pos)/2, -ky_lines[end] * res.ky_step, 0.])
end
for shift in unique(ky_lines[2:end] - ky_lines[1:end-1])
res.blips[shift] = Trapezoid(orientation=[0, shift > 0 ? 1 : -1, 0], group=group, qval=abs(shift) * res.ky_step)
@@ -61,16 +61,18 @@ function EPIReadout(; resolution::AbstractVector{<:Integer}, recenter=false, gro
return res
end
inverse_fov(epi::EPIReadout) = [inverse_fov(epi.positive_line), 1e3 * epi.ky_step]
inverse_voxel_size(epi::EPIReadout) = [inverse_voxel_size(epi.positive_line), 1e3 * epi.ky_step * maximum(abs.(epi.ky_lines))]
resolution(epi::EPIReadout) = [resolution(epi.positive_line), maximum(abs.(epi.ky_lines))]
@defvar begin
inverse_fov(epi::EPIReadout) = [variables.inverse_fov(epi.positive_line), 1e3 * epi.ky_step]
inverse_voxel_size(epi::EPIReadout) = [variables.inverse_voxel_size(epi.positive_line), 1e3 * epi.ky_step * maximum(abs.(epi.ky_lines))]
resolution(epi::EPIReadout) = [variables.resolution(epi.positive_line), maximum(abs.(epi.ky_lines))]
end
get_readout(epi::EPIReadout) = epi.positive_line
function effective_time(epi::EPIReadout)
@defvar function effective_time(epi::EPIReadout)
index = findfirst(iszero, epi.ky_lines)
if isnothing(index)
error("EPI readout does not pass through the centre of k-space")
end
return effective_time(epi, index * 2)
return variables.effective_time(epi, index * 2)
end
function get_index_single_TR(epi::EPIReadout, index::Integer)
@@ -101,7 +103,7 @@ function walk_pathway!(epi::EPIReadout, walker::PathwayWalker, pulse_effects::Ve
if nreadout[] > 0
return false
end
update_walker_till_time!(walker, block_start_time + effective_time(epi))
update_walker_till_time!(walker, block_start_time + variables.effective_time(epi))
return true
end
Loading