diff --git a/kowalski/tests/test_alert_broker_ztf.py b/kowalski/tests/test_alert_broker_ztf.py index 58c39330..ff3ab65b 100644 --- a/kowalski/tests/test_alert_broker_ztf.py +++ b/kowalski/tests/test_alert_broker_ztf.py @@ -1,5 +1,6 @@ import fastavro import pytest +from copy import deepcopy from kowalski.alert_brokers.alert_broker_ztf import ZTFAlertWorker from kowalski.config import load_config from kowalski.log import log @@ -54,8 +55,9 @@ def test_make_thumbnails(self): def test_alert_filter__ml(self): """Test executing ML models on the alert""" - alert, _ = self.worker.alert_mongify(self.alert) - scores = self.worker.alert_filter__ml(alert) + alert, prv_candidates = self.worker.alert_mongify(self.alert) + all_prv_candidates = deepcopy(prv_candidates) + [deepcopy(alert["candidate"])] + scores = self.worker.alert_filter__ml(alert, all_prv_candidates) assert len(scores) > 0 log(scores) diff --git a/kowalski/utils.py b/kowalski/utils.py index 6a7d3329..7d13b0d4 100644 --- a/kowalski/utils.py +++ b/kowalski/utils.py @@ -1171,7 +1171,8 @@ def __init__(self, alert, alert_history, models, label=None, **kwargs): self.alert["candidate"]["jdstarthist"], min([a["jd"] for a in alert_history]), ) - except Exception: + except Exception as e: + log(f"Failed to compute jd_first_alert: {e}") self.alert["candidate"]["jd_first_alert"] = self.alert["candidate"][ "jdstarthist" ] @@ -1184,10 +1185,14 @@ def __init__(self, alert, alert_history, models, label=None, **kwargs): # we define days_to_peak as the time between the first alert and the alert with the lowest magpsf # and we define days_since_peak as the time between the alert with the lowest magpsf and the current alert # first we define jd_at_peak_mag as the jd of the alert with the lowest magpsf - jd_at_peak_mag = min( - [a for a in alert_history if a.get("magpsf", None) is not None], - key=lambda x: x["magpsf"], - )["jd"] + try: + jd_at_peak_mag = min( + [a for a in alert_history if a.get("magpsf", None) is not None], + key=lambda x: x["magpsf"], + )["jd"] + except Exception as e: + log(f"Failed to compute jd_at_peak_mag: {e}") + jd_at_peak_mag = self.alert["candidate"]["jd"] self.alert["candidate"]["days_to_peak"] = ( jd_at_peak_mag - self.alert["candidate"]["jd_first_alert"]