Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make photometry: add all alert photometry #249

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 75 additions & 2 deletions kowalski/alert_brokers/alert_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
time_stamp,
timer,
)
from warnings import simplefilter

simplefilter(action="ignore", category=pd.errors.PerformanceWarning)

# Tensorflow is problematic for Mac's currently, so we can add an option to disable it
USE_TENSORFLOW = os.environ.get("USE_TENSORFLOW", True) in [
Expand Down Expand Up @@ -1677,6 +1680,37 @@ def alert_sentinel_skyportal(self, alert, prv_candidates, passed_filters):
log(e)
alert["prv_candidates"] = prv_candidates

# also get all the alerts for this object, to make sure to have all the detections
try:
all_alerts = list(
retry(self.mongo.db[self.collection_alerts].find)(
{
"objectId": alert["objectId"],
"candid": {"$ne": alert["candid"]},
},
{
"candidate": 1,
},
)
)
all_alerts = [
{**a["candidate"]} for a in all_alerts if "candidate" in a
]
# add to prv_candidates the detections that are not already in there
# use the jd and the fid to match
for a in all_alerts:
if not any(
[
(a["jd"] == p["jd"]) and (a["fid"] == p["fid"])
for p in alert["prv_candidates"]
]
):
alert["prv_candidates"].append(a)
del all_alerts
except Exception as e:
# this should never happen, but just in case
log(f"Failed to get all alerts for {alert['objectId']}: {e}")

self.alert_put_photometry(alert)

# post thumbnails
Expand Down Expand Up @@ -1765,6 +1799,37 @@ def alert_sentinel_skyportal(self, alert, prv_candidates, passed_filters):
# post alert photometry in single call to /api/photometry
alert["prv_candidates"] = prv_candidates

# also get all the alerts for this object, to make sure to have all the detections
try:
all_alerts = list(
retry(self.mongo.db[self.collection_alerts].find)(
{
"objectId": alert["objectId"],
"candid": {"$ne": alert["candid"]},
},
{
"candidate": 1,
},
)
)
all_alerts = [
{**a["candidate"]} for a in all_alerts if "candidate" in a
]
# add to prv_candidates the detections that are not already in there
# use the jd and the fid to match
for a in all_alerts:
if not any(
[
(a["jd"] == p["jd"]) and (a["fid"] == p["fid"])
for p in alert["prv_candidates"]
]
):
alert["prv_candidates"].append(a)
del all_alerts
except Exception as e:
# this should never happen, but just in case
log(f"Failed to get all alerts for {alert['objectId']}: {e}")

self.alert_put_photometry(alert)

if len(autosave_group_ids):
Expand Down Expand Up @@ -1885,14 +1950,22 @@ def alert_sentinel_skyportal(self, alert, prv_candidates, passed_filters):
)
if response.json()["status"] != "success":
raise ValueError(
response.json()["message"]
response.json().get(
"message",
"unknow error posting comment",
)
)
except Exception as e:
log(
f"Failed to post followup comment {comment['text']} for {alert['objectId']} to SkyPortal: {e}"
)
else:
raise ValueError(response.json()["message"])
raise ValueError(
response.json().get(
"message",
"unknow error posting followup request",
)
)
except Exception as e:
log(
f"Failed to post followup request for {alert['objectId']} to SkyPortal: {e}"
Expand Down
Loading