TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/MickaelRigault/ztfquery/llms.txt
Use this file to discover all available pages before exploring further.
ztfquery.query module is a Python wrapper around the IRSA ZTF web API. It lets you search the ZTF archive by sky position, SQL filter, or both, retrieve a metadata table describing every matching image, and then download the actual data products — all in a few lines of Python. The underlying workflow is always two steps: first fetch metadata to identify which files exist, then download the ones you want.
Public ZTF data is available without a private account. See the ZTF Data Release 3 announcement. For partnership or proprietary data, your IRSA account must be associated with ZTF. Create a free account at irsa.ipac.caltech.edu.
ZTFQuery class
ZTFQuery is the main entry point. It combines metadata search (via the IRSA API) with URL construction and file download into a single object.
load_metadata() and download_data() — that represent the two mandatory steps of every data-retrieval workflow.
Two-step workflow
Load metadata
Call
load_metadata() to query the IRSA ZTF archive. This populates the metatable property with a pandas DataFrame describing every matching image. No files are downloaded at this stage.load_metadata() parameters
load_metadata() accepts both spatial constraints and an arbitrary SQL WHERE clause. Either a spatial constraint or a SQL query is required (or both).
The category of ZTF data to search. Accepted values:
| Value | Description |
|---|---|
"sci" | Science exposures and derived products (default) |
"raw" | Raw images as acquired from the camera |
"ref" | Reference (co-added) images |
"cal" | Calibration frames: bias (bias) or high-frequency flat (hifreqflat) |
ICRS sky position
[ra, dec] in decimal degrees. Identifies the center of the spatial search region. Must be combined with size to define a finite search area.Full-width of the search region in decimal degrees, measured along the east axis at
radec. If a single value is given it is used for both axes. A value of zero means a point search. Negative values are not allowed.A SQL
WHERE clause applied server-side to filter results. Supports AND, OR, NOT, IN, BETWEEN, LIKE, and standard comparison operators. Function calls and subqueries are not supported. Required when no spatial constraint is provided.Inline IRSA credentials as
[username, password]. When provided, the stored ~/.ztfquery credentials are ignored.metatable property
After a successful load_metadata() call, results are stored as a pandas DataFrame accessible via zquery.metatable. Each row corresponds to one matching image. Columns include observational parameters such as obsjd, seeing, filtercode, ccdid, field, and qid.
get_metadata() module function
A module-level convenience wrapper that creates a ZTFQuery internally and returns the metatable directly as a DataFrame.
load_metadata().
download_data() parameters
download_data() must be called after load_metadata(). It constructs download URLs from the metatable and fetches each file.
The data product to download. Selects which file type to retrieve for each entry in the metatable. See the accordion below for the full list of science image suffixes.
Display a progress bar during download. When
nprocess > 1, this shows overall batch progress.Number of parallel download processes. When
None or 1, downloads are sequential. Set to a higher integer (e.g. 4) to use multiprocessing for large batches.When
False, files that already exist locally are skipped. Set to True to force re-download of all files.A list of row indexes from
metatable to download. Only those rows will be processed. When omitted, all rows are downloaded.All science image suffixes (kind='sci')
All science image suffixes (kind='sci')
Each science exposure (
kind="sci") has up to eleven associated data products. Pass any of the following strings as the suffix argument to download_data():| Suffix | Description |
|---|---|
sciimg.fits | Primary science image (default) |
mskimg.fits | Bit-mask image |
psfcat.fits | PSF-fit photometry catalog |
sexcat.fits | Nested-aperture photometry catalog |
sciimgdao.psf | Spatially varying PSF estimate in DAOPhot lookup table format |
sciimgdaopsfcent.fits | PSF estimate at the science image center as a FITS image |
sciimlog.txt | Log output from the instrumental calibration pipeline |
scimrefdiffimg.fits.fz | Difference image: science minus reference (fpack-compressed) |
diffimgpsf.fits | PSF estimate for the difference image as a FITS image |
diffimlog.txt | Log output from the image subtraction and extraction pipeline |
log.txt | Overall system summary log from the realtime pipeline |
Code examples
Generic SQL query — no coordinates
Query all observations with seeing better than 2 arcsec between two dates, then visualise the sky coverage of the results.Coordinate query with filter and time constraints
Retrieve i-band observations (filter ID 3) within 0.01 degree of a target since 14 May 2018.Reference image query
Find reference images for a sky position. Usesql_query="fid=1" (or filtercode='zg') to restrict to a single filter.
Basic download
After loading metadata, download PSF-fit photometry catalogs for all matched entries.Parallel download with nprocess
Speed up large downloads by running multiple processes simultaneously.Partial download using indexes
Download only specific rows from the metatable by passing their integer index values.Retrieve paths to local data
After downloading, get the local file paths for the data you have on disk.If you close your Python session, you must call
load_metadata() again before calling get_local_data(). The metatable is needed to reconstruct the IRSA directory structure and locate the files on disk.Download a file directly from its filename
If you have an IRSA filename string, you can download it without going through a metadata query.Additional utilities
show_gri_fields()
Visualise the sky footprint of the queried fields as a sky map. The method signature is show_gri_fields(sizeentry="visits", grid="main", **kwargs). Additional keyword arguments (such as title) are forwarded to the underlying fields.show_gri_fields() function.
sizeentry: what to encode as the field marker size —"visits"(default, observation count) or any column name present inmetatable.grid:"main"(primary ZTF grid, default) or"secondary"to include secondary grid fields.
grid="secondary" to include secondary grid fields alongside the primary grid.
metatable_to_url()
A module-level function that converts any ZTF IRSA metatable DataFrame directly into a list of download URLs, without needing a ZTFQuery instance.