Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodlz committed Aug 28, 2023
1 parent 2703ab1 commit 01697f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions kowalski/tests/test_alert_broker_ztf.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down
15 changes: 10 additions & 5 deletions kowalski/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand All @@ -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"]
Expand Down

0 comments on commit 01697f5

Please sign in to comment.