Commit 7497e734 authored by Chris Jewell's avatar Chris Jewell
Browse files

Incorporation of Rob Challen's long-format Tier data

CHANGES:

1. New data adapter `read_challen_tier_restriction`
2. Modified `model_spec.py` to use new data adapter
parent 595ea2eb
......@@ -172,3 +172,36 @@ def read_tier_restriction_data(
# Pack into [T, M, V] array.
arr_data = data.to_xarray().to_array()
return np.transpose(arr_data, axes=[1, 2, 0])
def read_challen_tier_restriction(tier_restriction_csv, date_low, date_high):
tiers = pd.read_csv(tier_restriction_csv)
tiers["date"] = pd.to_datetime(tiers["date"], format="%Y-%m-%d")
tiers["code"] = _merge_ltla(tiers["code"])
# Separate out December tiers
tiers.loc[
(tiers["date"] > np.datetime64("2020-12-02"))
& (tiers["tier"] == "three"),
"tier",
] = "dec_three"
tiers.loc[
(tiers["date"] > np.datetime64("2020-12-02"))
& (tiers["tier"] == "two"),
"tier",
] = "dec_two"
tiers.loc[
(tiers["date"] > np.datetime64("2020-12-02"))
& (tiers["tier"] == "one"),
"tier",
] = "dec_one"
index = pd.MultiIndex.from_frame(tiers[["date", "code", "tier"]])
index = index.sort_values()
index = index[~index.duplicated()]
ser = pd.Series(1.0, index=index, name="value")
ser = ser[date_low : (date_high - np.timedelta64(1, "D"))]
xarr = ser.to_xarray()
xarr.data[np.isnan(xarr.data)] = 0.0
return xarr.loc[..., ["two", "three", "dec_two", "dec_three"]]
......@@ -35,9 +35,8 @@ def read_covariates(paths, date_low, date_high):
geo = gp.read_file(paths["geopackage"])
geo = geo.loc[geo["lad19cd"].str.startswith("E")]
tier_restriction = data.read_tier_restriction_data(
tier_restriction = data.read_challen_tier_restriction(
paths["tier_restriction_csv"],
geo[["lad19cd", "lad19nm"]],
date_low,
date_high,
)
......@@ -112,7 +111,6 @@ def CovidUK(covariates, initial_state, initial_step, num_steps, priors):
)
def xi(beta1, sigma):
# sigma = tf.constant(0.1, dtype=DTYPE)
phi = tf.constant(24.0, dtype=DTYPE)
kernel = tfp.math.psd_kernels.MaternThreeHalves(sigma, phi)
idx_pts = tf.cast(tf.range(num_steps // XI_FREQ) * XI_FREQ, dtype=DTYPE)
......@@ -123,12 +121,6 @@ def CovidUK(covariates, initial_state, initial_step, num_steps, priors):
)
def gamma0():
# return tfd.Gamma(
# concentration=tf.constant(
# priors["gamma"]["concentration"], dtype=DTYPE
# ),
# rate=tf.constant(priors["gamma"]["rate"], dtype=DTYPE),
# )
return tfd.Normal(
loc=tf.constant(0.0, dtype=DTYPE),
scale=tf.constant(100.0, dtype=DTYPE),
......
......@@ -7,7 +7,7 @@ data:
reported_cases: data/Anonymised Combined Line List 20201109.csv
case_date_type: specimen
pillar: both
tier_restriction_csv: data/NPI_dataset_full_extract_03_12_2020 (3).csv
tier_restriction_csv: data/tidyLAD19Tiers.csv
geopackage: data/UK2019mod_pop.gpkg
parameter:
......
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