Note
Go to the end to download the full example code.
Action: Synthetic Photometry#
run_photometry_action() is a thin
wrapper over ~uvex_transients.simulation.event_catalog.EventCatalog.simulate_photometry,
supplying the simulator’s own transient_collection/survey_schedule. It runs real
synthetic photometry, band by band and observation by observation, for every event in a
catalog, and is normally run only after the cuts have already narrowed things down to
the events worth the cost.
import numpy as np
from astropy import units as u
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 get_band_color, plot_band_light_curve, 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)
detected = simulator.filter_by_snr(mag_filtered, uvex, snr_threshold=SNR_THRESHOLD)
print(f"{len(detected)} events detected (before scaling by DOWNSAMPLE).")
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.52s/bin, bin=1/10, type=slsn]
Generating events: 10%|█ | 1/10 [00:07<01:07, 7.52s/bin, bin=2/10, type=slsn]
Generating events: 20%|██ | 2/10 [00:07<01:00, 7.52s/bin, bin=3/10, type=slsn]
Generating events: 30%|███ | 3/10 [00:07<00:52, 7.52s/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.44bin/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.47chunk/s, chunk=1/1, type=slsn]
Filtering by mag limit: 100%|██████████| 1/1 [00:00<00:00, 9.45chunk/s, chunk=1/1, 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.33chunk/s, type=slsn]
Computing epochs: 100%|██████████| 1/1 [00:00<00:00, 1.33chunk/s, type=slsn]
135 events detected (before scaling by DOWNSAMPLE).
Running photometry on a handful of events#
The action itself takes the catalog straight from a cut and a mission; only the events actually present in catalog are simulated.
rng = np.random.default_rng(0)
sample_ids = [int(eid) for eid in rng.choice(detected.event_id, size=min(5, len(detected)), replace=False)]
sample = simulator.filter_by_query(detected, uvex, expr=f"np.isin(event_id, {sample_ids})")
photometry = simulator.run_photometry_action(catalog=sample, mission=uvex)
print(f"{len(photometry)} (event, observation, band) rows for {len(sample)} events.")
print(photometry["event_id", "obs_time", "band", "snr", "ab_mag"][:6])
Simulating photometry: 0%| | 0/5 [00:00<?, ?event/s]
Simulating photometry: 20%|██ | 1/5 [00:00<00:00, 6.16event/s]
Simulating photometry: 40%|████ | 2/5 [00:00<00:00, 6.38event/s]
Simulating photometry: 60%|██████ | 3/5 [00:00<00:00, 6.84event/s]
Simulating photometry: 80%|████████ | 4/5 [00:00<00:00, 7.16event/s]
Simulating photometry: 100%|██████████| 5/5 [00:00<00:00, 7.56event/s]
Simulating photometry: 100%|██████████| 5/5 [00:00<00:00, 7.17event/s]
256 (event, observation, band) rows for 5 events.
event_id obs_time band snr ab_mag
-------- ----------------------- ---- ------------------ ------------------
150 2030-07-31 12:32:48.151 FUV 0.4322284431904492 27.116853889519653
150 2030-07-31 12:32:48.151 NUV 8.327420872186334 23.897512821874443
150 2030-07-31 17:17:40.772 FUV 1.3463269587546864 25.883670641481377
150 2030-07-31 17:17:40.772 NUV 9.37008738011539 23.769928374655926
150 2030-08-02 19:22:01.452 FUV 0.8601164015816213 26.37463915054019
150 2030-08-02 19:22:01.452 NUV 10.511899509366572 23.651186495386348
One event’s light curve#
event_id = int(sample_ids[0])
event = detected.get_events(event_id, {"slsn": slsn}, schedule)
phot = photometry[photometry["event_id"] == event_id]
t_since_explosion = (phot["obs_time"] - event.t_explosion).to(u.day)
t_theory = np.linspace(0, slsn.duration_limit.to_value(u.day), 300) * u.day
fig, ax = resolve_fig_axes(fig_size=(7, 4))
for band in ("FUV", "NUV"):
plot_band_light_curve(
ax,
band,
t_since_explosion,
phot,
t_theory=t_theory,
theory_mag=event.mag(t_theory, uvex, band=band),
snr_threshold=SNR_THRESHOLD,
color=get_band_color(band),
err_scale=5.0,
label=band,
)
ax.invert_yaxis()
ax.set_xlabel("Days since explosion")
ax.set_ylabel("AB magnitude")
ax.set_title(f"Event {event.event_id} (z={event.redshift:.3f})")
ax.legend()
fig.tight_layout()
plt.show()

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