diff --git a/src/PreProcessing/FrequencyFilterParameter.jl b/src/PreProcessing/FrequencyFilterParameter.jl index be75e56..3bbac0a 100644 --- a/src/PreProcessing/FrequencyFilterParameter.jl +++ b/src/PreProcessing/FrequencyFilterParameter.jl @@ -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) @@ -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) @@ -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 \ No newline at end of file diff --git a/test/Reconstruction.jl b/test/Reconstruction.jl index b535ed5..84b084a 100644 --- a/test/Reconstruction.jl +++ b/test/Reconstruction.jl @@ -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