From 04a664fa3a3b31506a1830f3a6488320e7d0de5a Mon Sep 17 00:00:00 2001 From: JulienPeloton Date: Wed, 28 Feb 2024 13:33:58 +0100 Subject: [PATCH] Add Telegram bot to Early SN Ia --- .../filter_early_sn_candidates/filter.py | 53 ++++++++++++++++++- .../filter_yso_spicy_candidates/filter.py | 2 +- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/fink_filters/filter_early_sn_candidates/filter.py b/fink_filters/filter_early_sn_candidates/filter.py index 6663517..1a135f8 100644 --- a/fink_filters/filter_early_sn_candidates/filter.py +++ b/fink_filters/filter_early_sn_candidates/filter.py @@ -16,6 +16,9 @@ from pyspark.sql.types import BooleanType from fink_utils.xmatch.simbad import return_list_of_eg_host +from fink_utils.tg_bot.utils import get_curve +from fink_utils.tg_bot.utils import get_cutout +from fink_utils.tg_bot.utils import msg_handler_tg from fink_filters.tester import spark_unit_tests @@ -83,7 +86,8 @@ def early_sn_candidates_( @pandas_udf(BooleanType(), PandasUDFType.SCALAR) def early_sn_candidates( cdsxmatch, snn_snia_vs_nonia, snn_sn_vs_all, rf_snia_vs_nonia, - ndethist, drb, classtar) -> pd.Series: + ndethist, drb, classtar, objectId, cjdc, cmagpsfc, + csigmapsfc, cdiffmaglimc, cfidc, cstampDatac) -> pd.Series: """ Pandas UDF for early_sn_candidates_ Parameters @@ -122,6 +126,53 @@ def early_sn_candidates( cdsxmatch, snn_snia_vs_nonia, snn_sn_vs_all, rf_snia_vs_nonia, ndethist, drb, classtar ) + + pdf = pd.DataFrame( + { + "objectId": objectId, + "magpsf": cmagpsfc, + "sigmapsf": csigmapsfc, + "diffmaglim": cdiffmaglimc, + "fid": cfidc, + "jd": cjdc, + "snn_snia_vs_nonia": snn_snia_vs_nonia, + "snn_sn_vs_all": snn_sn_vs_all, + "rf_snia_vs_nonia": rf_snia_vs_nonia, + "cstampDatac": cstampDatac + } + ) + + # Loop over matches + if "FINK_TG_TOKEN" in os.environ: + payloads = [] + for _, alert in pdf[series.values].iterrows(): + curve_png = get_curve( + jd=alert["jd"], + magpsf=alert["magpsf"], + sigmapsf=alert["sigmapsf"], + diffmaglim=alert["diffmaglim"], + fid=alert["fid"], + objectId=alert["objectId"], + origin="fields", + ) + + cutout = get_cutout(cutout=alert['cstampDatac']) + + text = """ +*Object ID*: [{}](https://fink-portal.org/{}) +*Scores:*\n- Early SN Ia: {:.2f}\n- Ia SN vs non-Ia SN: {:.2f}\n- SN Ia and Core-Collapse vs non-SN: {:.2f} + """.format( + alert["objectId"], + alert["objectId"], + alert["rf_snia_vs_nonia"], + alert["snn_snia_vs_nonia"], + alert["snn_sn_vs_all"] + ) + + payloads.append((text, curve_png, cutout)) + + if len(payloads) > 0: + msg_handler_tg(payloads, channel_id="@fink_early_ia", init_msg="") return series diff --git a/fink_filters/filter_yso_spicy_candidates/filter.py b/fink_filters/filter_yso_spicy_candidates/filter.py index fbcca19..67d184b 100644 --- a/fink_filters/filter_yso_spicy_candidates/filter.py +++ b/fink_filters/filter_yso_spicy_candidates/filter.py @@ -90,7 +90,7 @@ def yso_spicy_candidates( objectId=alert["objectId"], origin="fields", ) - # pd.DataFrame({'magpsf': alert["magpsf"]})['magpsf'] + hyperlink = "[{}](https://fink-portal.org/{}): ID {} ({})".format( alert["objectId"], alert["objectId"],