Skip to content

Commit

Permalink
Changed struct types for multiple dispatch, still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris bpHPC committed Jul 23, 2024
1 parent fe2624c commit 52237f1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
15 changes: 10 additions & 5 deletions src/NMRInversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ to do list:
- Move the makie gui to extension
- rename svd function to create_kernel, and make it more user friendly
- add L curve method
- change multiple dispatch, from ::inversion1D to ::Type{inversion1D}, and use the stuct as input instead of defining variable with struct name
abstract type A end
struct a <: A end
foo(a::Type{<:A})
"""

Expand All @@ -29,15 +33,16 @@ customtypes = Dict(
:PFG => :inversion1D,
:IRCPMG => :inversion2D
)
struct inversion1D end
struct inversion2D end

abstract type inversion1D end
abstract type inversion2D end
export inversion1D, inversion2D

for (v, t) in customtypes
for (a, A) in customtypes
eval(
quote
$v = $t()
export $v
struct $a <: $A end
export $a
end
)
end
Expand Down
6 changes: 3 additions & 3 deletions src/inversions_1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct invres1D
alpha::Real
end

function invert(exptype::inversion1D, file::String=pick_file(pwd()); kwargs...)
function invert(exptype::Type{<:inversion1D}, file::String=pick_file(pwd()); kwargs...)

csvmatrix = readdlm(file, ',')
x = csvmatrix[:, 1]
Expand Down Expand Up @@ -36,13 +36,13 @@ function invert(exptype::inversion1D, file::String=pick_file(pwd()); kwargs...)
end


function invert(exptype::inversion1D, x::AbstractArray, y::Vector{<:Complex}; varargs...)
function invert(exptype::Type{<:inversion1D}, x::AbstractArray, y::Vector{<:Complex}; varargs...)

invert(exptype, x, y_re; varargs...)

end

function invert(exptype::inversion1D, x::AbstractArray, y::Vector{<:Real};
function invert(exptype::Type{<:inversion1D}, x::AbstractArray, y::Vector{<:Real};
lims=(-5, 1, 128),
α=1, order=0, solver=brd,
savedata=false, makeplot=false)
Expand Down
6 changes: 3 additions & 3 deletions src/inversions_2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ struct invres2D
end


function invert(exptype::inversion2D,directory::String=pick_folder(pwd());kwargs...)
function invert(exptype::Type{<:inversion2D}, directory::String=pick_folder(pwd()); kwargs...)

invert(exptype, import_spinsolve(directory)... ;kwargs...)
invert(exptype, import_spinsolve(directory)...; kwargs...)

end


function invert(
exptype::inversion2D, t_direct::AbstractVector, t_indirect::AbstractVector, Raw::AbstractMatrix;
exptype::Type{<:inversion2D}, t_direct::AbstractVector, t_indirect::AbstractVector, Raw::AbstractMatrix;
α=:gcv, rdir=(-5, 1, 100), rindir=(-5, 1, 100),
solver=brd, aopt=:none, order=0, savedata::Bool=true, plot::Bool=true)

Expand Down
6 changes: 3 additions & 3 deletions src/kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Create a kernel for the inversion of 1D data.
x is the experiment x axis (time or b factor etc.)
X is the range for the output x axis (T1, T2, D etc.)
"""
function create_kernel(exptype::inversion1D, x::Vector, X::Vector=exp10.(range(-5, 1, 100)))
function create_kernel(exptype::Type{<:inversion1D}, x::Vector, X::Vector=exp10.(range(-5, 1, 100)))
if exptype == IR
kernel_eq = (t, T) -> 1 - 2 * exp(-t / T)
elseif exptype in [CPMG, PFG]
Expand Down Expand Up @@ -60,7 +60,7 @@ t_direct is the direct dimension acquisition parameter
t_indirect is the indirect dimension acquisition parameter
Raw is the 2D data matrix of complex data
"""
function create_kernel(exptype::inversion2D, x_direct::AbstractVector, x_indirect::AbstractVector, Data::AbstractMatrix;
function create_kernel(exptype::Type{<:inversion1D}, x_direct::AbstractVector, x_indirect::AbstractVector, Data::AbstractMatrix;
rdir=(-5, 1, 100), rindir=(-5, 1, 100))

G = real.(Data)
Expand Down Expand Up @@ -106,7 +106,7 @@ end



function create_kernel_svd(exptype::inversion1D, t::AbstractVector, g::AbstractVector; rdir=(-5, 1, 100))
function create_kernel_svd(exptype::Type{<:inversion1D}, t::AbstractVector, g::AbstractVector; rdir=(-5, 1, 100))

if exptype == IR
kernel_eq = (t, T) -> 1 - 2 * exp(-t / T)
Expand Down

0 comments on commit 52237f1

Please sign in to comment.