Skip to content

Commit d8992f0

Browse files
authored
Handle cases where kadi events come from maude (#196)
Do not treat observations without level 0 as errors (this is common since kadi uses maude for events)
1 parent 16f75e1 commit d8992f0

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

agasc/supplement/magnitudes/mag_estimate.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@
4747

4848

4949
EXCEPTION_MSG = {
50-
-1: "Unknown",
5150
0: "OK",
5251
1: "No level 0 data",
5352
2: "No telemetry data",
5453
3: "Mismatch in telemetry between aca_l0 and cheta",
5554
4: "Time mismatch between cheta and level0",
5655
5: "Failed job",
5756
6: "Suspect observation",
57+
1000: "Unknown",
5858
}
59-
EXCEPTION_CODES = collections.defaultdict(lambda: -1)
59+
EXCEPTION_CODES = collections.defaultdict(lambda: 1000)
6060
EXCEPTION_CODES.update({msg: code for code, msg in EXCEPTION_MSG.items() if code > 0})
6161

6262

@@ -92,6 +92,16 @@ def __init__(
9292
"traceback": "\n".join(stack_trace),
9393
}
9494

95+
def _failed_(self):
96+
"""
97+
Check if the exception is a failure.
98+
99+
:return: bool
100+
"""
101+
return self.error_code > 1
102+
103+
failed = property(_failed_)
104+
95105
def __str__(self):
96106
return (
97107
f"MagStatsException: {self.msg} (agasc_id: {self.agasc_id}, "
@@ -1310,12 +1320,12 @@ def get_agasc_id_stats(agasc_id, obs_status_override=None, tstop=None):
13101320
{
13111321
"obs_ok": False,
13121322
"obs_suspect": False,
1313-
"obs_fail": True,
1323+
"obs_fail": e.failed,
13141324
"comments": comment if excluded_obs[i] else f"Error: {e.msg}.",
13151325
}
13161326
)
13171327
stats.append(obs_stat)
1318-
if not excluded_obs[i]:
1328+
if e.failed and not excluded_obs[i]:
13191329
logger.debug(
13201330
f" Error in get_agasc_id_stats({agasc_id=},"
13211331
f" obsid={obs['obsid']}): {e}"
@@ -1351,9 +1361,7 @@ def get_agasc_id_stats(agasc_id, obs_status_override=None, tstop=None):
13511361

13521362
if len(all_telem) - len(failures) <= 0:
13531363
# and we reach here if some observations were not flagged as bad, but all failed.
1354-
logger.debug(
1355-
f" Error in get_agasc_id_stats({agasc_id=}): There is no OK observation."
1356-
)
1364+
logger.debug(f" get_agasc_id_stats({agasc_id=}): There is no OK observation.")
13571365
return result, stats, failures
13581366

13591367
excluded_obs += np.array([t is None for t in all_telem])

0 commit comments

Comments
 (0)