-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_lorenz63_timevarying.jl
98 lines (78 loc) · 3.79 KB
/
test_lorenz63_timevarying.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using Statistics
using LinearAlgebra
using Random
using Distributions
import EnFPF.Filtering
import EnFPF.Filters
import EnFPF.Models
import EnFPF.Integrators
Random.seed!(10)
D = 3
model = Models.lorenz63
ens_size = 10
ens_obs_size = 100
model_size = D
integrator = Integrators.rk4
filter_method = Filters.enfpf
x0 = randn(D)
t0 = 0.0
Δt = 0.05
transient = 2000
x = integrator(model, x0, t0, transient * Δt, Δt; inplace=false)
n_cycles = 1500
n_moments = 2
p = 6
h(v) = vcat([v .^ i for i in 1:n_moments]...)
ens_err = Symmetric(diagm(0.25 * ones(D)))
x0 = x[end, :]
window = 4
max_cycle = nothing
ensemble = x0 .+ 0.25 * randn(D, ens_size)
ensemble_obs = x[1000, :] .+ 0.25 * randn(D, ens_obs_size)
true_states, ensembles, observations = Filtering.make_observations(; ensemble=ensemble_obs,
model_true=model,
h=h,
integrator=integrator,
Γ=nothing,
Δt=Δt,
window=window,
n_cycles=n_cycles,
p=p,
ens_size=ens_obs_size,
D=D)
Γ = cov(observations[500:end, :]; dims=1) / 5
obs_err_dist = MvNormal(Γ)
observations = observations .+ rand(obs_err_dist, n_cycles)'
analyses_filtered = Filtering.filtering_cycles(; ensemble=ensemble,
model=model,
h=h,
observations=observations,
integrator=integrator,
filter_method=filter_method,
ens_size=ens_size,
Δt=Δt,
window=window,
n_cycles=n_cycles,
model_size=model_size,
Γ=Γ,
assimilate_obs=true,
calc_score=false,
max_cycle=max_cycle)
filtered = hcat([mean([h(analyses_filtered[i, :, j]) for j in 1:ens_size])
for i in 1:n_cycles]...)'
ensemble = x0 .+ 0.25 * randn(D, ens_size)
analyses_unfiltered = Filtering.filtering_cycles(; ensemble=ensemble,
model=model,
h=h,
observations=observations,
integrator=integrator,
filter_method=filter_method,
ens_size=ens_size,
Δt=Δt,
window=window,
n_cycles=n_cycles,
model_size=model_size,
Γ=Γ,
assimilate_obs=false)
nfiltered = hcat([mean([h(analyses_unfiltered[i, :, j]) for j in 1:ens_size])
for i in 1:n_cycles]...)'