Skip to content

Commit

Permalink
Added MMMBackground estimator and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthlal25 committed Mar 3, 2020
1 parent 941cf14 commit f9b750f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Background/Background.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module Background
export estimate_background,
Mean,
Median,
Mode
Mode,
MMMBackground


# Abstract types
Expand Down
23 changes: 23 additions & 0 deletions src/Background/stat_estimators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,26 @@ julia> estimate_background(Mode, data)
struct Mode <: BackgroundEstimator end

estimate_background(::Mode, data; dims = :) = mode(data)


"""
MMMBackground <: BackgroundEstimator
This estimator returns background using DAOPHOT MMM algorithm.
The background is estiamated as `3*median - 2*mean`, the factors `3` and `2` can be changed by changing `median_factor` and `mean_factor`.
# Example
```jldoctest
julia> x = ones(5,5);
julia> estimate_background(MMMBackground, x)
1.0
julia> estimate_background(MMMBackground, x, dims = 1)
1×5 Array{Float64,2}:
1.0 1.0 1.0 1.0 1.0
```
"""
struct MMMBackground <: BackgroundEstimator end

estimate_background(::MMMBackground, data; median_factor = 3, mean_factor = 2, dims = :) = median_factor * median(data, dims = dims) - mean_factor * mean(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, Median]
@testset "$E" for E in [Mean, Median, MMMBackground]
@test estimate_background(E, ones(10, 10)) == estimate_background(E(), ones(10, 10))
test_ones(E)
test_zeros(E)
Expand Down

0 comments on commit f9b750f

Please sign in to comment.