Skip to content

Commit 31f2fe8

Browse files
committed
catch and reissue imputation errors as warnings to avoid failures
1 parent ec723a9 commit 31f2fe8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/acquisition/fluview/impute_missing_values.py

Lines changed: 13 additions & 2 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

@@ -240,7 +243,7 @@ def get_fusion_parameters(known_locations):
240243
H = graph[is_known, :]
241244
W = graph[is_unknown, :]
242245
if np.linalg.matrix_rank(H) != len(atoms):
243-
raise StatespaceException("system is underdetermined")
246+
raise StatespaceException(UNDERDETERMINED_MSG)
244247

245248
HtH = np.dot(H.T, H)
246249
HtH_inv = np.linalg.inv(HtH)
@@ -293,7 +296,15 @@ def impute_missing_values(database, test_mode=False):
293296
known_values["pr"] = (0, 0, 0)
294297

295298
# get the imputation matrix and lists of known and unknown locations
296-
F, known, unknown = get_fusion_parameters(known_values.keys())
299+
try:
300+
F, known, unknown = get_fusion_parameters(known_values.keys())
301+
except StatespaceException as e:
302+
message = str(e)
303+
if message == UNDERDETERMINED_MSG:
304+
warn(message)
305+
else:
306+
print(message)
307+
continue
297308

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

0 commit comments

Comments
 (0)