103.1. Introduction to PPDB TAP#
103.1. Introduction to TAP¶
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 efficiently for the Prompt Products Database (PPDB).
LSST data products: Prompt DiaObject and DiaSource tables
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 (Table Access Protocol) provides standardized access to catalog data for discovery, search, and retrieval. Full documentation for TAP is provided by the International Virtual Observatory Alliance (IVOA). ADQL (Astronomy Data Query Language) is similar to SQL (Structured Query Langage). The documentation for ADQL includes more information about syntax and keywords. Not all ADQL functionality is supported yet in the preview-era RSP.
The Data Previews (DP1 and DP2) are served by Qserv, a database built for astronomy that splits each catalog into chunks by sky position. On the other hand the PPDB is served by Google BigQuery, a cloud database designed for scanning very large tables. BigQuery stores each column separately and reads every column a query uses, so the amount of data a query reads depends mostly on which columns it uses. Small inefficiencies that go unnoticed on Qserv, such as SELECT *, missing filters, or looping over objects one query at a time, can make PPDB queries much slower and more expensive, and very large queries may exceed your quotas. Writing efficient queries therefore matters more for the PPDB than for the Data Previews.
This tutorial demonstrates how to get started with the TAP service and make simple queries for the PPDB. More general advice on writing efficient TAP queries can be found in the 100-level tutorials for DP2.
Best practices for TAP queries on the PPDB:
- Use asynchronous queries (as in Section 2).
- Use spatial constraints on
Dia*tables. Spatial constraints are the main way to reduce cost (as in Section 2.1). - Specify only the columns you need (as in Section 2.1).
- Lookups by
diaObjectIdare optimized (as in Section 2.2). - Use time constraint, when applicable, together with a spatial or ID constraint. A time constraint on its own doesn't reduce cost, but it is useful for the science and shrinks the result (as in Section 2.3).
- When joining
DiaObjectwithDiaSourceand/orDiaForcedSource, add aCONTAINSconstraint on each table (see Tutorial 103.2 in this series). - Batch your ID lookups. Run one large query, rather than looping over objects with many small ones (see Tutorial 103.3 in this series).
1.1. Import packages¶
Import general python packages numpy and matplotlib, and the RSPDiscovery class for accessing the RSP TAP service.
import numpy as np
import matplotlib.pyplot as plt
from lsst.rsp import RSPDiscovery
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()
2. Basic PPDB queries¶
This section shows three basic types of asynchronous PPDB queries: spatial (objects within a cone), identifier-based (records for one or more objects by ID), and temporal (objects first detected within a time window).
2.1. Spatial query¶
Define the central coordinates (RA, Dec) = (150.5°, +3.15°), which lies within the COSMOS Deep Drilling Field, and create an ADQL query that returns all DiaObject entries within 0.005° of that position. Use the CONTAINS(POINT, CIRCLE) syntax for the spatial constraint, with the radius in degrees. The PPDB TAP service converts it into an efficient spatial search, so only the parts of the table covering this area of sky are read. Request only the columns you need, here diaObjectId and the number of DiaSources associated with this DiaObject within the last 12 months (nDiaSources), rather than SELECT *.
ra_cen, dec_cen, radius = 150.5, 3.15, 0.005
query = f"""
SELECT diaObjectId, nDiaSources
FROM ppdb.DiaObject
WHERE CONTAINS(POINT('ICRS', ra, dec),
CIRCLE('ICRS', {ra_cen}, {dec_cen}, {radius})) = 1
"""
job = service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
results = job.fetch_result().to_table()
Display the results table.
results
| diaObjectId | nDiaSources |
|---|---|
| int64 | int32 |
| 313972183240015888 | 1 |
| 313972184135499800 | 1 |
| 313976546004041854 | 1 |
| 314003015487979536 | 1 |
| 314003015487979546 | 1 |
| 314003015487979531 | 1 |
| 170046101254570040 | 1 |
| 170050503058653218 | 1 |
| 313963406582874452 | 1 |
| 170028517386879044 | 98 |
job.delete()
del query, results
2.2. Identifier-based query¶
Identifier-based queries retrieve records for specific objects by their unique ID. This is the most direct way to get the light curve of an object you already know, for example from an alert. The alert ID equals the diaSourceId of the detection that triggered the alert, and each DiaSource record also carries the diaObjectId it belongs to.
Retrieve the $g$-band light curve of an RR Lyrae star (diaObjectId = 313985345023639575) identified in Rubin alerts from the DiaSource table that selects all detections with the target's diaObjectId in the $g$ band. This RR Lyrae is in the COSMOS field (Ngeow et al. 2026).
targetId = 313985345023639575
query = f"""
SELECT midpointMjdTai, psfFlux, psfFluxErr
FROM ppdb.DiaSource
WHERE diaObjectId = {targetId}
AND band = 'g'
"""
job = service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
lc = job.fetch_result().to_table()
fig, ax = plt.subplots(figsize=(8, 4))
ax.errorbar(lc['midpointMjdTai'], lc['psfFlux'], yerr=lc['psfFluxErr'],
fmt='o', ms=1, color='tab:red', ecolor='lightgray')
ax.axhline(0, color='gray', lw=0.8, ls='--')
ax.set_xlabel('MJD (TAI)')
ax.set_ylabel('Difference-image PSF flux (nJy)')
ax.set_title(f'diaObjectId = {targetId}')
plt.tight_layout()
plt.show()
Figure 1: $g$-band light curve of the RR Lyrae candidate
diaObjectId= 313985345023639575 in the COSMOS field, from the PPDBDiaSourcetable. Points show the difference-image PSF flux, with 1σ uncertainties, against observation time. The dashed line marks zero flux, the brightness level in the template image. Negative values mean the star was fainter than in the template.
job.delete()
del query, lc
2.3. Temporal query¶
Find objects in a small area of sky that were first recorded by Rubin within a given time window.
Define the center and radius of a cone, (RA, Dec) = (63.5°, −46°) with a radius of 0.5°, and a one-night time window from MJD 61342.5 to 61343.5 (TAI), which is the night of 2026-10-29. Combine a spatial constraint with a constraint on firstDiaSourceMjdTai, the time of each object's first Rubin detection.
To use the current time as the end of the window, get it in MJD (TAI) with astropy:
from astropy.time import Time
end = Time.now().tai.mjd
ra_cen, dec_cen, radius = 63.5, -46, 0.5
end = 61343.5
start = end - 1.0
query = f"""
SELECT diaObjectId, ra, dec
FROM ppdb.DiaObject
WHERE CONTAINS(POINT('ICRS', ra, dec),
CIRCLE('ICRS', {ra_cen}, {dec_cen}, {radius})) = 1
AND firstDiaSourceMjdTai >= {start}
AND firstDiaSourceMjdTai < {end}
"""
job = service.submit_job(query)
job.run()
job.wait(phases=['COMPLETED', 'ERROR'])
results = job.fetch_result().to_table()
fig, ax = plt.subplots(figsize=(5, 3))
hb = ax.hexbin(results['ra'], results['dec'], gridsize=50,
cmap='magma_r', mincnt=1)
fig.colorbar(hb, ax=ax, label='Number of DiaObjects')
ax.set_xlabel('RA (deg)')
ax.set_ylabel('Dec (deg)')
ax.invert_xaxis()
plt.tight_layout()
plt.show()
Figure 2: Sky positions of the
DiaObjectentries returned by the temporal query, i.e., objects within 0.5° of (RA, Dec) = (63.5°, −46°) whose first Rubin detection falls between MJD 61342.5 and 61343.5 (TAI).
job.delete()
del query, results