Skip to content

Commit

Permalink
Add Telegram bot to Early SN Ia
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienPeloton committed Feb 28, 2024
1 parent 1520bb7 commit 04a664f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
53 changes: 52 additions & 1 deletion fink_filters/filter_early_sn_candidates/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion fink_filters/filter_yso_spicy_candidates/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 04a664f

Please sign in to comment.