Skip to content

Commit

Permalink
Merge pull request #370 from JuliaHealth/patchdocs
Browse files Browse the repository at this point in the history
Update Docs
  • Loading branch information
cncastillo authored Apr 11, 2024
2 parents ef2060d + f87c5df commit bd2c310
Show file tree
Hide file tree
Showing 14 changed files with 1,845 additions and 98 deletions.
35 changes: 18 additions & 17 deletions KomaMRIBase/src/datatypes/sequence/ADC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,32 @@ function get_adc_sampling_times(seq)
end

"""
phase = get_adc_phase_compensation(seq)
comp = get_adc_phase_compensation(seq)
Returns the array of phases for every acquired sample in the sequence `seq`.
!!! note
This function is useful to compensate the phase when the RF pulse has a phase too. Refer
to the end of the [`run_sim_time_iter`](@ref) function to see its usage.
Returns an array of phase compensation factors, ``\\exp(-\\mathrm{i}\\varphi)``, which are
used to compensate the acquired signal ``S`` by applying the operation
``S_{\\mathrm{comp}} = S \\exp(-\\mathrm{i}\\varphi)`` after the simulation. This compensation
is necessary because the signal typically exhibits a phase offset of ``\\varphi`` following
RF excitation with a phase of ``\\varphi``. Such pulses are commonly employed in sequences
involving RF spoiling.
# Arguments
- `seq`: (`::Sequence`) sequence struct
# Returns
- `phase`: (`::Vector{Complex{Int64}}`, `[rad]`) array of phases for every acquired sample
- `comp`: (`::Vector{Complex}`, `[rad]`) array of phase compensations for every acquired sample
"""
function get_adc_phase_compensation(seq)
phase = ComplexF32[]
for i = 1:length(seq)
if is_ADC_on(seq[i])
N = seq.ADC[i].N
ϕ = seq.ADC[i].ϕ
aux = ones(N) .* exp(-1im*ϕ)
append!(phase, aux)
end
end
return phase
phase = ComplexF32[]
for i in 1:length(seq)
if is_ADC_on(seq[i])
N = seq.ADC[i].N
ϕ = seq.ADC[i].ϕ
aux = ones(N) .* exp(-1im * ϕ)
append!(phase, aux)
end
end
return phase
end

