Skip to content

Commit

Permalink
Add CompositeFreqeuncyFilterParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
nHackel committed Aug 1, 2024
1 parent e656851 commit 25d1c01
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/PreProcessing/FrequencyFilterParameter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export AbstractFrequencyFilterParameter
abstract type AbstractFrequencyFilterParameter <: AbstractMPIRecoParameters end

export NoFrequencyFilterParameter
# TODO This requires numPeriodAverages and numPeriodGrouping and should use a freq. loading function from MPIFiles
struct NoFrequencyFilterParameter <: AbstractFrequencyFilterParameter end

function process(::Type{<:AbstractMPIRecoAlgorithm}, params::NoFrequencyFilterParameter, file::MPIFile)
Expand All @@ -10,8 +11,9 @@ end

export DirectSelectionFrequencyFilterParameters
Base.@kwdef struct DirectSelectionFrequencyFilterParameters{T <: Union{Integer, CartesianIndex{2}}, FIT <: AbstractVector{T}} <: AbstractFrequencyFilterParameter
freqIndices::FIT
freqIndices::Union{Nothing, FIT} = nothing
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 @@ -67,3 +69,11 @@ function process(::Type{<:AbstractMPIRecoAlgorithm}, params::AbstractFrequencyFi
kwargs = toKwargs(params, default = Dict{Symbol, Any}(:maxFreq => rxBandwidth(file), :recChannels => 1:rxNumChannels(file)))
filterFrequencies(file; kwargs...)
end

export CompositeFrequencyFilterParameters
Base.@kwdef struct CompositeFrequencyFilterParameters{FS} <: AbstractFrequencyFilterParameter where FS <: AbstractFrequencyFilterParameter
filters::Vector{FS}
end
function process(algoT::Type{<:AbstractMPIRecoAlgorithm}, params::CompositeFrequencyFilterParameters, file::MPIFile)
return reduce(intersect, filter(!isnothing, map(p -> process(algoT, p, file), params.filters)))
end
17 changes: 17 additions & 0 deletions test/Reconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,21 @@
c11d = reconstruct("SinglePatch", b; params..., freqFilter = DirectSelectionFrequencyFilterParameters(freqIndices = freq_components))
@test isapprox(arraydata(c11c), arraydata(c11d))

# No given freqs should be same as normal SNR thresh
freqFilter = CompositeFrequencyFilterParameters([
DirectSelectionFrequencyFilterParameters(),
SNRThresholdFrequencyFilterParameter(minFreq = params[:minFreq], SNRThresh = params[:SNRThresh], recChannels = params[:recChannels])
])
c11e = reconstruct("SinglePatch", b; params..., freqFilter = freqFilter)
@test isapprox(arraydata(c11a), arraydata(c11e))

# Custom freqs should remove one channel
custom_freqs = filter(f -> f[2] == 2, freqs)
freqFilter = CompositeFrequencyFilterParameters([
DirectSelectionFrequencyFilterParameters(freqIndices = custom_freqs),
SNRThresholdFrequencyFilterParameter(minFreq = params[:minFreq], SNRThresh = params[:SNRThresh], recChannels = params[:recChannels])
])
c11f = reconstruct("SinglePatch", b; params..., freqFilter = freqFilter)
c11g = reconstruct("SinglePatch", b; params..., recChannels = 2:2)
@test isapprox(arraydata(c11f), arraydata(c11g))
end

0 comments on commit 25d1c01

Please sign in to comment.