Defining a scenario¶
Scenarios are defined in TOML files, as illustrated in the example below.
The key components are defined in the
[components]
table:The simulation model (
model
);The time scale (
time
, eitherscalar time
ordate-time
);The prior distribution sampler (
sampler
, seepypfilt.sampler
); andThe output recorder (
summary
).
The simulation period and time-step settings are defined in the
[time]
table.The model prior distribution is defined in the
[prior]
table. Here, we have defined all the parameters and state variables to have fixed values, so that we can simulate observations from a known ground truth.Each observation model is defined in an
[observations.UNIT]
table, whereUNIT
is the observation unit (see The observation model for details). Here, we have defined three observations models, with observation units'x'
,'y'
, and'z'
.Particle filter settings are defined in the
[filter]
table, including:The number of particles (
particles
); andThe seed for the pseudo-random number generator (
prng_seed
).
Each scenario is defined in a
[scenario.ID]
table, whereID
is a unique identifier for the scenario. In Defining multiple scenarios we will see how to define multiple scenarios and scenario-specific settings.
1[components]
2model = "pypfilt.examples.lorenz.Lorenz63"
3time = "pypfilt.Scalar"
4sampler = "pypfilt.sampler.LatinHypercube"
5summary = "pypfilt.summary.HDF5"
6
7[time]
8start = 0.0
9until = 25.0
10steps_per_unit = 10
11summaries_per_unit = 10
12
13[prior]
14sigma = { name = "constant", args.value = 10 }
15rho = { name = "constant", args.value = 28 }
16beta = { name = "constant", args.value = 2.66667 }
17x = { name = "constant", args.value = 1 }
18y = { name = "constant", args.value = 1 }
19z = { name = "constant", args.value = 1 }
20
21[observations.x]
22model = "pypfilt.examples.lorenz.ObsLorenz63"
23
24[observations.y]
25model = "pypfilt.examples.lorenz.ObsLorenz63"
26
27[observations.z]
28model = "pypfilt.examples.lorenz.ObsLorenz63"
29
30[filter]
31particles = 500
32prng_seed = 2001
33history_window = -1
34resample.threshold = 0.25
35
36[scenario.simulate]
Once we have defined one or more scenarios in a TOML file, we can iterate over the scenario instances with pypfilt.load_instances()
:
def check_lorenz63_instances():
"""Ensure that the example Lorenz-63 file defines a single scenario."""
scenario_file = 'lorenz63_simulate.toml'
with open(scenario_file, 'w') as f:
f.write(pypfilt.examples.lorenz.lorenz63_simulate_toml())
instances = list(pypfilt.load_instances(scenario_file))
assert len(instances) == 1