Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions fink_filters/ztf/filter_anomaly_notification/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
import pandas as pd
import numpy as np

from astropy import units as u
from astropy.coordinates import SkyCoord

Expand Down Expand Up @@ -133,15 +132,15 @@ def anomaly_notification_(
... df_proc = df.select(
... 'objectId', 'candidate.ra',
... 'candidate.dec', 'candidate.rb',
... f'anomaly_score{model}', 'timestamp')
... f'anomaly_score{model}', 'timestamp', 'candid')
... df_out = anomaly_notification_(df_proc, send_to_tg=False,
... send_to_slack=False, send_to_anomaly_base=True, model=model)

# Disable communication
>>> df_proc = df.select(
... 'objectId', 'candidate.ra',
... 'candidate.dec', 'candidate.rb',
... 'anomaly_score', 'timestamp')
... 'anomaly_score', 'timestamp', 'candid')
>>> pdf_anomalies = anomaly_notification_(df_proc, threshold=10,
... send_to_tg=True, channel_id='@fink_test',
... send_to_slack=False, channel_name=None)
Expand All @@ -161,7 +160,9 @@ def anomaly_notification_(
cut_count = df_proc.count()
if cut_count == 0:
return pd.DataFrame()

df_proc = df_proc.filter(f"not isnan(anomaly_score{model})")
if df_proc.rdd.isEmpty():
return pd.DataFrame()
# Compute the median for the night
buf_df = df_proc.select(f"anomaly_score{model}")
med = buf_df.approxQuantile(f"anomaly_score{model}", [0.5], 0.05)
Expand Down Expand Up @@ -242,6 +243,7 @@ def anomaly_notification_(
{t5_}""".replace("\n", " \n"),
cutout,
curve,
row.candid,
))

init_msg = f"Median anomaly score overnight: {med}."
Expand Down
15 changes: 9 additions & 6 deletions fink_filters/ztf/filter_anomaly_notification/filter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,19 @@ def load_to_anomaly_base(data, model, timeout=60):
tg_id_data = int(tg_id_data.replace('"', ""))
except ValueError:
tg_id_data = "ND"
for ztf_id, text_data, cutout, curve in data:
for ztf_id, text_data, cutout, curve, candid_id in data:
cutout.seek(0)
curve.seek(0)
files = {"image1": cutout, "image2": curve}
data = {"description": text_data}
params = {"ztf_id": ztf_id}
data_payload = {"description": text_data}
params = {"ztf_id": ztf_id, "candid_id": candid_id}
headers = {"Authorization": f"Bearer {access_token}"}
response = send_post_request_with_retry(
session=session,
url="https://anomaly.fink-broker.org:443/images/upload",
files=files,
params=params,
data=data,
data=data_payload,
headers=headers,
timeout=timeout,
source="upload_to_anomaly_base",
Expand All @@ -467,11 +467,14 @@ def load_to_anomaly_base(data, model, timeout=60):
curve.seek(0)
if tg_id_data == "ND":
continue
callback_anomaly = f"A_{candid_id}_{ztf_id}"
callback_not_anomaly = f"NA_{candid_id}_{ztf_id}"

inline_keyboard = {
"inline_keyboard": [
[
{"text": "Anomaly", "callback_data": f"A_{ztf_id}"},
{"text": "Not anomaly", "callback_data": f"NA_{ztf_id}"},
{"text": "Anomaly", "callback_data": callback_anomaly},
{"text": "Not anomaly", "callback_data": callback_not_anomaly},
]
]
}
Expand Down