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# NOTE: Save this file as 'lorenz63_simulate.toml'
2
3[components]
4model = "pypfilt.examples.lorenz.Lorenz63"
5time = "pypfilt.Scalar"
6sampler = "pypfilt.sampler.LatinHypercube"
7summary = "pypfilt.summary.HDF5"
8
9[time]
10start = 0.0
11until = 25.0
12steps_per_unit = 10
13summaries_per_unit = 10
14
15[prior]
16sigma = { name = "constant", args.value = 10 }
17rho = { name = "constant", args.value = 28 }
18beta = { name = "constant", args.value = 2.66667 }
19x = { name = "constant", args.value = 1 }
20y = { name = "constant", args.value = 1 }
21z = { name = "constant", args.value = 1 }
22
23[observations.x]
24model = "pypfilt.examples.lorenz.ObsLorenz63"
25
26[observations.y]
27model = "pypfilt.examples.lorenz.ObsLorenz63"
28
29[observations.z]
30model = "pypfilt.examples.lorenz.ObsLorenz63"
31
32[filter]
33particles = 500
34prng_seed = 2001
35history_window = -1
36resample.threshold = 0.25
37
38[scenario.simulate]
Note
Call save_lorenz63_scenario_files()
to save this scenario file (and the others used in this tutorial) in the working directory.
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'
instances = list(pypfilt.load_instances(scenario_file))
assert len(instances) == 1