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

Aqua #435

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Aqua #435

Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion KomaMRIBase/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KomaMRIBase"
uuid = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
authors = ["Carlos Castillo Passi <[email protected]>"]
version = "0.9.0"
version = "0.9.0-DEV"

[deps]
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
Expand Down
2 changes: 1 addition & 1 deletion KomaMRIBase/src/datatypes/Phantom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ end

"""Scalar multiplication of a phantom"""
*(α::Real, obj::Phantom) = begin
obj1 = copy(obj)
obj1 = deepcopy(obj)
obj1.ρ .*= α
return obj1
end
Expand Down
1 change: 0 additions & 1 deletion KomaMRIBase/src/datatypes/Sequence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Base.getindex(x::Sequence, i::Int) = Sequence(x.GR[:,i], x.RF[:,i], x.ADC[i], x.
Base.getindex(x::Sequence, i::BitArray{1}) = any(i) ? Sequence(x.GR[:,i], x.RF[:,i], x.ADC[i], x.DUR[i], x.DEF) : nothing
Base.getindex(x::Sequence, i::Array{Bool,1}) = any(i) ? Sequence(x.GR[:,i], x.RF[:,i], x.ADC[i], x.DUR[i], x.DEF) : nothing
Base.lastindex(x::Sequence) = length(x.DUR)
Base.copy(x::Sequence) where Sequence = Sequence([deepcopy(getfield(x, k)) for k ∈ fieldnames(Sequence)]...)

#Arithmetic operations
recursive_merge(x::Dict{K, V}) where {K, V} = merge(recursive_merge, x...)
Expand Down
45 changes: 28 additions & 17 deletions KomaMRIBase/src/datatypes/sequence/ADC.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
adc = ADC(N, T)
adc = ADC(N, T, delay)
adc = ADC(N, T, delay, Δf, ϕ)
adc = ADC(N, T)
adc = ADC(N, T, delay)
adc = ADC(N, T, delay, Δf, ϕ)

The ADC struct represents the Analog to Digital Converter (ADC) of a sequence event.

Expand Down Expand Up @@ -29,40 +29,51 @@ mutable struct ADC
Δf::Float64
ϕ::Float64
function ADC(N, T, delay, Δf, ϕ)
T < 0 || delay < 0 ? error("ADC timings must be positive.") : new(N, T, delay, Δf, ϕ)
if T < 0 || delay < 0
error("ADC timings must be positive.")
end
return new(N, T, delay, Δf, ϕ)
end
function ADC(N, T, delay)
T < 0 || delay < 0 ? error("ADC timings must be positive.") : new(N, T, delay, 0, 0)
if T < 0 || delay < 0
error("ADC timings must be positive.")
end
return new(N, T, delay, 0.0, 0.0)
end
function ADC(N, T)
T < 0 ? error("ADC timings must be positive.") : new(N, T, 0, 0, 0)
if T < 0
error("ADC timings must be positive.")
end
return new(N, T, 0.0, 0.0, 0.0)
end
end

# ADC comparison
Base.isapprox(adc1::ADC, adc2::ADC) = begin
return all(length(getfield(adc1, k)) ≈ length(getfield(adc2, k)) for k ∈ fieldnames(ADC))
all(getfield(adc1, k) ≈ getfield(adc2, k) for k ∈ fieldnames(ADC))
function Base.isapprox(adc1::ADC, adc2::ADC)
return all(
length(getfield(adc1, k)) ≈ length(getfield(adc2, k)) for k in fieldnames(ADC)
)
all(getfield(adc1, k) ≈ getfield(adc2, k) for k in fieldnames(ADC))
end

"""
y = getproperty(x::Vector{ADC}, f::Symbol)
y = getproperty(x::Vector{ADC}, f::Symbol)

Overloads Base.getproperty(). It is meant to access properties of the ADC vector `x`
directly without the need to iterate elementwise.

# Arguments
- `x`: (`::Vector{ADC}`) vector of ADC structs
- `f`: (`::Symbol`, opts: [`:N`, `:T`, `:delay`, `:Δf`, `:ϕ`, `:dur`]) input symbol that
represents a property of the ADC structs
represents a property of the ADC structs

# Returns
- `y`: (`::Vector{Any}`) vector with the property defined by the `f` for all elements of
the ADC vector `x`
the ADC vector `x`
"""
getproperty(x::Vector{ADC}, f::Symbol) = begin
if f == :dur
dur.(x)
dur.(x)
elseif f in fieldnames(ADC)
getfield.(x, f)
else
Expand All @@ -71,7 +82,7 @@ getproperty(x::Vector{ADC}, f::Symbol) = begin
end

"""
times = get_adc_sampling_times(seq)
times = get_adc_sampling_times(seq)

Returns an array of times when the samples of the sequence `seq` are acquired.

Expand All @@ -85,18 +96,18 @@ function get_adc_sampling_times(seq)
T0 = get_block_start_times(seq)
t = zeros(Float64, sum(seq.ADC.N))
idx = 1
for i = 1:length(seq)
for i in 1:length(seq)
if is_ADC_on(seq[i])
N = seq.ADC[i].N
t[idx:idx+N-1] .= times(seq.ADC[i]) .+ T0[i]
t[idx:(idx + N - 1)] .= times(seq.ADC[i]) .+ T0[i]
idx += N
end
end
return t
end

"""
comp = get_adc_phase_compensation(seq)
comp = get_adc_phase_compensation(seq)

Returns an array of phase compensation factors, ``\\exp(-\\mathrm{i}\\varphi)``, which are
used to compensate the acquired signal ``S`` by applying the operation
Expand Down
7 changes: 5 additions & 2 deletions KomaMRIBase/src/datatypes/sequence/Delay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ julia> seq = delay + s; plot_seq(seq)
struct Delay
T::Real
function Delay(T)
T < 0 ? error("Delays must be positive.") : new(T)
if T < 0
error("Delays must be positive.")
end
return new(T)
end
end

Expand Down Expand Up @@ -57,7 +60,7 @@ sequence.
+(s::Sequence, d::Delay) = s + empty_seq(d.T)
+(d::Delay, s::Sequence) = empty_seq(d.T) + s
function empty_seq(T)
seq = Sequence([Grad(0., 0.);;])
seq = Sequence([Grad(0., 0.);;]) # 1-block empty sequence (!= Sequence(), which is a 0-block empty sequence)
seq.DUR[1] = T
return seq
end
20 changes: 8 additions & 12 deletions KomaMRIBase/src/datatypes/sequence/Grad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,28 @@ mutable struct Grad
first
last
function Grad(A, T, rise, fall, delay)
return if all(T .< 0) || rise < 0 || fall < 0 || delay < 0
if all(T .< 0) || rise < 0 || fall < 0 || delay < 0
error("Gradient timings must be positive.")
else
new(A, T, rise, fall, delay, 0.0, 0.0)
end
return new(A, T, rise, fall, delay, 0.0, 0.0)
end
function Grad(A, T, rise, delay)
return if all(T .< 0) < 0 || rise < 0 || delay < 0
if all(T .< 0) || rise < 0 || delay < 0
error("Gradient timings must be positive.")
else
new(A, T, rise, rise, delay, 0.0, 0.0)
end
return new(A, T, rise, rise, delay, 0.0, 0.0)
end
function Grad(A, T, rise)
return if all(T .< 0) < 0 || rise < 0
if all(T .< 0) || rise < 0
error("Gradient timings must be positive.")
else
new(A, T, rise, rise, 0.0, 0.0, 0.0)
end
return new(A, T, rise, rise, 0.0, 0.0, 0.0)
end
function Grad(A, T)
return if all(T .< 0) < 0
if all(T .< 0)
error("Gradient timings must be positive.")
else
new(A, T, 0.0, 0.0, 0.0, 0.0, 0.0)
end
return new(A, T, 0.0, 0.0, 0.0, 0.0, 0.0)
end
end

Expand Down
15 changes: 10 additions & 5 deletions KomaMRIBase/src/datatypes/sequence/RF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ mutable struct RF
Δf
delay::Real
function RF(A, T, Δf, delay)
return if any(T .< 0) || delay < 0
if any(T .< 0) || delay < 0
error("RF timings must be non-negative.")
else
new(A, T, Δf, delay)
end
return new(A, T, Δf, delay)
end
function RF(A, T, Δf)
return any(T .< 0) ? error("RF timings must be non-negative.") : new(A, T, Δf, 0.0)
if any(T .< 0)
error("RF timings must be non-negative.")
end
return new(A, T, Δf, 0.0)
end
function RF(A, T)
return any(T .< 0) ? error("RF timings must be non-negative.") : new(A, T, 0.0, 0.0)
if any(T .< 0)
error("RF timings must be non-negative.")
end
return new(A, T, 0.0, 0.0)
end
end

Expand Down
1 change: 1 addition & 0 deletions KomaMRIBase/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
KomaMRIBase = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
10 changes: 5 additions & 5 deletions KomaMRIBase/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ using TestItems, TestItemRunner
delay = Delay(T)
@test delay.T ≈ T

# Test delay construction error for negative values
err = Nothing
try Delay(-T) catch err end
@test err isa ErrorException

# Just checking to ensure that show() doesn't get stuck and that it is covered
show(IOBuffer(), "text/plain", delay)
@test true
Expand Down Expand Up @@ -655,3 +650,8 @@ end
@test KomaMRIBase.trapz(dt, x)[1] ≈ 4 #Triangle area = bh/2, with b = 4 and h = 2
@test KomaMRIBase.cumtrapz(dt, x) ≈ [0.5 2 3.5 4]
end

@testitem "Aqua" tags=[:base, :aqua] begin
using Aqua
Aqua.test_all(KomaMRIBase)
end
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.9.0"
version = "0.9.0-DEV"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
1 change: 1 addition & 0 deletions KomaMRICore/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
KomaMRIBase = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
Expand Down
5 changes: 5 additions & 0 deletions KomaMRICore/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,9 @@ end

@suppress print_devices()
@test true
end

@testitem "Aqua" tags=[:core, :aqua] begin
using Aqua
Aqua.test_all(KomaMRICore)
end
2 changes: 1 addition & 1 deletion KomaMRIFiles/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KomaMRIFiles"
uuid = "fcf631a6-1c7e-4e88-9e64-b8888386d9dc"
authors = ["Carlos Castillo Passi <[email protected]>"]
version = "0.9.0"
version = "0.9.0-DEV"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand Down
1 change: 1 addition & 0 deletions KomaMRIFiles/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
KomaMRIBase = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
KomaMRIFiles = "fcf631a6-1c7e-4e88-9e64-b8888386d9dc"
MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
Expand Down
5 changes: 5 additions & 0 deletions KomaMRIFiles/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ end
end
end
end

@testitem "Aqua" tags=[:files, :aqua] begin
using Aqua
Aqua.test_all(KomaMRIFiles)
end
2 changes: 1 addition & 1 deletion KomaMRIPlots/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KomaMRIPlots"
uuid = "76db0263-63f3-4d26-bb9a-5dba378db904"
authors = ["Carlos Castillo Passi <[email protected]>"]
version = "0.9.0"
version = "0.9.0-DEV"

[deps]
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
Expand Down
Loading
Loading