Skip to content

nabeelre/BTSbot

Repository files navigation

BTSbot Logo

DOI arXiv arXiv ascl:2403.004

BTSbot is a multi-modal convolutional neural network for automating supernova identification and follow-up in the Zwicky Transient Facility (ZTF) Bright Transient Survey (BTS).

BTSbot contributed to the first supernova to be fully automatically discovered, confirmed, classified, and shared. (AstroNote, press release)

Presented at the ML for Astrophysics workshop at ICML 2023 (Extended abstract)

The training set for the production model is available on Zenodo.

Also see this animated walkthrough of the fully-automated BTS workflow

A multi-modal convolutional neural network

model

Fig. 5 from Rehemtulla et al. 2024

Usage

Start with the usual imports.

import tensorflow as tf
import numpy as np 
import pandas as pd

I've experienced weird behavior when training and running inference on the GPU cores of my M1 Mac, so we'll disable them here.

import sys
if sys.platform == "darwin":
    tf.config.set_visible_devices([], 'GPU')

Load some example data. It contains alerts from two sources: ZTF23abhvlji (SN 2023tyk, a bright SNIa) and ZTF23abdsfms (AT 2023sxt, an average CV).

cand = pd.read_csv("example_data/usage_candidates.csv", index_col=None)
trips = np.load("example_data/usage_triplets.npy", mmap_mode='r')

These are the metadata columns that the multi-modal BTSbot uses - order matters!

metadata_cols = [
    "sgscore1", "distpsnr1", "sgscore2", "distpsnr2", "fwhm", "magpsf",
    "sigmapsf", "chipsf", "ra", "dec", "diffmaglim", "ndethist", "nmtchps",
    "age", "days_since_peak", "days_to_peak", "peakmag_so_far", "new_drb",
    "ncovhist", "nnotdet", "chinr", "sharpnr", "scorr", "sky", "maxmag_so_far"
]

First, unzip BTSbot at production_models/v1.0.1.tar.gz and then proceed with loading it.

BTSbot = tf.keras.models.load_model("production_models/best_model/")

Now run BTSbot on the example alerts!

raw_preds = BTSbot.predict([trips, cand[metadata_cols]], verbose=1)

Rearrange the scores and compare with the scores I get. You should get a number very close to zero - some minor deviation of scores is normal.

raw_preds = np.transpose(raw_preds)[0]
print(np.median(np.abs(cand['expected_scores'] - raw_preds)))

Now BTSbot is up and running! If you have access to Kowalski you can query for new sources to run BTSbot on using download_training_data(); if not, see alert_utils() for functions to process raw triplets and compute metadata features as BTSbot expects them.

Performance

BTSbot finds nearly all SNe of interest from the input data stream (~100% completeness) with little contamination from uninteresting phenomena (93% purity) and does so as quickly as humans typically do.

test_performance.pdf

Fig. 7 from Rehemtulla et al. 2024

Citing BTSbot

If you use or reference BTSbot please cite Rehemtulla et al. 2024 (ADS)