-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_forecast.py
executable file
·78 lines (53 loc) · 1.79 KB
/
run_forecast.py
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
#!/usr/bin/env python
"""
This script performs the following series of actions:
1. Downloads the latest Reff(t) trajectories and COVID-19 case data, as
provided by Nick Golding via Dropbox shared folders.
2. Generates the input Reff(t) and COVID-19 case data files for each
jurisdiction.
3. Generates a forecast for each jurisdiction.
4. Collects the forecast results and saves them to several CSV files:
(a) Forecast credible intervals;
(b) Parameter credible intervals;
(c) Daily COVID-19 case counts;
(d) Forecast sample trajectories; and
(e) Parameter and state variable sample trajectories.
5. Generates the output file for the ensemble forecast:
moss_backcast_and_forecast_samples_YYYY-MM-DD.csv
6. Generates validation plots.
"""
import argparse
import datetime
import epifx
import epifx.cmd.decl_fs
import h5py
import multiprocessing
import numpy as np
import os
import os.path
import re
import subprocess
import sys
def main(args=None):
"""
Perform all of the actions described at the top of this file.
"""
p = get_parser()
options = p.parse_args(args)
# Only generate live forecasts for the baseline model.
toml_files = [options.ff]
forecast_args = [arg for f in toml_files for arg in ['-c', f]]
num_cpus = multiprocessing.cpu_count()
if num_cpus >= 8:
# Run each forecast in parallel if there are sufficient CPUs.
forecast_args.extend(['--spawn', '8'])
epifx.cmd.decl_fs.main(args=forecast_args)
return 0
def get_parser():
p = argparse.ArgumentParser()
p.add_argument('--ff',
action = 'store', type = str, help = 'The forecast file to read (default forecast.toml).',
default = 'forecast.toml')
return p
if __name__ == "__main__":
sys.exit(main())