Skip to content

Commit af03314

Browse files
committed
catch and reissue imputation errors as warnings to avoid failures
1 parent cde15e0 commit af03314

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

src/acquisition/fluview/impute_missing_values.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@
5151
# third party
5252
import mysql.connector
5353
import numpy as np
54+
from warnings import warn
5455

5556
# first party
5657
import delphi.operations.secrets as secrets
5758
from delphi.utils.epiweek import delta_epiweeks
5859
from delphi.utils.geo.locations import Locations
5960

6061

62+
UNDERDETERMINED_MSG = "system is underdetermined"
63+
6164
class Database:
6265
"""Database wrapper and abstraction layer."""
6366

@@ -107,14 +110,7 @@ class Sql:
107110
# epiweek.
108111
get_known_values = """
109112
SELECT
110-
`region`, `num_ili`, `num_patients`, `num_providers`,
111-
-- TODO
112-
-- `num_age_0`,
113-
-- `num_age_1`,
114-
-- `num_age_2`,
115-
-- `num_age_3`,
116-
-- `num_age_4`,
117-
-- `num_age_5`
113+
`region`, `num_ili`, `num_patients`, `num_providers`
118114
FROM
119115
`fluview`
120116
WHERE
@@ -181,24 +177,8 @@ def get_known_values(self, issue, epiweek):
181177

182178
self.cur.execute(Database.Sql.get_known_values, (issue, epiweek))
183179
return {
184-
loc: (n_ili, n_pat, n_prov,
185-
## TODO
186-
# num_age_0,
187-
# num_age_1,
188-
# num_age_2,
189-
# num_age_3,
190-
# num_age_4,
191-
# num_age_5,
192-
)
193-
for (loc, n_ili, n_pat, n_prov,
194-
## TODO
195-
# num_age_0,
196-
# num_age_1,
197-
# num_age_2,
198-
# num_age_3,
199-
# num_age_4,
200-
# num_age_5,
201-
)
180+
loc: (n_ili, n_pat, n_prov,)
181+
for (loc, n_ili, n_pat, n_prov,)
202182
in self.cur
203183
}
204184

@@ -267,7 +247,7 @@ def get_fusion_parameters(known_locations):
267247
H = graph[is_known, :]
268248
W = graph[is_unknown, :]
269249
if np.linalg.matrix_rank(H) != len(atoms):
270-
raise StatespaceException("system is underdetermined")
250+
raise StatespaceException(UNDERDETERMINED_MSG)
271251

272252
HtH = np.dot(H.T, H)
273253
HtH_inv = np.linalg.inv(HtH)
@@ -320,7 +300,15 @@ def impute_missing_values(database, test_mode=False):
320300
known_values["pr"] = (0, 0, 0)
321301

322302
# get the imputation matrix and lists of known and unknown locations
323-
F, known, unknown = get_fusion_parameters(known_values.keys())
303+
try:
304+
F, known, unknown = get_fusion_parameters(known_values.keys())
305+
except StatespaceException as e:
306+
message = str(e)
307+
if message == UNDERDETERMINED_MSG:
308+
warn(message)
309+
else:
310+
print(message)
311+
continue
324312

325313
# finally, impute the missing values
326314
z = np.array([known_values[k] for k in known])

0 commit comments

Comments
 (0)