103.3. User-uploaded tables#
103.3. User uploaded tables¶
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-27
Repository: github.com/lsst/tutorial-notebooks
DOI: 10.11578/rubin/dc.20250909.20
Learning objective: How to use the TAP service to cross-match PPDB tables to a user-uploaded table.
LSST data products: Prompt DiaObject and DiaSource table
Packages: lsst.rsp.RSPDiscovery
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¶
TAP provides standardized access to catalog data for discovery, search, and retrieval. Full documentation for TAP is provided by the International Virtual Observatory Alliance (IVOA).
This tutorial demonstrates the workflow for ingesting user-provided tables into the TAP service to enable queries against the Prompt Products Database (PPDB), either by sky position or by diaObjectId. The PPDB tables are organized by sky position, so the server reads only the parts of a table that overlap a spatial constraint. How efficient a cross-match is therefore depends on where your targets are. A compact group of targets can be enclosed in a single cone, which limits the data read. Targets scattered across the sky cannot. When the IDs are already known, cross-matching on diaObjectId avoids spatial matching altogether. The example user tables contain RR Lyrae candidates verified with Rubin alerts by Ngeow et al. (2026), Table 3.
Related tutorials: The other 103-series tutorials in this series demonstrate how to use the TAP service for the PPDB.
1.1. Import packages¶
Import general python packages numpy, matplotlib, and astropy. Import the RSPDiscovery class from the Rubin lsst package to access the RSP TAP service and plotting functions from lsst.utils to apply Rubin's standard filter colors and symbols.
import numpy as np
import matplotlib.pyplot as plt
from astropy.table import Table
from astropy.coordinates import SkyCoord
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¶
Instantiate RSPDiscovery with the PPDB release, create an instance of the TAP service, and assert that it exists.
discovery = RSPDiscovery("prompt")
service = discovery.get_tap_client()
Define filter names, plot markers, and colors for plotting
set_rubin_plotstyle()
filter_colors = get_multiband_plot_colors()
filter_symbols = get_multiband_plot_symbols()
2. Cross-match with a table of coordinates¶
Load a user-defined table to upload to the TAP service and spatially cross-match to the PPDB table
2.1. Targets scattered across the sky¶
Cross-match a table of RR Lyrae candidates spread across several fields with the DiaObject table. In this case, the targets are spread across the sky, so no single cone encloses them all, and the server may read a large part of the DiaObject table. Keep tables like this short, and match them to DiaObject only. To get light curves, pass the matched diaObjectId values to an identifier-based query (Section 3), rather than double joining DiaSource here.
Read the user table as an astropy table.
path = '/rubin/cst_repos/tutorial-notebooks-data/data/'
ut1 = Table.read(path + 'ppdb_103_user_table1.csv')
Option to display the user table.
# ut1
Define a query that joins the uploaded table to DiaObject, keeping objects within 1″ of each target. Prefix the uploaded columns with ut1_ so they're easy to tell apart from PPDB columns in the results.
query = """
SELECT o.diaObjectId, ut1.ra AS ut1_ra, ut1.dec AS ut1_dec,
o.ra, o.dec, o.nDiaSources
FROM TAP_UPLOAD.ut1 AS ut1
JOIN ppdb.DiaObject AS o
ON CONTAINS(POINT('ICRS', o.ra, o.dec),
CIRCLE('ICRS', ut1.ra, ut1.dec, 0.00028)) = 1
"""
job = service.submit_job(query, uploads={'ut1': ut1})
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
results = job.fetch_result().to_table()
unique_matches = np.unique(results['ut1_ra'])
print(f"Returned {len(results)} matches with {len(unique_matches)} unique entries.")
print("Always check for duplicates!")
Returned 9 matches with 9 unique entries. Always check for duplicates!
job.delete()
del ut1, query, results, unique_matches
2.2. Targets clustered in one field¶
Cross-match a table of RR Lyrae candidates in the M49 field. Then retrieve their light curves from DiaSource in the same query.
Read the user table as an astropy table.
ut2 = Table.read(path + 'ppdb_103_user_table2.csv')
Option to display the user table.
# ut2
Because all targets lie in one field (M49), define an outer cone that encloses them all. Compute its radius from the table, and add a small margin.
center = SkyCoord(186.3, 6.9, unit='deg')
radius = center.separation(SkyCoord(ut2['ra'], ut2['dec'], unit='deg')).max().deg + 0.001
print(f'Outer cone radius: {radius:.4f} deg')
Outer cone radius: 1.8496 deg
Define a query that joins the uploaded table to DiaObject by position, then joins DiaObject to DiaSource on diaObjectId. Add the outer cone on both PPDB tables. Each table is organized by sky position separately, so the cone on DiaObject alone does not limit how much of DiaSource is read. Make the cone on DiaSource about 2″ larger, to keep detections that scatter slightly beyond an object's average position.
query = f"""
SELECT o.diaObjectId, ut2.ra AS ut2_ra, ut2.dec AS ut2_dec,
s.midpointMjdTai, s.band, s.psfFlux, s.psfFluxErr
FROM TAP_UPLOAD.ut2 AS ut2
JOIN ppdb.DiaObject AS o
ON CONTAINS(POINT('ICRS', o.ra, o.dec),
CIRCLE('ICRS', ut2.ra, ut2.dec, 0.00028)) = 1
JOIN ppdb.DiaSource AS s
ON s.diaObjectId = o.diaObjectId
WHERE CONTAINS(POINT('ICRS', o.ra, o.dec),
CIRCLE('ICRS', {center.ra.deg}, {center.dec.deg}, {radius})) = 1
AND CONTAINS(POINT('ICRS', s.ra, s.dec),
CIRCLE('ICRS', {center.ra.deg}, {center.dec.deg}, {radius + 0.0006})) = 1
"""
job = service.submit_job(query, uploads={'ut2': ut2})
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
lcs = job.fetch_result().to_table()
print(len(lcs), 'detections of', len(np.unique(lcs['diaObjectId'])), 'objects')
4084 detections of 10 objects
Display the results table, which has one row per detection. Group it by diaObjectId to get each object's light curve.
lcs.group_by('diaObjectId')
| diaObjectId | ut2_ra | ut2_dec | midpointMjdTai | band | psfFlux | psfFluxErr |
|---|---|---|---|---|---|---|
| d | nJy | nJy | ||||
| int64 | float64 | float64 | float64 | str1 | float32 | float32 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61090.32581730404 | g | 24396.992 | 460.79404 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61090.25865463237 | g | 53950.496 | 516.6128 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61090.33660197413 | r | 47675.598 | 561.3041 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61091.26961376423 | g | -25158.113 | 655.8898 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61094.229264415204 | i | 70524.26 | 622.3087 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61095.20790604932 | g | -40402.457 | 401.70126 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61098.210024117456 | i | 74624.98 | 624.02747 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61091.25159485913 | r | -4806.0293 | 539.32043 |
| 170028526449721369 | 185.42815351408444 | 8.1823168919415 | 61095.189580421094 | r | 2193.1968 | 519.9552 |
| ... | ... | ... | ... | ... | ... | ... |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61096.37702856063 | g | -8696.085 | 297.9272 |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61097.3476180529 | g | -10399.5 | 296.5977 |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61098.23591076338 | r | -10130.185 | 350.12714 |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61098.185070775115 | g | 15022.65 | 414.29297 |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61094.20391338295 | g | -9627.448 | 316.29584 |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61094.20815369804 | g | -10001.312 | 319.4056 |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61096.360414573894 | g | -10750.967 | 294.18042 |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61098.23124559513 | r | -13070.474 | 363.484 |
| 170028527591620680 | 186.93314496731318 | 7.543695002655765 | 61094.216251691396 | r | -1550.8264 | 377.7543 |
job.delete()
del ut2, query, lcs
3. Cross-match with a table of identifiers¶
When the Rubin IDs of your targets are already known, for example from alerts, a broker or a publication, cross-match on diaObjectId or diaSourceId instead of position. Lookups by identifiers are optimized in the PPDB. This works regardless of where the targets are on the sky.
3.1. Retrieve light curves for a table of diaObjectId values¶
Load the table of diaObjectId values. Make sure the IDs are stored as 64-bit integers.
ut3 = Table.read(path + 'ppdb_103_user_table3.csv')
Option to display the user table.
# ut3
Define a query that joins the uploaded table to DiaSource on diaObjectId.
query = """
SELECT ut3.alertOID, s.midpointMjdTai, s.band, s.psfFlux, s.psfFluxErr
FROM TAP_UPLOAD.ut3 AS ut3
JOIN ppdb.DiaSource AS s
ON s.diaObjectId = ut3.alertOID
"""
job = service.submit_job(query, uploads={'ut3': ut3})
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
job.raise_if_error()
lcs = job.fetch_result().to_table()
Check for IDs with no detections returned.
missing = set(ut3['alertOID']) - set(lcs['alertOID'])
print('IDs with no detections:', missing if missing else 'none')
IDs with no detections: none
Plot the light curve of the first object from the uploaded table, showing the difference-image PSF flux and its uncertainty as a function of MJD in each band.
oid = ut3['alertOID'][0]
lc = lcs[lcs['alertOID'] == oid]
fig, ax = plt.subplots(figsize=(8, 4))
for band in filter_colors.keys():
sel = lc['band'] == band
if not np.any(sel):
continue
ax.errorbar(lc['midpointMjdTai'][sel], lc['psfFlux'][sel],
yerr=lc['psfFluxErr'][sel],
fmt=filter_symbols[band], ms=6, mew=1.5,
mec=filter_colors[band], ecolor=filter_colors[band],
color='none', alpha=0.7, label=band)
ax.axhline(0, color='gray', lw=0.8, ls='--')
ax.set_xlabel('MJD (TAI)')
ax.set_ylabel('PSF flux (nJy)')
ax.set_title(f'diaObjectId = {oid}')
ax.legend()
plt.show()
Figure 1: Light curve of one RR Lyrae candidate from Ngeow et al. (2026), retrieved by cross-matching the uploaded table of
diaObjectIdvalues with the PPDBDiaSourcetable. Points show the difference-image PSF flux with 1σ uncertainties against observation time, with Rubin's standard colors and symbols for each band. The dashed line marks zero flux, the brightness level in the template image.
job.delete()
del ut3, query, lcs