Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Feb 10, 2025
1 parent 9f36943 commit a16c2ca
Show file tree
Hide file tree
Showing 4 changed files with 1,897 additions and 12,609 deletions.
14,470 changes: 1,889 additions & 12,581 deletions notebooks/Linear system with EnKF.ipynb

Large diffs are not rendered by default.

34 changes: 8 additions & 26 deletions src/EnKF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,40 +92,28 @@ end
"""
Define action of ENKF on EnsembleState
"""
function (enkf::ENKF{N,NZ})(t::Float64,
Δt::Float64,
function (enkf::ENKF{N,NZ})(t::Float64, Δt::Float64,
ens::EnsembleState{N,TS}) where {N,NZ,TS}

"Propagate each ensemble member"
enkf.f(t, ens)
enkf.f(t, ens) # Propagate each ensemble member

"Is data assimilation used"
if enkf.isenkf == true
# println("good prop")
"Covariance inflation if 'isinflated==true' "
if enkf.isinflated == true
enkf.A(ens)
end

"State filtering if 'isfiltered==true' "
if enkf.isfiltered == true
enkf.G(ens)
end
# println("good filtering")
enkf.isinflated && (enkf.A(ens)) # Covariance inflation
enkf.isfiltered && (enkf.G(ens)) # State filtering

"Compute mean and deviation"
ensfluc = EnsembleState(N, ens.S[1])
deviation(ensfluc, ens)
deviation(ensfluc, ens) # Compute mean and deviation

A′ = hcat(ensfluc)

" Additional computing for RTPS inflation"
if typeof(enkf.A) <: Union{RTPSInflation,RTPSAdditiveInflation,RTPSRecipeInflation}
# correct scaling by 1/N-1 instead of 1/N for small ensembles
σᵇ = std(ensfluc.S, corrected=false)
σᵇ = std(ensfluc.S; corrected=false)
end

# println("good deviation")
"Compute measurement"
mens = EnsembleState(N, zeros(NZ))

Expand All @@ -141,15 +129,12 @@ function (enkf::ENKF{N,NZ})(t::Float64,

"Compute deviation from measurement of the mean"
= mean(deepcopy(ens))

Â′ =.- enkf.m(t, Ŝ)

# println("good deviation mean")
"Get actual measurement"
zens = EnsembleState(N, zeros(NZ))
enkf.z(t + Δt, zens)
# @show zens
# println("good actual measurement")

"Perturb actual measurement"
enkf.ϵ(zens)
Expand Down Expand Up @@ -177,14 +162,12 @@ function (enkf::ENKF{N,NZ})(t::Float64,
end

"State filtering if 'isfiltered==true' "
if enkf.isfiltered == true
enkf.G(ens)
end
enkf.isfiltered && (enkf.G(ens))

" Compute a posteriori covariance"
deviation(ensfluc, ens)

A′ = hcat(ensfluc)

return t + Δt, ens, A′ * A′'
else
return t + Δt, ens
Expand All @@ -197,7 +180,6 @@ function ENKF(N, NZ, f, A, G, m, z, ϵ;
return ENKF{N,NZ}(f, A, G, m, z, ϵ, isenkf, isinflated, isfiltered, isaugmented)
end


# size(enkf::ENKF{N, TS, NZ, TZ}) where {N, TS, NZ, TZ} = (N, size, NZ)

# function Base.show(io::IO, sys::ENKF{N, TS, NZ, TZ}) where {N, TS, NZ, TZ}
Expand Down
1 change: 0 additions & 1 deletion test/inflation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ using EnKF


@testset "Additive Inflation" begin

T = AdditiveInflation(10)

@test size(T) == (10,)
Expand Down
1 change: 0 additions & 1 deletion test/initial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ using EnKF, Test
A = MvNormal(zeros(4), I)
ENS = initialize(10, A)
@test size(ENS) == (10, (4,))

end

0 comments on commit a16c2ca

Please sign in to comment.