dur(adc::ADC) = adc.delay + adc.T
2 changes: 1 addition & 1 deletion KomaMRICore/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KomaMRICore"
uuid = "4baa4f4d-2ae9-40db-8331-a7d1080e3f4e"
authors = ["Carlos Castillo Passi <cncastillo@uc.cl>"]
version = "0.8.1"
version = "0.8.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
169 changes: 132 additions & 37 deletions KomaMRIPlots/src/ui/DisplayFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,55 +171,150 @@ function plot_seq(
usadc(x) = show_adc || isempty(x) ? x : [first(x); last(x)]
# Get the samples of the events in the sequence
seq_samples = (get_samples(seq, i; freq_in_phase) for i in 1:length(seq))
gx = (A=reduce(vcat, [block.gx.A; Inf] for block in seq_samples),
t=reduce(vcat, [block.gx.t; Inf] for block in seq_samples))
gy = (A=reduce(vcat, [block.gy.A; Inf] for block in seq_samples),
t=reduce(vcat, [block.gy.t; Inf] for block in seq_samples))
gz = (A=reduce(vcat, [block.gz.A; Inf] for block in seq_samples),
t=reduce(vcat, [block.gz.t; Inf] for block in seq_samples))
rf = (A=reduce(vcat, [usrf(block.rf.A); Inf] for block in seq_samples),
t=reduce(vcat, [usrf(block.rf.t); Inf] for block in seq_samples))
Δf = (A=reduce(vcat, [usrf(block.Δf.A); Inf] for block in seq_samples),
t=reduce(vcat, [usrf(block.Δf.t); Inf] for block in seq_samples))
adc = (A=reduce(vcat, [usadc(block.adc.A); Inf] for block in seq_samples),
t=reduce(vcat, [usadc(block.adc.t); Inf] for block in seq_samples))
gx = (
A=reduce(vcat, [block.gx.A; Inf] for block in seq_samples),
t=reduce(vcat, [block.gx.t; Inf] for block in seq_samples),
)
gy = (
A=reduce(vcat, [block.gy.A; Inf] for block in seq_samples),
t=reduce(vcat, [block.gy.t; Inf] for block in seq_samples),
)
gz = (
A=reduce(vcat, [block.gz.A; Inf] for block in seq_samples),
t=reduce(vcat, [block.gz.t; Inf] for block in seq_samples),
)
rf = (
A=reduce(vcat, [usrf(block.rf.A); Inf] for block in seq_samples),
t=reduce(vcat, [usrf(block.rf.t); Inf] for block in seq_samples),
)
Δf = (
A=reduce(vcat, [usrf(block.Δf.A); Inf] for block in seq_samples),
t=reduce(vcat, [usrf(block.Δf.t); Inf] for block in seq_samples),
)
adc = (
A=reduce(vcat, [usadc(block.adc.A); Inf] for block in seq_samples),
t=reduce(vcat, [usadc(block.adc.t); Inf] for block in seq_samples),
)

# Define general params and the vector of plots
idx = ["Gx" "Gy" "Gz"]
O = size(seq.RF, 1)
p = [scatter_fun() for _ in 1:(3 + 3O + 1)]
O = size(seq.RF, 1)
p = [scatter_fun() for _ in 1:(3 + 3O + 1)]

# For GRADs
p[1] = scatter(x=gx.t*1e3, y=gx.A*1e3, name=idx[1], hovertemplate="(%{x:.4f} ms, %{y:.2f} mT/m)",
xaxis=xaxis, yaxis=yaxis, legendgroup="Gx", showlegend=showlegend, marker=attr(color="#636EFA"))
p[2] = scatter(x=gy.t*1e3, y=gy.A*1e3, name=idx[2], hovertemplate="(%{x:.4f} ms, %{y:.2f} mT/m)",
xaxis=xaxis, yaxis=yaxis, legendgroup="Gy", showlegend=showlegend, marker=attr(color="#EF553B"))
p[3] = scatter(x=gz.t*1e3, y=gz.A*1e3, name=idx[3], hovertemplate="(%{x:.4f} ms, %{y:.2f} mT/m)",
xaxis=xaxis, yaxis=yaxis, legendgroup="Gz", showlegend=showlegend, marker=attr(color="#00CC96"))

# For RFs
for j in 1:O
rf_amp = abs.(rf.A[:,j])
rf_phase = angle.(rf.A[:,j])
fgx = is_Gy_on(seq) ? 1.0 : Inf
fgy = is_Gx_on(seq) ? 1.0 : Inf
fgz = is_Gz_on(seq) ? 1.0 : Inf
p[1] = scatter(;
x=gx.t * 1e3,
y=gx.A * 1e3 * fgx,
name=idx[1],
hovertemplate="(%{x:.4f} ms, %{y:.2f} mT/m)",
xaxis=xaxis,
yaxis=yaxis,
legendgroup="Gx",
showlegend=showlegend,
marker=attr(; color="#636EFA"),
)
p[2] = scatter(;
x=gy.t * 1e3,
y=gy.A * 1e3 * fgy,
name=idx[2],
hovertemplate="(%{x:.4f} ms, %{y:.2f} mT/m)",
xaxis=xaxis,
yaxis=yaxis,
legendgroup="Gy",
showlegend=showlegend,
marker=attr(; color="#EF553B"),
)
p[3] = scatter(;
x=gz.t * 1e3,
y=gz.A * 1e3 * fgz,
name=idx[3],
hovertemplate="(%{x:.4f} ms, %{y:.2f} mT/m)",
xaxis=xaxis,
yaxis=yaxis,
legendgroup="Gz",
showlegend=showlegend,
marker=attr(; color="#00CC96"),
)

# For RFs
frf = is_RF_on(seq) ? 1.0 : Inf
for j in 1:O
rf_amp = abs.(rf.A[:, j])
rf_phase = angle.(rf.A[:, j])
rf_phase[rf_amp .== Inf] .= Inf # Avoid weird jumps
# Plot RF
p[2j-1+3] = scatter_fun(x=rf.t*1e3, y=rf_amp*1e6, name="|B1|_AM", hovertemplate="(%{x:.4f} ms, %{y:.2f} μT)",
xaxis=xaxis, yaxis=yaxis, legendgroup="|B1|_AM", showlegend=showlegend, marker=attr(color="#AB63FA"))
p[2j+3] = scatter_fun(x=rf.t*1e3, y=rf_phase, text=ones(size(rf.t)), name="∠B1_AM", hovertemplate="(%{x:.4f} ms, ∠B1: %{y:.4f} rad)", visible="legendonly",
xaxis=xaxis, yaxis=yaxis, legendgroup="∠B1_AM", showlegend=showlegend, marker=attr(color="#FFA15A"))
p[2j - 1 + 3] = scatter_fun(;
x=rf.t * 1e3,
y=rf_amp * 1e6 * frf,
name="|B1|_AM",
hovertemplate="(%{x:.4f} ms, %{y:.2f} μT)",
xaxis=xaxis,
yaxis=yaxis,
legendgroup="|B1|_AM",
showlegend=showlegend,
marker=attr(; color="#AB63FA"),
)
p[2j + 3] = scatter_fun(;
x=rf.t * 1e3,
y=rf_phase * frf,
text=ones(size(rf.t)),
name="∠B1_AM",
hovertemplate="(%{x:.4f} ms, ∠B1: %{y:.4f} rad)",
visible="legendonly",
xaxis=xaxis,
yaxis=yaxis,
legendgroup="∠B1_AM",
showlegend=showlegend,
marker=attr(; color="#FFA15A"),
)
if !freq_in_phase
p[2j+4] = scatter_fun(x=Δf.t*1e3, y=Δf.A[:,j]*1e-3, text=ones(size(Δf.t)), name="B1_FM", hovertemplate="(%{x:.4f} ms, B1_FM: %{y:.4f} kHz)", visible="legendonly",
xaxis=xaxis, yaxis=yaxis, legendgroup="B1_FM", showlegend=showlegend, marker=attr(color="#AB63FA"), line=attr(dash="dot"))
p[2j + 4] = scatter_fun(;
x=Δf.t * 1e3,
y=Δf.A[:, j] * 1e-3 * frf,
text=ones(size(Δf.t)),
name="B1_FM",
hovertemplate="(%{x:.4f} ms, B1_FM: %{y:.4f} kHz)",
visible="legendonly",
xaxis=xaxis,
yaxis=yaxis,
legendgroup="B1_FM",
showlegend=showlegend,
marker=attr(; color="#AB63FA"),
line=attr(; dash="dot"),
)
end
end
end

# For ADCs
p[3O+3+1] = scatter_fun(x=adc.t*1e3, y=adc.A*0, name="ADC", hovertemplate="(%{x:.4f} ms, %{y:i})",
xaxis=xaxis, yaxis=yaxis, legendgroup="ADC", showlegend=showlegend, mode=(show_adc ? "markers" : "line"), marker=attr(color="#19D3F3"))
# For ADCs
fa = is_ADC_on(seq) ? 0.0 : Inf
p[3O + 3 + 1] = scatter_fun(;
x=adc.t * 1e3,
y=adc.A * fa,
name="ADC",
hovertemplate="(%{x:.4f} ms, %{y:i})",
xaxis=xaxis,
yaxis=yaxis,
legendgroup="ADC",
showlegend=showlegend,
mode=(show_adc ? "markers" : "line"),
marker=attr(; color="#19D3F3"),
)

# Return the plot
l, config = generate_seq_time_layout_config(title, width, height, range, slider, show_seq_blocks, darkmode; T0=get_block_start_times(seq))
return plot_koma(p, l; config)
l, config = generate_seq_time_layout_config(
title,
width,
height,
range,
slider,
show_seq_blocks,
darkmode;
T0=get_block_start_times(seq),
)
return plot_koma(p, l; config)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KomaMRI"
uuid = "6a340f8b-2cdf-4c04-99be-4953d9b66d0a"
authors = ["Carlos Castillo Passi <cncastillo@uc.cl>"]
version = "0.8.0"
version = "0.8.1"

[deps]
AssetRegistry = "bf4720bc-e11a-5d0c-854e-bdca1663c893"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"

[compat]
Documenter = "0.27"
Documenter = "1"
Loading

10 comments on commit bd2c310

@beorostica
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=KomaMRIBase

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104808

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a KomaMRIBase-v0.8.3 -m "<description of version>" bd2c310dde75c35b41df51505f45f998aae69532
git push origin KomaMRIBase-v0.8.3

@beorostica
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=KomaMRICore

@beorostica
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=KomaMRIFiles

@beorostica
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=KomaMRIPlots

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104809

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a KomaMRICore-v0.8.2 -m "<description of version>" bd2c310dde75c35b41df51505f45f998aae69532
git push origin KomaMRICore-v0.8.2

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104810

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a KomaMRIFiles-v0.8.2 -m "<description of version>" bd2c310dde75c35b41df51505f45f998aae69532
git push origin KomaMRIFiles-v0.8.2

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104811

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a KomaMRIPlots-v0.8.2 -m "<description of version>" bd2c310dde75c35b41df51505f45f998aae69532
git push origin KomaMRIPlots-v0.8.2

@beorostica
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104814

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.1 -m "<description of version>" bd2c310dde75c35b41df51505f45f998aae69532
git push origin v0.8.1

Please sign in to comment.