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

Added Median for background estimation #15

Merged
merged 4 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions src/Background/Background.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Background

export estimate_background,
Mean
Mean,
Median


# Abstract types
Expand Down Expand Up @@ -33,9 +34,9 @@ estimate_background(T::Type{<:BackgroundEstimator}, d::AbstractArray; dims = :)

Perform 2D background estimation using the given estimator using meshes and kernels.

This function will estimate backgrounds in meshes of size `box_size`, using a filter kernel of size `kernel_size`. These correspond to the dimension, so for 2D data you could specify (20,) or (20,20) as the box/kernel size, matching with dims=1 for the scalar variant.
This function will estimate backgrounds in meshes of size `box_size`, using a filter kernel of size `kernel_size`. These correspond to the dimension, so for 2D data you could specify (20,) or (20,20) as the box/kernel size, matching with dims=1 for the scalar variant.

If either size is an integer, the implicit shape will be square (eg. `box_size=4` is equivalent to `box_size=(4,4)`). Contrast this to a single dimension size, like `box_size=(4,)`.
If either size is an integer, the implicit shape will be square (eg. `box_size=4` is equivalent to `box_size=(4,4)`). Contrast this to a single dimension size, like `box_size=(4,)`.

If the background estimator has no parameters (like [`Mean`](@ref)), you can just specify the type without construction.

Expand Down
21 changes: 21 additions & 0 deletions src/Background/stat_estimators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,24 @@ julia> estimate_background(Mean, data, dims=1)
struct Mean <: BackgroundEstimator end

estimate_background(::Mean, data; dims = :) = mean(data, dims = dims)

"""
Median <: BackgroundEstimator

This estimator returns the median of the input.

#Example
siddharthlal25 marked this conversation as resolved.
Show resolved Hide resolved
```jldoctest
julia> data = ones(5 ,5)

julia> estimate_background(Median, data)
1.0

julia> estimate_background(Median, data, dims=1)
1×5 Array{Float64,2}:
1.0 1.0 1.0 1.0 1.0
```
"""
struct Median <: BackgroundEstimator end

estimate_background(::Median, data; dims = :) = median(data, dims = dims)
2 changes: 1 addition & 1 deletion test/background/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function test_zeros(estimator)
@test estimate_background(estimator, data, dims = 2) ≈ zeros(10)
end

@testset "$E" for E in [Mean]
@testset "$E" for E in [Mean, Median]
@test estimate_background(E, ones(10, 10)) == estimate_background(E(), ones(10, 10))
test_ones(E)
test_zeros(E)
Expand Down