Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Docs #370

Merged
merged 18 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 1:length(seq)
beorostica marked this conversation as resolved.
Show resolved Hide resolved
if is_ADC_on(seq[i])
N = seq.ADC[i].N
ϕ = seq.ADC[i].ϕ
aux = ones(N) .* exp(-1im*ϕ)
beorostica marked this conversation as resolved.
Show resolved Hide resolved
cncastillo marked this conversation as resolved.
Show resolved Hide resolved
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 <[email protected]>"]
version = "0.8.1"
version = "0.8.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
107 changes: 77 additions & 30 deletions KomaMRIPlots/src/ui/DisplayFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,55 +171,102 @@ 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)",
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, name=idx[2], hovertemplate="(%{x:.4f} ms, %{y:.2f} mT/m)",
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, name=idx[3], hovertemplate="(%{x:.4f} ms, %{y:.2f} mT/m)",
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
cncastillo marked this conversation as resolved.
Show resolved Hide resolved
cncastillo marked this conversation as resolved.
Show resolved Hide resolved
for j in 1:O
rf_amp = abs.(rf.A[:,j])
rf_phase = angle.(rf.A[:,j])
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)",
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, text=ones(size(rf.t)), name="∠B1_AM", hovertemplate="(%{x:.4f} ms, ∠B1: %{y:.4f} rad)", visible="legendonly",
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"))
cncastillo marked this conversation as resolved.
Show resolved Hide resolved
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))
beorostica marked this conversation as resolved.
Show resolved Hide resolved
cncastillo marked this conversation as resolved.
Show resolved Hide resolved
cncastillo marked this conversation as resolved.
Show resolved Hide resolved
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 <[email protected]>"]
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"
117 changes: 117 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Scanner
Phantom
brain_phantom2D
brain_phantom3D
pelvis_phantom2D
```

### `Sequence`
Expand Down Expand Up @@ -127,11 +128,21 @@ roty
rotz
```

### `get_Mk`
```@docs
get_Mk
```

### `get_kspace`
```@docs
get_kspace
```

### `get_M0`
```@docs
get_M0
```

### `get_M1`
```@docs
get_M1
Expand All @@ -157,11 +168,85 @@ is_RF_on
is_GR_on
```

### `is_Gx_on`
```@docs
is_Gx_on
```

### `is_Gy_on`
```@docs
is_Gy_on
```

### `is_Gz_on`
```@docs
is_Gz_on
```

### `is_ADC_on`
```@docs
is_ADC_on
```

## Sampling-related Functions

### `get_samples`
```@docs
get_samples
```

### `get_adc_sampling_times`
```@docs
get_adc_sampling_times
```

### `get_adc_phase_compensation`
```@docs
get_adc_phase_compensation
```

### `get_block_start_times`
```@docs
get_block_start_times
```

### `DiscreteSequence`
```@docs
DiscreteSequence
```

### `discretize`
```@docs
discretize
```

## Sampling Miscellaneous

### `trapz`
```@docs
trapz
```

### `cumtrapz`
```@docs
cumtrapz
```

### `kfoldperm`
```@docs
kfoldperm
```

### `ampl`
```@docs
ampl
```

### `time`
```@docs
time
```


## Prebuilt Sequence Building Blocks

Expand Down Expand Up @@ -281,6 +366,38 @@ signal_to_raw_data
Mag
```

## Simulation Miscellaneous

### `Spinor`
```@docs
Spinor
```

### `Q`
```@docs
Q
```

### `Un`
```@docs
Un
```

### `Rx`
```@docs
Rx
```

### `Ry`
```@docs
Ry
```

### `Rz`
```@docs
Rz
```


## Plots

Expand Down
10 changes: 5 additions & 5 deletions docs/src/assets/create-your-own-phantom-plot-rho.html

Large diffs are not rendered by default.

Loading
Loading