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

Allow reconstruct method to point to plan files directly #40

Merged
merged 2 commits into from
Aug 1, 2024
Merged
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
20 changes: 12 additions & 8 deletions src/AlgorithmInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ export planpath, plandir
plandir() = abspath(homedir(), ".mpi", "RecoPlans")

function planpath(name::AbstractString)
if isfile(name)
return name
end

for dir in [plandir(), joinpath(@__DIR__, "..", "config")]
filename = joinpath(dir, string(name, ".toml"))
if isfile(filename)
return filename
end
end
throw(ArgumentError("Could not find a suitable MPI reconstruction plan with name $name.\nCustom plans can be stored in $(plandir())."))
throw(ArgumentError("Could not find a suitable MPI reconstruction plan with name $name. Custom plans can be stored in $(plandir())."))
end

const recoPlans = LRU{UInt64, RecoPlan}(maxsize = 3)
Expand All @@ -65,7 +69,7 @@ Perform a reconstruction with the `RecoPlan` specified by `name` and given `data
Additional keyword arguments can be passed to the reconstruction plan.

`RecoPlans` can be stored in the directory `$(plandir())` or in the MPIReco package config folder. The first plan found is used. The cache considers the last modification time of the plan file.
If a keyword argument changes the structure of the plan the cache is bypassed.
If a keyword argument changes the structure of the plan the cache is bypassed. Alternatively, name can be a path to specific plan file.

The cache can be emptied with `emptyRecoCache!()`.

Expand All @@ -76,26 +80,26 @@ julia> mdf = MPIFile("data.mdf");
julia> reconstruct("SinglePatch", mdf; solver = Kaczmarz, reg = [L2Regularization(0.3f0)], iterations = 10, frames = 1:10, ...)
```
"""
function reconstruct(name::AbstractString, data::MPIFile, cache::Bool = true; kwargs...)
plan = loadRecoPlan(name, cache; kwargs...)
function reconstruct(name::AbstractString, data::MPIFile, cache::Bool = true, modules = [AbstractImageReconstruction, MPIFiles, MPIReco, RegularizedLeastSquares]; kwargs...)
plan = loadRecoPlan(name, cache, modules; kwargs...)
setAll!(plan; kwargs...)
return reconstruct(build(plan), data)
end
function loadRecoPlan(name::AbstractString, cache::Bool; kwargs...)
function loadRecoPlan(name::AbstractString, cache::Bool, modules; kwargs...)
planfile = AbstractImageReconstruction.planpath(MPIReco, name)

# If the user disables caching or changes the plan structure we bypass the cache
kwargValues = values(values(kwargs))
if !cache || any(val -> isa(val, RecoPlan) || isa(val, AbstractImageReconstructionParameters), kwargValues)
return loadRecoPlan(planfile)
return loadRecoPlan(planfile, modules)
end

key = hash(planfile, hash(mtime(planfile)))
return get!(recoPlans, key) do
loadRecoPlan(planfile)
loadRecoPlan(planfile, modules)
end
end
loadRecoPlan(planfile::AbstractString) = loadPlan(planfile, [AbstractImageReconstruction, MPIFiles, MPIReco, RegularizedLeastSquares])
loadRecoPlan(planfile::AbstractString, modules) = loadPlan(planfile, modules)

export emptyRecoCache!
"""
Expand Down
19 changes: 14 additions & 5 deletions src/PreProcessing/FrequencyFilterParameter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ function process(::Type{<:AbstractMPIRecoAlgorithm}, params::NoFrequencyFilterPa
end

export DirectSelectionFrequencyFilterParameters
Base.@kwdef struct DirectSelectionFrequencyFilterParameters{T <: Union{Integer, CartesianIndex{2}}, FIT <: AbstractVector{T}} <: AbstractFrequencyFilterParameter
freqIndices::Union{Nothing, FIT} = nothing
struct DirectSelectionFrequencyFilterParameters{T <: Union{Integer, CartesianIndex{2}}, FIT <: AbstractVector{T}} <: AbstractFrequencyFilterParameter
freqIndices::Union{Nothing, FIT}
function DirectSelectionFrequencyFilterParameters(;freqIndices::FIT = nothing) where FIT
if isnothing(freqIndices)
el = CartesianIndex{2}
v = Vector{el}
else
el = eltype(freqIndices)
v = typeof(v)
end
new{el, v}(freqIndices)
end
end
DirectSelectionFrequencyFilterParameters() = DirectSelectionFrequencyFilterParameters{CartesianIndex{2}, Vector{CartesianIndex{2}}}(nothing)
function process(::Type{<:AbstractMPIRecoAlgorithm}, params::DirectSelectionFrequencyFilterParameters{T}, file::MPIFile) where T <: Integer
nFreq = params.freqIndices
nReceivers = rxNumChannels(file)
Expand Down Expand Up @@ -71,8 +80,8 @@ function process(::Type{<:AbstractMPIRecoAlgorithm}, params::AbstractFrequencyFi
end

export CompositeFrequencyFilterParameters
Base.@kwdef struct CompositeFrequencyFilterParameters{FS} <: AbstractFrequencyFilterParameter where FS <: AbstractFrequencyFilterParameter
filters::Vector{FS}
Base.@kwdef struct CompositeFrequencyFilterParameters <: AbstractFrequencyFilterParameter
filters::Vector{AbstractFrequencyFilterParameter}
end
function process(algoT::Type{<:AbstractMPIRecoAlgorithm}, params::CompositeFrequencyFilterParameters, file::MPIFile)
return reduce(intersect, filter(!isnothing, map(p -> process(algoT, p, file), params.filters)))
Expand Down
4 changes: 2 additions & 2 deletions src/Weighting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function process(::Type{<:AbstractMPIRecoAlgorithm}, params::RowNormWeightingPar
end

export CompositeWeightingParameters
Base.@kwdef struct CompositeWeightingParameters{WS} <: AbstractWeightingParameters where WS <: AbstractWeightingParameters
weightingParameters::Vector{WS}
Base.@kwdef struct CompositeWeightingParameters <: AbstractWeightingParameters
weightingParameters::Vector{AbstractWeightingParameters}
end
function process(algoT::Type{<:AbstractMPIRecoAlgorithm}, params::CompositeWeightingParameters, args...)
weights = map(p -> process(algoT, p, args...), params.weightingParameters)
Expand Down
Loading