Commit baf2ea83 authored by Chris Jewell's avatar Chris Jewell
Browse files

Changes to prediction modules:

CHANGES:

1. `summary.py` provide a 56 day projection
2. `medium_term_prediction.py` correct issues turning dates into day, month, year.
parent ca7e464c
......@@ -2,6 +2,7 @@
import os
import yaml
from datetime import datetime
import numpy as np
import h5py
import pandas as pd
......@@ -10,7 +11,7 @@ import tensorflow as tf
import tensorflow_probability as tfp
from covid.cli_arg_parse import cli_args
from covid.util import compute_state
from covid.impl.util import compute_state
import model_spec
......@@ -49,7 +50,7 @@ def predicted_incidence(theta, xi, init_state, init_step, num_steps):
if __name__ == "__main__":
args = cli_args()
args = cli_args(["--config", "medium_term.yaml"])
with open(args.config, "r") as f:
config = yaml.load(f, Loader=yaml.FullLoader)
......@@ -110,20 +111,20 @@ if __name__ == "__main__":
"Model": "StochasticSEIR",
"ModelType": "Pillar 1+2",
"Version": 0.2,
"Creation Day": dates[0].day,
"Creation Month": dates[0].month,
"Creation Year": dates[0].year,
"Day of Value": [d.day for d in dates],
"Month of Value": [d.month for d in dates],
"Year of Value": [d.year for d in dates],
"Creation Day": dates[0].astype(datetime).day,
"Creation Month": dates[0].astype(datetime).month,
"Creation Year": dates[0].astype(datetime).year,
"Day of Value": [d.astype(datetime).day for d in dates],
"Month of Value": [d.astype(datetime).month for d in dates],
"Year of Value": [d.astype(datetime).year for d in dates],
"AgeBand": "All",
"Geography": "England",
"ValueType": "num_positive_tests",
"Value": quantiles[9, :],
}
)
foo = pd.DataFrame(quantiles.T, columns=[f"Quantile {qq:%.2f}" for qq in q])
output = pd.concat([output, foo], axis=-1)
foo = pd.DataFrame(quantiles.numpy().T, columns=[f"Quantile {qq:.2f}" for qq in q])
output = pd.concat([output, foo], axis="columns")
output.to_csv(
os.path.join(config["output"]["results_dir"], config["output"]["medium_term"]),
index=False,
......
......@@ -159,7 +159,7 @@ if __name__ == "__main__":
xi,
init_state=state_timeseries[..., -1, :],
init_step=state_timeseries.shape[-2] - 1,
num_steps=33,
num_steps=70,
)
predicted_state = compute_state(
state_timeseries[..., -1, :], prediction, model_spec.STOICHIOMETRY
......@@ -176,12 +176,14 @@ if __name__ == "__main__":
cases_14 = predicted_events(prediction[..., 4:18, 2], name="cases14")
cases_21 = predicted_events(prediction[..., 4:25, 2], name="cases21")
cases_28 = predicted_events(prediction[..., 4:32, 2], name="cases28")
cases_56 = predicted_events(prediction[..., 4:60, 2], name="cases56")
# Prevalence at day 7
prev_7 = prevalence(predicted_state[..., 11, :], covar_data["N"], name="prev7")
prev_14 = prevalence(predicted_state[..., 18, :], covar_data["N"], name="prev14")
prev_21 = prevalence(predicted_state[..., 25, :], covar_data["N"], name="prev21")
prev_28 = prevalence(predicted_state[..., 28, :], covar_data["N"], name="prev28")
prev_28 = prevalence(predicted_state[..., 32, :], covar_data["N"], name="prev28")
prev_56 = prevalence(predicted_state[..., 60, :], covar_data["N"], name="prev56")
def geosummary(geodata, summaries):
for summary in summaries:
......@@ -207,10 +209,12 @@ if __name__ == "__main__":
prev_14,
prev_21,
prev_28,
prev_56,
cases_7,
cases_14,
cases_21,
cases_28,
cases_56,
),
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment