Skip to content

Commit

Permalink
Details on documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gsahonero committed Sep 26, 2024
1 parent 262bf14 commit cf83a9e
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 256 deletions.
289 changes: 33 additions & 256 deletions KomaMRIBase/src/datatypes/Phantom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,20 @@ julia> obj = brain_phantom2D(; axis="sagittal", ss=1)
julia> obj = brain_phantom2D(; axis="axial", us=[1, 2])
julia> phantom_values = Dict(
#CSF, GM, WM, FAT1, MUSCLE, SKIN/MUSCLE, SKULL, VESSELS, FAT2, DURA, MARROW
"T1"=> [2569, 1153, 746, 0, 0, 0, 0, 0, 0, 0, 0],
"T2" => [329, 83, 70, 0, 0, 0, 0, 0, 0, 0, 0],
"T2s" => [58, 69, 61, 0, 0, 0, 0, 0, 0, 0, 0],
"ρ" => [1, 0.86, 0.77, 0, 0, 0, 0, 0, 0, 0, 0],
"Δw" => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
julia> phantom_values =
Dict(
# T1, T2, T2*, ρ, Δw
"CSF" => [2569, 329, 58, 1, 0],
"GM" => [1153, 83, 69, 0.86, 0],
"WM" => [746, 70, 61, 0.77, 0],
"FAT1" => [0, 0, 0, 0, 0],
"MUSCLE" => [0, 0, 0, 0, 0],
"SKIN/MUSCLE" => [0, 0, 0, 0, 0],
"SKULL" => [0, 0, 0, 0, 0],
"VESSELS" => [0, 0, 0, 0, 0],
"FAT2" => [0, 0, 0, 0, 0],
"DURA" => [0, 0, 0, 0, 0],
"MARROW" => [0, 0, 0, 0, 0])
julia> obj = brain_phantom2D(; tissue_properties=phantom_values)
julia> plot_phantom_map(obj, :ρ)
Expand Down Expand Up @@ -262,127 +269,8 @@ function brain_phantom2D(; axis="axial", ss=4, us=1, tissue_properties = nothing
y = (-FOVy / 2):Δy:(FOVy / 2) #spin coordinates
x, y = x .+ y' * 0, x * 0 .+ y' #grid points


if !isnothing(custom_values)
# Define spin property vectors
T2 =
(class .== 23) * custom_values["T2"][1] .+ #CSF
(class .== 46) * custom_values["T2"][2] .+ #GM
(class .== 70) * custom_values["T2"][3] .+ #WM
(class .== 93) * custom_values["T2"][4] .+ #FAT1
(class .== 116) * custom_values["T2"][5] .+ #MUSCLE
(class .== 139) * custom_values["T2"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["T2"][7] .+ #SKULL
(class .== 185) * custom_values["T2"][8] .+ #VESSELS
(class .== 209) * custom_values["T2"][9] .+ #FAT2
(class .== 232) * custom_values["T2"][10] .+ #DURA
(class .== 255) * custom_values["T2"][11] #MARROW
T2s =
(class .== 23) * custom_values["T2s"][1] .+ #CSF
(class .== 46) * custom_values["T2s"][2] .+ #GM
(class .== 70) * custom_values["T2s"][3] .+ #WM
(class .== 93) * custom_values["T2s"][4] .+ #FAT1
(class .== 116) * custom_values["T2s"][5] .+ #MUSCLE
(class .== 139) * custom_values["T2s"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["T2s"][7] .+ #SKULL
(class .== 185) * custom_values["T2s"][8] .+ #VESSELS
(class .== 209) * custom_values["T2s"][9] .+ #FAT2
(class .== 232) * custom_values["T2s"][10] .+ #DURA
(class .== 255) * custom_values["T2s"][11] #MARROW
T1 =
(class .== 23) * custom_values["T1"][1] .+ #CSF
(class .== 46) * custom_values["T1"][2] .+ #GM
(class .== 70) * custom_values["T1"][3] .+ #WM
(class .== 93) * custom_values["T1"][4] .+ #FAT1
(class .== 116) * custom_values["T1"][5] .+ #MUSCLE
(class .== 139) * custom_values["T1"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["T1"][7] .+ #SKULL
(class .== 185) * custom_values["T1"][8] .+ #VESSELS
(class .== 209) * custom_values["T1"][9] .+ #FAT2
(class .== 232) * custom_values["T1"][10] .+ #DURA
(class .== 255) * custom_values["T1"][11] #MARROW
ρ =
(class .== 23) * custom_values["ρ"][1] .+ #CSF
(class .== 46) * custom_values["ρ"][2] .+ #GM
(class .== 70) * custom_values["ρ"][3] .+ #WM
(class .== 93) * custom_values["ρ"][4] .+ #FAT1
(class .== 116) * custom_values["ρ"][5] .+ #MUSCLE
(class .== 139) * custom_values["ρ"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["ρ"][7] .+ #SKULL
(class .== 185) * custom_values["ρ"][8] .+ #VESSELS
(class .== 209) * custom_values["ρ"][9] .+ #FAT2
(class .== 232) * custom_values["ρ"][10] .+ #DURA
(class .== 255) * custom_values["ρ"][11] #MARROW

Δw =
(class .== 23) * custom_values["Δw"][1] .+ #CSF
(class .== 46) * custom_values["Δw"][2] .+ #GM
(class .== 70) * custom_values["Δw"][3] .+ #WM
(class .== 93) * custom_values["Δw"][4] .+ #FAT1
(class .== 116) * custom_values["Δw"][5] .+ #MUSCLE
(class .== 139) * custom_values["Δw"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["Δw"][7] .+ #SKULL
(class .== 185) * custom_values["Δw"][8] .+ #VESSELS
(class .== 209) * custom_values["Δw"][9] .+ #FAT2
(class .== 232) * custom_values["Δw"][10] .+ #DURA
(class .== 255) * custom_values["Δw"][11] #MARROW
Δw = -2π.*Δw

else
# Define spin property vectors
T2 =
(class .== 23) * 329 .+ #CSF
(class .== 46) * 83 .+ #GM
(class .== 70) * 70 .+ #WM
(class .== 93) * 70 .+ #FAT1
(class .== 116) * 47 .+ #MUSCLE
(class .== 139) * 329 .+ #SKIN/MUSCLE
(class .== 162) * 0 .+ #SKULL
(class .== 185) * 0 .+ #VESSELS
(class .== 209) * 70 .+ #FAT2
(class .== 232) * 329 .+ #DURA
(class .== 255) * 70 #MARROW
T2s =
(class .== 23) * 58 .+ #CSF
(class .== 46) * 69 .+ #GM
(class .== 70) * 61 .+ #WM
(class .== 93) * 58 .+ #FAT1
(class .== 116) * 30 .+ #MUSCLE
(class .== 139) * 58 .+ #SKIN/MUSCLE
(class .== 162) * 0 .+ #SKULL
(class .== 185) * 0 .+ #VESSELS
(class .== 209) * 61 .+ #FAT2
(class .== 232) * 58 .+ #DURA
(class .== 255) * 61 #MARROW
T1 =
(class .== 23) * 2569 .+ #CSF
(class .== 46) * 833 .+ #GM
(class .== 70) * 500 .+ #WM
(class .== 93) * 350 .+ #FAT1
(class .== 116) * 900 .+ #MUSCLE
(class .== 139) * 569 .+ #SKIN/MUSCLE
(class .== 162) * 0 .+ #SKULL
(class .== 185) * 0 .+ #VESSELS
(class .== 209) * 500 .+ #FAT2
(class .== 232) * 2569 .+ #DURA
(class .== 255) * 500 #MARROW
ρ =
(class .== 23) * 1 .+ #CSF
(class .== 46) * 0.86 .+ #GM
(class .== 70) * 0.77 .+ #WM
(class .== 93) * 1 .+ #FAT1
(class .== 116) * 1 .+ #MUSCLE
(class .== 139) * 1 .+ #SKIN/MUSCLE
(class .== 162) * 0 .+ #SKULL
(class .== 185) * 0 .+ #VESSELS
(class .== 209) * 0.77 .+ #FAT2
(class .== 232) * 1 .+ #DURA
(class .== 255) * 0.77 #MARROW
Δw_fat = -220 * 2π
Δw =
(class .== 93) * Δw_fat .+ #FAT1
(class .== 209) * Δw_fat #FAT2
end
# Get tissue properties
T1, T2, T2s, ρ, Δw = default_brain_tissue_properties(class, tissue_properties)
T1 = T1 * 1e-3
T2 = T2 * 1e-3
T2s = T2s * 1e-3
Expand Down Expand Up @@ -430,13 +318,20 @@ julia> obj = brain_phantom3D(; ss=5)
julia> obj = brain_phantom3D(; us=[2, 2, 1])
julia> phantom_values = Dict(
#CSF, GM, WM, FAT1, MUSCLE, SKIN/MUSCLE, SKULL, VESSELS, FAT2, DURA, MARROW
"T1"=> [2569, 1153, 746, 0, 0, 0, 0, 0, 0, 0, 0],
"T2" => [329, 83, 70, 0, 0, 0, 0, 0, 0, 0, 0],
"T2s" => [58, 69, 61, 0, 0, 0, 0, 0, 0, 0, 0],
"ρ" => [1, 0.86, 0.77, 0, 0, 0, 0, 0, 0, 0, 0],
"Δw" => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
julia> phantom_values =
Dict(
# T1, T2, T2*, ρ, Δw
"CSF" => [2569, 329, 58, 1, 0],
"GM" => [1153, 83, 69, 0.86, 0],
"WM" => [746, 70, 61, 0.77, 0],
"FAT1" => [0, 0, 0, 0, 0],
"MUSCLE" => [0, 0, 0, 0, 0],
"SKIN/MUSCLE" => [0, 0, 0, 0, 0],
"SKULL" => [0, 0, 0, 0, 0],
"VESSELS" => [0, 0, 0, 0, 0],
"FAT2" => [0, 0, 0, 0, 0],
"DURA" => [0, 0, 0, 0, 0],
"MARROW" => [0, 0, 0, 0, 0])
julia> obj = brain_phantom3D(; tissue_properties=phantom_values)
julia> plot_phantom_map(obj, :ρ)
Expand Down Expand Up @@ -470,127 +365,9 @@ function brain_phantom3D(; ss=4, us=1, start_end=[160, 200], tissue_properties=n
x = 1 * xx .+ 0 * yy .+ 0 * zz
y = 0 * xx .+ 1 * yy .+ 0 * zz
z = 0 * xx .+ 0 * yy .+ 1 * zz

if !isnothing(custom_values)
# Define spin property vectors
T2 =
(class .== 23) * custom_values["T2"][1] .+ #CSF
(class .== 46) * custom_values["T2"][2] .+ #GM
(class .== 70) * custom_values["T2"][3] .+ #WM
(class .== 93) * custom_values["T2"][4] .+ #FAT1
(class .== 116) * custom_values["T2"][5] .+ #MUSCLE
(class .== 139) * custom_values["T2"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["T2"][7] .+ #SKULL
(class .== 185) * custom_values["T2"][8] .+ #VESSELS
(class .== 209) * custom_values["T2"][9] .+ #FAT2
(class .== 232) * custom_values["T2"][10] .+ #DURA
(class .== 255) * custom_values["T2"][11] #MARROW
T2s =
(class .== 23) * custom_values["T2s"][1] .+ #CSF
(class .== 46) * custom_values["T2s"][2] .+ #GM
(class .== 70) * custom_values["T2s"][3] .+ #WM
(class .== 93) * custom_values["T2s"][4] .+ #FAT1
(class .== 116) * custom_values["T2s"][5] .+ #MUSCLE
(class .== 139) * custom_values["T2s"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["T2s"][7] .+ #SKULL
(class .== 185) * custom_values["T2s"][8] .+ #VESSELS
(class .== 209) * custom_values["T2s"][9] .+ #FAT2
(class .== 232) * custom_values["T2s"][10] .+ #DURA
(class .== 255) * custom_values["T2s"][11] #MARROW
T1 =
(class .== 23) * custom_values["T1"][1] .+ #CSF
(class .== 46) * custom_values["T1"][2] .+ #GM
(class .== 70) * custom_values["T1"][3] .+ #WM
(class .== 93) * custom_values["T1"][4] .+ #FAT1
(class .== 116) * custom_values["T1"][5] .+ #MUSCLE
(class .== 139) * custom_values["T1"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["T1"][7] .+ #SKULL
(class .== 185) * custom_values["T1"][8] .+ #VESSELS
(class .== 209) * custom_values["T1"][9] .+ #FAT2
(class .== 232) * custom_values["T1"][10] .+ #DURA
(class .== 255) * custom_values["T1"][11] #MARROW
ρ =
(class .== 23) * custom_values["ρ"][1] .+ #CSF
(class .== 46) * custom_values["ρ"][2] .+ #GM
(class .== 70) * custom_values["ρ"][3] .+ #WM
(class .== 93) * custom_values["ρ"][4] .+ #FAT1
(class .== 116) * custom_values["ρ"][5] .+ #MUSCLE
(class .== 139) * custom_values["ρ"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["ρ"][7] .+ #SKULL
(class .== 185) * custom_values["ρ"][8] .+ #VESSELS
(class .== 209) * custom_values["ρ"][9] .+ #FAT2
(class .== 232) * custom_values["ρ"][10] .+ #DURA
(class .== 255) * custom_values["ρ"][11] #MARROW

Δw =
(class .== 23) * custom_values["Δw"][1] .+ #CSF
(class .== 46) * custom_values["Δw"][2] .+ #GM
(class .== 70) * custom_values["Δw"][3] .+ #WM
(class .== 93) * custom_values["Δw"][4] .+ #FAT1
(class .== 116) * custom_values["Δw"][5] .+ #MUSCLE
(class .== 139) * custom_values["Δw"][6] .+ #SKIN/MUSCLE
(class .== 162) * custom_values["Δw"][7] .+ #SKULL
(class .== 185) * custom_values["Δw"][8] .+ #VESSELS
(class .== 209) * custom_values["Δw"][9] .+ #FAT2
(class .== 232) * custom_values["Δw"][10] .+ #DURA
(class .== 255) * custom_values["Δw"][11] #MARROW
Δw = -2π.*Δw

else
# Define spin property vectors
T2 =
(class .== 23) * 329 .+ #CSF
(class .== 46) * 83 .+ #GM
(class .== 70) * 70 .+ #WM
(class .== 93) * 70 .+ #FAT1
(class .== 116) * 47 .+ #MUSCLE
(class .== 139) * 329 .+ #SKIN/MUSCLE
(class .== 162) * 0 .+ #SKULL
(class .== 185) * 0 .+ #VESSELS
(class .== 209) * 70 .+ #FAT2
(class .== 232) * 329 .+ #DURA
(class .== 255) * 70 #MARROW
T2s =
(class .== 23) * 58 .+ #CSF
(class .== 46) * 69 .+ #GM
(class .== 70) * 61 .+ #WM
(class .== 93) * 58 .+ #FAT1
(class .== 116) * 30 .+ #MUSCLE
(class .== 139) * 58 .+ #SKIN/MUSCLE
(class .== 162) * 0 .+ #SKULL
(class .== 185) * 0 .+ #VESSELS
(class .== 209) * 61 .+ #FAT2
(class .== 232) * 58 .+ #DURA
(class .== 255) * 61 #MARROW
T1 =
(class .== 23) * 2569 .+ #CSF
(class .== 46) * 833 .+ #GM
(class .== 70) * 500 .+ #WM
(class .== 93) * 350 .+ #FAT1
(class .== 116) * 900 .+ #MUSCLE
(class .== 139) * 569 .+ #SKIN/MUSCLE
(class .== 162) * 0 .+ #SKULL
(class .== 185) * 0 .+ #VESSELS
(class .== 209) * 500 .+ #FAT2
(class .== 232) * 2569 .+ #DURA
(class .== 255) * 500 #MARROW
ρ =
(class .== 23) * 1 .+ #CSF
(class .== 46) * 0.86 .+ #GM
(class .== 70) * 0.77 .+ #WM
(class .== 93) * 1 .+ #FAT1
(class .== 116) * 1 .+ #MUSCLE
(class .== 139) * 1 .+ #SKIN/MUSCLE
(class .== 162) * 0 .+ #SKULL
(class .== 185) * 0 .+ #VESSELS
(class .== 209) * 0.77 .+ #FAT2
(class .== 232) * 1 .+ #DURA
(class .== 255) * 0.77 #MARROW
Δw_fat = -220 * 2π
Δw =
(class .== 93) * Δw_fat .+ #FAT1
(class .== 209) * Δw_fat #FAT2
end

# Get tissue properties
T1, T2, T2s, ρ, Δw = default_brain_tissue_properties(class, tissue_properties)
T1 = T1 * 1e-3
T2 = T2 * 1e-3
T2s = T2s * 1e-3
Expand Down
2 changes: 2 additions & 0 deletions KomaMRICore/src/simulation/SimulatorCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ function simulate(
out = Xt
elseif sim_params["return_type"] == "mat"
out = sig
elseif sim_params["return_type"] == "full"
out = Dict("state" => Xt, "mat" => sig)
elseif sim_params["return_type"] == "raw"
# To visually check the simulation blocks
sim_params_raw = copy(sim_params)
Expand Down
Loading

0 comments on commit cf83a9e

Please sign in to comment.