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.io module is the backbone of ztfquery’s data-access layer. It translates ZTF filenames into local paths, authenticates with IRSA (the primary ZTF data archive), downloads missing files on demand, and verifies the integrity of everything on disk. All other ztfquery modules that touch files — queries, lightcurves, alerts — ultimately route through the functions defined here.
Storage Configuration
ztfquery stores all downloaded data under a configurable root directory.LOCALSOURCE defaults to ./Data/ in the current working directory. Set the ZTFDATA environment variable to point to any local path before importing ztfquery:/sps/ztf/data/, which is exposed as the CCIN2P3_SOURCE constant. No download is needed in that environment.Authentication
ZTF science and calibration images hosted on IRSA require an authenticated session. ztfquery stores credentials (base64-encoded) in~/.ztfquery.
set_account
Set or update stored credentials for any ZTF-related service.
The service to configure. Supported values:
"irsa", "fritz", "marshal", "pharos", "skyvision". Use "fritz" for Fritz/SkyPortal (token-based).IRSA username. If
None, you will be prompted interactively.Account password. If
None, a secure getpass prompt is shown.Validate credentials against the live service before saving. Set
False for offline use or when testing without network access.Save credentials even if the validation test fails. Use with caution.
get_cookie
Obtain a session cookie from the IPAC login service.
username and password are None, the stored credentials from ~/.ztfquery are used automatically.
open_irsa_session
Open a requests.Session pre-loaded with IRSA authentication cookies.
test_irsa_account
Verify that stored (or supplied) IRSA credentials are accepted by the server.
Resolving and Downloading Files
get_file
The primary entry point for obtaining a local file path. If the file is not already cached locally, it is downloaded from IRSA automatically.
One or more ZTF filenames (science, raw, or calibration). Accepted forms are ZTF basenames such as
ztf_20190917468333_000698_zi_c03_o_q2_sciimg.fits.Override the product suffix to retrieve an associated file. For example, if
filename is a sciimg.fits, passing suffix="mskimg.fits" returns the corresponding mask image path. For raw files, suffix is used as the imgtypecode.A pre-authenticated session (from
open_irsa_session). If None, a new session is created per call.Whether to download the file if it is not found locally. Set
False to only resolve the local path without triggering a download.If
False, return the local paths without checking whether the files exist or triggering any download.If
True, FITS files that exist locally are tested for corruption; corrupted files are re-downloaded.Download source. Only
"irsa" and "ccin2p3" are currently supported.Re-download and overwrite the file even if it already exists locally.
Maximum number of parallel download processes when
filename is a list.If
True and only a single file is requested, return a plain string instead of a one-element list.Display a progress bar during download.
A Dask distributed client. When provided, downloads are submitted as Dask futures.
Throttle the download rate when using a Dask client.
None auto-computes a wait based on queue length; "None" disables throttling; a float sets an absolute wait time in seconds.Controls what to return for files that do not exist after the download attempt.
"None" (string) leaves the path as-is; "remove" drops missing entries from the returned list; any other string is substituted as a placeholder.download_from_filename
Lower-level function to explicitly download a file by its ZTF filename, bypassing the local-cache check.
bulk_get_file
Download a large list of files using Dask for parallelism. Returns either delayed objects, futures, or computed results depending on as_dask.
List of ZTF filenames to download.
A Dask distributed client for cluster-level parallelism. If
None, local Dask threads are used.Controls the return type:
"delayed"— returns(list_of_delayed, session)."computed"— blocks and returns the list of local file paths."futures"— submits toclientand returns(futures, session)."gathered"— submits toclient, waits, and returns the file paths.
Parsing Filenames
ZTF filenames encode rich metadata — date, field, filter, CCD, quadrant, and product type — in a structured naming convention.parse_filename
Decompose a ZTF filename into its constituent parts.
A ZTF basename or full path. Works for science (
sciimg), raw, calibration, and reference filenames.If
True (default), return a pandas.Series. If False, return a plain dict.filename_to_kind
Determine whether a filename corresponds to a science, raw, calibration, or reference product.
get_filedataframe
Parse a list of ZTF filenames into a combined DataFrame that includes parsed metadata and a column indicating whether each file exists locally.
Raw Data Paths
filefracday_to_local_rawdata
Glob for all local raw FITS files matching a given filefracday identifier and optional CCD ID.
File Integrity Checking
ztfquery can validate every cached file and optionally remove or re-download corrupted entries.run_full_filecheck
Scan all files under LOCALSOURCE (or a custom path) and report corrupted or unreadable files.
Only check files with this extension (e.g.
"fits", "txt"). Leading dots are stripped automatically.Root directory to scan. Defaults to
LOCALSOURCE ($ZTFDATA).Automatically delete corrupted files from disk.
Re-download corrupted files from IRSA after erasing them.
Number of parallel worker processes for checking.
test_files
Test a specific list of files rather than scanning an entire directory.
get_localfiles
List all ztfquery-managed files of a given extension under a directory tree.
calculate_hash
Compute the MD5 hash of a file for integrity verification.
Complete Workflow Examples
from ztfquery import io
scifile = "ztf_20190917468333_000698_zi_c03_o_q2_sciimg.fits"
local_path = io.get_file(scifile)
print("Saved to:", local_path)
meta = io.parse_filename(scifile)
print(meta)
kind = io.filename_to_kind(scifile)
print("Product type:", kind) # "sci"