304.1. Transient light curves#
304.1. Transient light curves¶
For the Rubin Science Platform at data.lsst.cloud.
Data Release: Prompt Products
Container Size: Large
LSST Science Pipelines version: r30.0.11
Last verified to run: 2026-11-30
Repository: github.com/lsst/tutorial-notebooks
DOI: 10.11578/rubin/dc.20250909.20
Learning objective: An overview of plotting extragalactic transient light curves.
LSST data products: ppdb.DiaObject, ppdb.DiaSource, ppdb.DiaForcedSource
Packages: lsst.rsp
Credit: Originally developed by the Rubin Community Science team. Please consider acknowledging them if this notebook is used for the preparation of journal articles, software releases, or other notebooks.
Get Support: Everyone is encouraged to ask questions or raise issues in the Support Category of the Rubin Community Forum. Rubin staff will respond to all questions posted there.
1. Introduction¶
This notebook demonstrates how to obtain and plot a difference-image light curve of an extragalactic transient.
Key concepts for PPDB light curves:
- It is recommended to use the difference-image photometry to ensure that any underlying host galaxy light does not contaminate the flux measurement, as can happen if science-image (also called the direct- or visit-image) photometry is used.
- Using the fluxes is important because difference-image fluxes can be negative (cannot be converted to magnitudes).
- Difference-image sources detected with SNR $>$ 5 are stored in the
DiaSourcetable. - The diaSources (detections) are associated into diaObjects (time-domain events) using a 1" radius.
- After a diaObject has at least 2 detections, forced PSF flux measurements are performed on all subsequent difference images, and stored in the
DiaForcedSourcetable. - Using the forced fluxes ensures that a data point exists for every observation that overlapped the transient's coordinates, not just those in which it was detected at $>5\sigma$ in the difference image.
- Forced flux measurements began April 4 2026, and do not exist for diaObjects that were only detected before that date.
Be aware that some template images may contain transient flux ("template contamination"). In some cases, especially for longer-duration transients, the template image might contain some transient flux, and the transient itself can appear negative in a difference-image if it was brighter in the template than in the visit image. This is more likely to occur during Rubin Observatory's Early Science phase, when template images are created incrementally (on-the-fly, as soon as sufficient input images exist) and deployed as quickly as possible.
Related tutorials: The 200-level tutorials on the DiaSource, DiaObject and DiaForcedSource catalogs.
1.1. Import packages¶
Import numpy, a fundamental package for scientific computing with arrays in Python (numpy.org), and matplotlib , a comprehensive library for data visualization (matplotlib.org; see also the matplotlib gallery).
From the lsst package, import modules for accessing the Table Access Protocol (TAP) service and plotting-style utilities from the LSST Science Pipelines (pipelines.lsst.io).
import numpy as np
import matplotlib.pyplot as plt
from lsst.rsp import RSPDiscovery
from lsst.utils.plotting import (get_multiband_plot_colors,
get_multiband_plot_symbols,
set_rubin_plotstyle)
1.2. Define parameters and functions¶
Create an instance of the TAP service.
discovery = RSPDiscovery("prompt")
tap_service = discovery.get_tap_client()
Define filter names, plot markers, and colors for plotting.
set_rubin_plotstyle()
filter_colors = get_multiband_plot_colors()
filter_names = filter_colors.keys()
filter_symbols = get_multiband_plot_symbols()
2. Retrieve the light curve data¶
Light curve data - difference-image fluxes - are retrieved from the DiaSource table, using the diaObjectId column.
The DiaSource table should not be queried by coordinate; all spatial queries for time-domain objects should be done on the DiaObject table.
- Sections 2.1 and 2.2 together demonstrate the two step process to retrieve first the
diaObjectIdfor the extragalactic transient using a spatial query on theDiaObjecttable, then retrieve the light curve data from theDiaSourcetable using a query on thediaObjectIdcolumn. - Section 2.3 demonstrates how to combine these two steps into a single query using table joins.
2.1. Spatial query for the diaObject¶
Spatial queries should be done on DiaObject, not on the source tables which contain measured fluxes at the same location in every image.
Spatial queries on DiaSource (or DiaForcedSource) are inefficient.
Define the coordinates of known transient SN2026aeud. This object was originally chosen for this tutorial by looking for alerts classified as supernova (SN) in late November 2026 by the ALeRCE broker (ALeRCE: 171141218388934752).
ra_targ = 63.469749
dec_targ = -46.685906
Use a 2" search radius, slightly larger than necessary, to check for potential interlopers or duplicates.
search_radius = 2.0/3600.0
Query the DiaObject table and retrieve the diaObjectId, the number of detections (nDiaSources), and the offset distance between all matches and the search coordinates. Note that this is not a nearest-neighbor search and that multiple matches within the search radius may be returned. Retrieve the results as an Astropy table.
query = """SELECT diaObjectId, nDiaSources,
DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', {}, {})) AS distance
FROM ppdb.DiaObject
WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', {}, {}, {})) = 1
""".format(ra_targ, dec_targ, ra_targ, dec_targ, search_radius)
job = tap_service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
print('Job phase is', job.phase)
if job.phase == 'ERROR':
job.raise_if_error()
assert job.phase == 'COMPLETED'
diao_table = job.fetch_result().to_table()
Job phase is COMPLETED
Show the table. The units for distance is degrees.
diao_table
| diaObjectId | nDiaSources | distance |
|---|---|---|
| int64 | int32 | float64 |
| 171141218388934752 | 30 | 1.8195307409647608e-06 |
If there is more than one diaObject returned by the query, consider the nDiaSources and distance. The true match is usually the closer diaObject, and DIA artifacts (spurious detections) are usually only detected once.
2.2. Query for difference-image fluxes¶
Create a query to retrieve the difference-image flux light curve from the DiaSource table using the diaObjectId found by the cross-match query above.
Retrieve the results as an Astropy table, then print the table length (number of measurements).
use_diaObjectId = 171141218388934752
query = """SELECT diaObjectId, psfFlux, psfFluxErr, band, midpointMjdTai
FROM ppdb.DiaSource
WHERE diaObjectId = {}""".format(use_diaObjectId)
job = tap_service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
print('Job phase is', job.phase)
if job.phase == 'ERROR':
job.raise_if_error()
assert job.phase == 'COMPLETED'
dias_table = job.fetch_result().to_table()
print(len(dias_table))
Job phase is COMPLETED 30
Option to view the table.
# dias_table
Delete the first two query results, as they will be repeated as a table join in the next section.
del diao_table, dias_table
2.3. Combine steps with a TAP join¶
Lower the cross-match radius to 1", because it has already been confirmed to be sufficient for this known transient. Combine the two queries above into a single query with a table join. Execute the query job and return the results as an Astropy table, and print the number of rows.
search_radius = 1.0/3600.0
query = """SELECT diao.diaObjectId, dias.psfFlux, dias.psfFluxErr, dias.band,
dias.midpointMjdTai, dias.visit, dias.detector
FROM ppdb.DiaObject AS diao
JOIN ppdb.DiaSource AS dias ON dias.diaObjectId = diao.diaObjectId
WHERE CONTAINS(POINT('ICRS', diao.ra, diao.dec), CIRCLE('ICRS', {}, {}, {})) = 1
""".format(ra_targ, dec_targ, search_radius)
job = tap_service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
print('Job phase is', job.phase)
if job.phase == 'ERROR':
job.raise_if_error()
assert job.phase == 'COMPLETED'
dias_table = job.fetch_result().to_table()
print(len(dias_table))
Job phase is COMPLETED 30
3. Plot the light curve¶
Plot the difference-image fluxes as open symbols with error bars.
fig = plt.figure(figsize=(8, 4))
for filt in filter_names:
fx = np.where(dias_table['band'] == filt)[0]
plt.errorbar(dias_table['midpointMjdTai'][fx], dias_table['psfFlux'][fx],
yerr=dias_table['psfFluxErr'][fx],
fmt=filter_symbols[filt], ms=10, mew=1, mec=filter_colors[filt],
ecolor=filter_colors[filt], alpha=0.8, color='none',
label=filt + f" ({len(fx)})")
plt.xlabel('Modified Julian Date', fontsize=12)
plt.ylabel('Difference-Image Flux (nJy)', fontsize=12)
plt.legend(loc='upper right', ncol=2, fontsize=12, handletextpad=0.1)
plt.show()
Figure 1: PSF difference-image photometry of an extragalactic transient from the
DiaSourcetable. In the legend, the number of detections per filter is in brackets.
3.1. Forced flux measurements¶
Retrieve the forced flux measurements for this extragalactic transient.
query = """SELECT psfFlux, psfFluxErr, band, midpointMjdTai
FROM ppdb.DiaForcedSource
WHERE diaObjectId = {}""".format(use_diaObjectId)
job = tap_service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
print('Job phase is', job.phase)
if job.phase == 'ERROR':
job.raise_if_error()
assert job.phase == 'COMPLETED'
diafs_table = job.fetch_result().to_table()
print(len(diafs_table))
Job phase is COMPLETED 24
Option to display the table.
# diafs_table
Plot the detection (DiaSource) and forced (DiaForcedSource) difference-image flux light curves together.
fig, ax = plt.subplots(2, 1, figsize=(8, 6), sharex=True)
for filt in filter_names:
fx = np.where(dias_table['band'] == filt)[0]
ax[0].errorbar(dias_table['midpointMjdTai'][fx], dias_table['psfFlux'][fx],
yerr=dias_table['psfFluxErr'][fx],
fmt=filter_symbols[filt], ms=10, mew=1, mec=filter_colors[filt],
ecolor=filter_colors[filt], alpha=0.8, color='none',
label=filt + f" ({len(fx)})")
ax[0].set_xlabel('Modified Julian Date', fontsize=12)
ax[0].set_ylabel('Detection Flux (nJy)', fontsize=12)
ax[0].legend(loc='upper right', ncol=2, fontsize=12, handletextpad=0.1)
for f, filt in enumerate(filter_names):
fx = np.where(diafs_table['band'] == filt)[0]
ax[1].errorbar(diafs_table['midpointMjdTai'][fx], diafs_table['psfFlux'][fx],
yerr=diafs_table['psfFluxErr'][fx],
fmt=filter_symbols[filt], ms=10, mew=0, mec='none', alpha=0.5,
ecolor=filter_colors[filt], color=filter_colors[filt],
label=filt + f" ({len(fx)})")
ax[1].set_xlabel('Modified Julian Date', fontsize=12)
ax[1].set_ylabel('Forced Flux (nJy)', fontsize=12)
ax[1].legend(loc='upper right', ncol=2, fontsize=12, handletextpad=0.1)
plt.show()
Figure 2: The top panel is the same as Figure 1: SNR>5 difference-image fluxes from the
DiaSourcetable (i.e., detections). The bottom panel shows the forced difference-image flux measurements that started after the minimum of two detections (in this case, after the first night). As this transient fades below the SNR=5 detection threshold, forced flux measurements will continue.
3.2. Plot with magnitudes¶
At the time this notebook was created, for this particular diaObject, none of the associated fluxes are negative and it was safe to convert to magnitudes. Calculate the magnitudes and their errors using the standard equation for AB magnitudes (the fluxes are in units of nJy). If a pink RuntimeWarning "invalid value encountered in log10" then it means at least one flux value was negative and failed to convert to magnitudes.
dias_table['psfMag'] = -2.5 * np.log10(dias_table['psfFlux']) + 31.4
diafs_table['psfMag'] = -2.5 * np.log10(diafs_table['psfFlux']) + 31.4
dias_table['psfMagErr'] = 2.5 * np.log10((dias_table['psfFlux']
+ dias_table['psfFluxErr'])/(dias_table['psfFlux']))
diafs_table['psfMagErr'] = 2.5 * np.log10((diafs_table['psfFlux']
+ diafs_table['psfFluxErr'])/(diafs_table['psfFlux']))
Make a version of Figure 2 with magnitudes, instead of fluxes.
fig, ax = plt.subplots(2, 1, figsize=(8, 6), sharex=True)
for filt in filter_names:
fx = np.where(dias_table['band'] == filt)[0]
ax[0].errorbar(dias_table['midpointMjdTai'][fx], dias_table['psfMag'][fx],
yerr=dias_table['psfMagErr'][fx],
fmt=filter_symbols[filt], ms=10, mew=1, mec=filter_colors[filt],
ecolor=filter_colors[filt], alpha=0.8, color='none',
label=filt + f" ({len(fx)})")
ax[0].set_xlabel('Modified Julian Date', fontsize=12)
ax[0].set_ylabel('Detection Magnitude (AB)', fontsize=12)
ax[0].legend(loc='lower left', ncol=2)
ax[0].legend(loc='upper right', ncol=2, fontsize=12, handletextpad=0.1)
ax[0].yaxis.set_inverted(True)
for f, filt in enumerate(filter_names):
fx = np.where(diafs_table['band'] == filt)[0]
ax[1].errorbar(diafs_table['midpointMjdTai'][fx], diafs_table['psfMag'][fx],
yerr=diafs_table['psfMagErr'][fx],
fmt=filter_symbols[filt], ms=10, mew=0, mec='none', alpha=0.5,
ecolor=filter_colors[filt], color=filter_colors[filt],
label=filt + f" ({len(fx)})")
ax[1].set_xlabel('Modified Julian Date', fontsize=12)
ax[1].set_ylabel('Forced Magnitude (AB)', fontsize=12)
ax[1].legend(loc='upper right', ncol=2, fontsize=12, handletextpad=0.1)
ax[1].yaxis.set_inverted(True)
plt.show()
Figure 3: The same as Figure 2, but with fluxes converted to magnitudes.
3.3. Why are some forced fluxes missing?¶
In Figures 2 and 3, there are no forced flux measurements on the first night of detection, as expected. Unexpectedly, there are no forced flux for at least two later nights: in the r-band on MJD 61350, and in z-band on 61356 (as of when this notebook was developed).
Print the visit and detector numbers for any diaSource that does not have a forced measurement at the same MJD.
for i in range(len(dias_table)):
if not np.any(diafs_table['midpointMjdTai'] == dias_table['midpointMjdTai'][i]):
print(np.round(dias_table['midpointMjdTai'][i], 2),
dias_table['band'][i], dias_table['visit'][i], dias_table['detector'][i])
61343.14 g 2026102900257 16 61343.14 g 2026102900258 16 61343.14 i 2026102900262 15 61350.22 r 2026110500355 21 61343.14 i 2026102900261 15 61356.23 z 2026111100410 126
In the above list, four of the above are from the first night, and then the last two are the unexpectedly missing forced fluxes.
Check if there were any forced flux measurements from the r-band visit and detector on MJD 61350. If there are zero, it could be some kind of processing error unrelated to this particular supernova.
query = """SELECT COUNT(diaObjectId) AS N_forced_fluxes
FROM ppdb.DiaForcedSource
WHERE visit = 2026110500355 AND detector = 21"""
job = tap_service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
print('Job phase is', job.phase)
if job.phase == 'ERROR':
job.raise_if_error()
assert job.phase == 'COMPLETED'
result = job.fetch_result().to_table()
Job phase is COMPLETED
result
| N_forced_fluxes |
|---|
| int64 |
| 0 |
The above table shows that there are no forced sources for that visit and detector. A similar query would show that there were also no forced sources for visit and detector 2026111100410 126 (z-band on MJD=61356.23).