Note
Go to the end to download the full example code.
Cut: Time to First Detection#
filter_by_time_to_first_detection()
cuts on the time (days) from explosion to each event’s first SNR-qualifying detection.
It is schedule-aware, like
filter_by_snr(), and is useful for
selecting events caught early, e.g. while a rise is still being resolved.
from matplotlib import pyplot as plt
from uvex_transients.missions import uvex_fast as uvex
from uvex_transients.simulation.core import SurveySimulator
from uvex_transients.surveys import get_schedule
from uvex_transients.transients.supernovae import MagnetarSLSNe
from uvex_transients.utils.plotting import resolve_fig_axes, set_plot_style
set_plot_style()
schedule = get_schedule()
slsn = MagnetarSLSNe()
simulator = SurveySimulator(schedule, transients={"slsn": slsn}, simulation_seed=42)
TIME_BINS = 10
NSIDE = 32
DOWNSAMPLE = 50
MAG_LIMIT = 25.0
SNR_THRESHOLD = 5.0
catalog = simulator.generate_events(time_bins=TIME_BINS, nside=NSIDE, sampling_factor=1 / DOWNSAMPLE)
mag_filtered = simulator.filter_by_limiting_magnitude(catalog, uvex, mag_limit=MAG_LIMIT)
print(f"{len(mag_filtered) * DOWNSAMPLE} events available before the delay cut.")
Generating events: 0%| | 0/10 [00:00<?, ?bin/s]
Generating events: 0%| | 0/10 [00:00<?, ?bin/s, bin=1/10, type=slsn]
Building HEALPix coverage index for (nside=32, order='nested'); this can be slow for a long schedule.
Generating events: 0%| | 0/10 [00:00<?, ?bin/s, bin=1/10, type=slsn]
Generating events: 10%|█ | 1/10 [00:07<01:07, 7.50s/bin, bin=1/10, type=slsn]
Generating events: 10%|█ | 1/10 [00:07<01:07, 7.50s/bin, bin=2/10, type=slsn]
Generating events: 20%|██ | 2/10 [00:07<00:59, 7.50s/bin, bin=3/10, type=slsn]
Generating events: 30%|███ | 3/10 [00:07<00:52, 7.50s/bin, bin=4/10, type=slsn]
Generating events: 40%|████ | 4/10 [00:07<00:08, 1.45s/bin, bin=4/10, type=slsn]
Generating events: 40%|████ | 4/10 [00:07<00:08, 1.45s/bin, bin=5/10, type=slsn]
Generating events: 50%|█████ | 5/10 [00:07<00:07, 1.45s/bin, bin=6/10, type=slsn]
Generating events: 60%|██████ | 6/10 [00:07<00:05, 1.45s/bin, bin=7/10, type=slsn]
Generating events: 70%|███████ | 7/10 [00:07<00:02, 1.44bin/s, bin=7/10, type=slsn]
Generating events: 70%|███████ | 7/10 [00:07<00:02, 1.44bin/s, bin=8/10, type=slsn]
Generating events: 80%|████████ | 8/10 [00:07<00:01, 1.44bin/s, bin=9/10, type=slsn]
Generating events: 90%|█████████ | 9/10 [00:07<00:00, 1.44bin/s, bin=10/10, type=slsn]
Generating events: 100%|██████████| 10/10 [00:07<00:00, 2.45bin/s, bin=10/10, type=slsn]
Generating events: 100%|██████████| 10/10 [00:07<00:00, 1.27bin/s, bin=10/10, type=slsn]
Filtering by mag limit: 0%| | 0/1 [00:00<?, ?chunk/s]
Filtering by mag limit: 0%| | 0/1 [00:00<?, ?chunk/s, chunk=1/1, type=slsn]
Filtering by mag limit: 100%|██████████| 1/1 [00:00<00:00, 9.67chunk/s, chunk=1/1, type=slsn]
Filtering by mag limit: 100%|██████████| 1/1 [00:00<00:00, 9.64chunk/s, chunk=1/1, type=slsn]
19700 events available before the delay cut.
Keeping only events caught early#
An event with zero SNR-qualifying detections never survives, regardless of min_delay/max_delay.
early = simulator.filter_by_time_to_first_detection(mag_filtered, uvex, snr_threshold=SNR_THRESHOLD, max_delay=14.0)
late = simulator.filter_by_time_to_first_detection(mag_filtered, uvex, snr_threshold=SNR_THRESHOLD, min_delay=100.0)
print(f"First detected within 14 d: {len(early) * DOWNSAMPLE} events.")
print(f"First detected after 100 d: {len(late) * DOWNSAMPLE} events.")
Computing epochs: 0%| | 0/1 [00:00<?, ?chunk/s]
Computing epochs: 0%| | 0/1 [00:00<?, ?chunk/s, type=slsn]
Computing epochs: 100%|██████████| 1/1 [00:00<00:00, 1.35chunk/s, type=slsn]
Computing epochs: 100%|██████████| 1/1 [00:00<00:00, 1.34chunk/s, type=slsn]
Computing epochs: 0%| | 0/1 [00:00<?, ?chunk/s]
Computing epochs: 0%| | 0/1 [00:00<?, ?chunk/s, type=slsn]
Computing epochs: 100%|██████████| 1/1 [00:00<00:00, 1.51chunk/s, type=slsn]
Computing epochs: 100%|██████████| 1/1 [00:00<00:00, 1.50chunk/s, type=slsn]
First detected within 14 d: 1250 events.
First detected after 100 d: 500 events.
Early vs. late counts#
fig, ax = resolve_fig_axes(fig_size=(5, 4))
ax.bar(
["max_delay=14 d", "min_delay=100 d"],
[len(early) * DOWNSAMPLE, len(late) * DOWNSAMPLE],
color=["#4C72B0", "#C44E52"],
)
ax.set_ylabel("Events surviving")
ax.set_title("Effect of the time-to-first-detection cut")
fig.tight_layout()
plt.show()

Total running time of the script: (0 minutes 10.513 seconds)