def test_operator_defaults(): M = 3 op = modelling.Operator(**{"M": M}) assert (op.linear() == np.identity(M)).all() assert op.model(3) == 3 assert op.model(3, 2, 1) == 3 assert (op.noise.sample(M) == np.zeros(M)).all()
def test_operator_dyn(): """Simple test using 1D linear advection.""" Nx = 6 tseq = modelling.Chronology(dt=1, dko=5, T=10) Fm = Fmat(Nx, c=-1, dx=1, dt=tseq.dt) def step(x, t, dt): assert dt == tseq.dt return x @ Fm.T Dyn = { "M": Nx, "model": step, "linear": lambda x, t, dt: Fm, "noise": 0, } Dyn_op = modelling.Operator(**Dyn) # Square wave x = np.array([1, 1, 1, 0, 0, 0]) x1 = Dyn_op(x, tseq.T - 1, tseq.dt) assert (x1 == np.array([0, 1, 1, 1, 0, 0])).all() x2 = Dyn_op(x1, tseq.T - 3, 1) assert (x2 == np.array([0, 0, 1, 1, 1, 0])).all() x3 = Dyn_op(x2, tseq.T - 4, 1) assert (x3 == np.array([0, 0, 0, 1, 1, 1])).all() x4 = Dyn_op(x3, tseq.T - 5, 1) assert (x4 == np.array([1, 0, 0, 0, 1, 1])).all()
"""Settings from `bib.wiljes2016second`.""" import numpy as np import dapper.mods as modelling from dapper.mods.Lorenz63.sakov2012 import HMM as _HMM from dapper.mods.Lorenz63.sakov2012 import Nx HMM = _HMM.copy() HMM.tseq = modelling.Chronology(0.01, dko=12, T=4**5, BurnIn=4) jj = np.array([0]) Obs = modelling.partial_Id_Obs(Nx, jj) Obs['noise'] = 8 HMM.Obs = modelling.Operator(**Obs) #################### # Suggested tuning #################### # Reproduce benchmarks for NETF and ESRF (here EnKF-N) from left pane of Fig 1. # from dapper.mods.Lorenz63.wiljes2017 import HMM # rmse.a reported by DAPPER / PAPER: # ------------------------------------------------------------------------------ # HMM.tseq.Ko = 10**2 # xps += OptInterp() # 5.4 / N/A # xps += Var3D(xB=0.3) # 3.0 / N/A # xps += EnKF_N(N=5) # 2.68 / N/A # xps += EnKF_N(N=30,rot=True) # 2.52 / 2.5 # xps += LNETF(N=40,rot=True,infl=1.02,Rs=1.0,loc_rad='NA') # 2.61 / ~2.2 # xps += PartFilt(N=35 ,reg=1.4,NER=0.3) # 2.05 / 1.4 * # *: tuning settings not given #
"""Settings from `bib.mandel2016hybrid`.""" import dapper.mods as modelling from dapper.mods.Lorenz63.sakov2012 import HMM as _HMM HMM = _HMM.copy() # HMM.t = modelling.Chronology(0.01,KObs=10**5,BurnIn=500), with dkObs in [5:55]. # But it's pretty safe to shorten the BurnIn and KObs. HMM.Obs = modelling.Operator(**{ 'M': 3, 'model': lambda x, t: x**3, 'noise': 8, }) # It is unclear whether the model error (cov Q) is used # just for the DA method, or also for the truth. def Q(dkObs): return modelling.GaussRV(M=HMM.Nx, C=0.01/(dkObs*HMM.t.dt)) #################### # Suggested tuning #################### # Compare EnKF scores with those in figure 5 of paper. # Note: We tune mult. inflation. # The paper only seems to use Q, probably yielding divergence. # rmse.a as reported by: DAPPER paper # --------------------------------------------------------------------------