Skip to content

Commit

Permalink
Suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillacorta committed Sep 19, 2024
1 parent f2ad03b commit e416800
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion KomaMRIBase/src/KomaMRIBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ include("timing/KeyValuesCalculation.jl")
include("datatypes/Sequence.jl")
include("datatypes/sequence/Delay.jl")
# Motion
include("motion/MotionSet.jl")
include("motion/AbstractMotion.jl")
# Phantom
include("datatypes/Phantom.jl")
# Simulator
Expand Down
4 changes: 2 additions & 2 deletions KomaMRIBase/src/datatypes/Phantom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ a property value representing a spin. This struct serves as an input for the sim
- `Dλ1`: (`::AbstractVector{T<:Real}`) spin Dλ1 (diffusion) parameter vector
- `Dλ2`: (`::AbstractVector{T<:Real}`) spin Dλ2 (diffusion) parameter vector
- `Dθ`: (`::AbstractVector{T<:Real}`) spin Dθ (diffusion) parameter vector
- `motion`: (`::AbstractMotionSet{T<:Real}`) motion set
- `motion`: (`::AbstractMotion{T<:Real}`) motion
# Returns
- `obj`: (`::Phantom`) Phantom struct
Expand Down Expand Up @@ -47,7 +47,7 @@ julia> obj.ρ
::AbstractVector{T} = zeros(eltype(x), size(x))
#Diff::Vector{DiffusionModel} #Diffusion map
#Motion
motion::AbstractMotionSet{T} = NoMotion{eltype(x)}()
motion::AbstractMotion{T} = NoMotion{eltype(x)}()
end

const NON_STRING_PHANTOM_FIELDS = Iterators.filter(x -> fieldtype(Phantom, x) != String, fieldnames(Phantom))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract type AbstractMotionSet{T<:Real} end
abstract type AbstractMotion{T<:Real} end

# NoMotion
include("nomotion/NoMotion.jl")
Expand Down
6 changes: 3 additions & 3 deletions KomaMRIBase/src/motion/motionlist/MotionList.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ julia> motionlist = MotionList(
)
```
"""
struct MotionList{T<:Real} <: AbstractMotionSet{T}
struct MotionList{T<:Real} <: AbstractMotion{T}
motions::Vector{<:Motion{T}}
end

Expand Down Expand Up @@ -91,7 +91,7 @@ Calculates the position of each spin at a set of arbitrary time instants, i.e. t
For each dimension (x, y, z), the output matrix has ``N_{\t{spins}}`` rows and `length(t)` columns.
# Arguments
- `motionset`: (`::AbstractMotionSet{T<:Real}`) phantom motion
- `motionset`: (`::AbstractMotion{T<:Real}`) phantom motion
- `x`: (`::AbstractVector{T<:Real}`, `[m]`) spin x-position vector
- `y`: (`::AbstractVector{T<:Real}`, `[m]`) spin y-position vector
- `z`: (`::AbstractVector{T<:Real}`, `[m]`) spin z-position vector
Expand Down Expand Up @@ -148,7 +148,7 @@ If `motionset::NoMotion`, this function does nothing.
If `motionset::MotionList`, this function sorts its motions.
# Arguments
- `motionset`: (`::AbstractMotionSet{T<:Real}`) phantom motion
- `motionset`: (`::AbstractMotion{T<:Real}`) phantom motion
# Returns
- `nothing`
Expand Down
2 changes: 1 addition & 1 deletion KomaMRIBase/src/motion/nomotion/NoMotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NoMotion struct. It is used to create static phantoms.
julia> nomotion = NoMotion{Float64}()
```
"""
struct NoMotion{T<:Real} <: AbstractMotionSet{T} end
struct NoMotion{T<:Real} <: AbstractMotion{T} end

Base.getindex(mv::NoMotion, p) = mv

Check warning on line 16 in KomaMRIBase/src/motion/nomotion/NoMotion.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRIBase/src/motion/nomotion/NoMotion.jl#L16

Added line #L16 was not covered by tests
Base.view(mv::NoMotion, p) = mv
Expand Down
3 changes: 1 addition & 2 deletions KomaMRICore/src/simulation/Functors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ f64(m) = paramtype(Float64, m)

# Koma motion-related adapts
adapt_storage(backend::KA.GPU, xs::MotionList) = MotionList(gpu.(xs.motions, Ref(backend)))
adapt_storage(T::Type{<:Real}, xs::NoMotion) = NoMotion{T}()
adapt_storage(T::Type{<:Real}, xs::MotionList) = MotionList(paramtype.(T, xs.motions))
adapt_storage(T::Type{<:Real}, xs::Motion) = Motion(paramtype(T, xs.action), paramtype(T, xs.time), xs.spins)
adapt_storage(T::Type{<:Real}, xs::NoMotion) = NoMotion{T}()

#The functor macro makes it easier to call a function in all the parameters
# Phantom
Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference/2-koma-base.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ heart_phantom

## `Motion`-related functions

### `AbstractMotionSet` types and related functions
### `AbstractMotion` types and related functions
```@docs
NoMotion
MotionList
Expand Down
4 changes: 2 additions & 2 deletions examples/3.tutorials/lit-05-SimpleMotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using KomaMRI # hide
sys = Scanner() # hide

# It can also be interesting to see the effect of the patient's motion during an MRI scan.
# For this, Koma provides the ability to add `motion <: AbstractMotionSet` to the phantom.
# For this, Koma provides the ability to add `motion <: AbstractMotion` to the phantom.
# In this tutorial, we will show how to add a [`Translate`](@ref) motion to a 2D brain phantom.

# First, let's load the 2D brain phantom used in the previous tutorials:
Expand Down Expand Up @@ -67,7 +67,7 @@ p2 = plot_image(abs.(image1[:, :, 1]); height=400) # hide
# S_{\mathrm{MC}}\left(t\right)=S\left(t\right)\cdot\mathrm{e}^{\mathrm{i}\Delta\phi_{\mathrm{corr}}}=S\left(t\right)\cdot\mathrm{e}^{\mathrm{i}2\pi\boldsymbol{k}\left(t\right)\cdot\boldsymbol{u}\left(t\right)}
# ```

# In practice, we would need to estimate or measure the motion before performing a motion-corrected reconstruction, but for this example, we will directly use the displacement functions ``\boldsymbol{u}(\boldsymbol{x}, t)`` defined by `obj.motion::SimpleAction`.
# In practice, we would need to estimate or measure the motion before performing a motion-corrected reconstruction, but for this example, we will directly use the displacement functions ``\boldsymbol{u}(\boldsymbol{x}, t)`` defined by `obj.motion::MotionList`.
# Since translations are rigid motions (``\boldsymbol{u}(\boldsymbol{x}, t)=\boldsymbol{u}(t)`` no position dependence), we can obtain the required displacements by calculating ``\boldsymbol{u}(\boldsymbol{x}=\boldsymbol{0},\ t=t_{\mathrm{adc}})``.
sample_times = get_adc_sampling_times(seq1)
displacements = hcat(get_spin_coords(obj.motion, [0.0], [0.0], [0.0], sample_times)...)
Expand Down

0 comments on commit e416800

Please sign in to comment.