Skip to main content

Documentation 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.

The ztfquery.fritz module is a Python interface to fritz.science, the ZTF-II data broker built on the SkyPortal platform. It lets you download and work with photometry, spectra, alerts, and source/group information for any target you have access to on Fritz — all directly from Python, with optional local caching under $ZTFDATA/fritz/.
This documentation covers ztfquery ≥ 1.12.0. The API described here reflects the module as of that version. For the very latest features introduced in v1.14+, refer to the tutorial notebooks which supersede parts of this page.

Requirements

1

Create a Fritz account

Register at fritz.science and navigate to your profile page to generate an API token.
2

Install ztfquery ≥ 1.12.0

pip install ztfquery --upgrade
3

Store your Fritz token

The first time you call any Fritz function without an explicit token= argument, ztfquery will prompt you for your token and store it encrypted in ~/.ztfquery. You can also save it ahead of time:
from ztfquery import io
io.set_account("fritz")  # prompts for token, stores in ~/.ztfquery
Alternatively, pass token="YOUR_TOKEN" directly to any download function.

Module Structure

ztfquery.fritz is organised around two patterns:
PatternPurpose
download_{type}(name, ...)Fetch data from Fritz (optionally stores locally)
Class methods (FritzPhotometry.from_name, etc.)Load a previously downloaded local copy or download fresh
Each data type (lightcurve, spectra, alerts, source, sample, groups) has a corresponding Python class (FritzPhotometry, FritzSpectrum, FritzAlerts, FritzSource, FritzSample, FritzGroups) returned when you pass get_object=True.

Download Functions

download_lightcurve

name
str
required
ZTF source name (e.g. "ZTF20acmzoxo").
get_object
bool
default:"False"
If True, returns a FritzPhotometry instance. Otherwise returns a raw pandas.DataFrame.
token
str
default:"None"
Fritz API token. Uses the stored token if not provided.
store
bool
default:"False"
If True, saves the light curve to $ZTFDATA/fritz/lightcurve/. Set to False to skip storing.
format
str
default:"None"
SkyPortal API option — "flux" or "mag". Default uses the API default.
magsys
str
default:"None"
SkyPortal API option — "ab" or "vega". Default uses the API default.
from ztfquery import fritz

lc = fritz.download_lightcurve("ZTF20acmzoxo", get_object=True)
lc.show()

download_spectra

name
str
required
ZTF source name.
get_object
bool
default:"False"
If True, returns a FritzSpectrum (or list of FritzSpectrum if multiple spectra exist).
token
str
default:"None"
Fritz API token.
store
bool
default:"False"
If True, saves spectra under $ZTFDATA/fritz/spectra/{name}/.
verbose
bool
default:"False"
If True, prints the queried URL.
from ztfquery import fritz

spec = fritz.download_spectra("ZTF20acmzoxo", get_object=True, store=True)
spec.show()

download_alerts

name
str
required
ZTF source name.
candid
int or str
default:"None"
Specific alert candidate ID to retrieve. Returns all alerts when None.
allfields
bool
default:"None"
Set True to retrieve all alert fields (not just candidate info).
get_object
bool
default:"False"
If True, returns a FritzAlerts instance.
token
str
default:"None"
Fritz API token.
store
bool
default:"False"
If True, saves alerts to $ZTFDATA/fritz/alerts/.
from ztfquery import fritz

alerts = fritz.download_alerts("ZTF20acmzoxo", allfields=True, get_object=True)

download_source

name
str
required
ZTF source name.
get_object
bool
default:"False"
If True, returns a FritzSource instance.
token
str
default:"None"
Fritz API token.
store
bool
default:"False"
If True, saves the source JSON to $ZTFDATA/fritz/source/.
source = fritz.download_source("ZTF20acmzoxo", get_object=True)
source.get_redshift()
source.get_coordinates()
source.view_on_fritz()  # opens the Fritz page in your browser

download_sample

Downloads all sources belonging to a Fritz group.
groupid
int or str
required
Numeric group ID or "*" / "all" for no group filter.
get_object
bool
default:"False"
Returns a FritzSample when True.
token
str
default:"None"
Fritz API token.
store
bool
default:"False"
If True, saves the sample CSV to $ZTFDATA/fritz/sample/.
sample = fritz.download_sample(groupid=177, get_object=True)

download_groups

get_object
bool
default:"False"
Returns a FritzGroups instance when True.
token
str
default:"None"
Fritz API token.
store
bool
default:"True"
If True (default), saves the groups JSON to $ZTFDATA/fritz/groups/.
groups = fritz.download_groups(get_object=True)
print(groups.accessible)

Fritz Object Classes

FritzPhotometry wraps the photometry DataFrame returned by Fritz and adds filtering, coordinate extraction, and plotting methods.

Accessing the data

from ztfquery import fritz

lc = fritz.download_lightcurve("ZTF20acmzoxo", get_object=True)

print(lc.data.columns)
# Index(['obj_id', 'ra', 'dec', 'filter', 'mjd', 'instrument_id',
#        'instrument_name', 'ra_unc', 'dec_unc', 'origin', 'id', 'groups',
#        'mag', 'magerr', 'magsys', 'limiting_mag'],
#       dtype='object')

Getting coordinates

Retrieve the full set of per-epoch coordinates as a DataFrame:
lc.get_coordinates(full=True)
#            ra         dec
# 0   331.205290  16.856651
# 2   331.205307  16.856643
# ...
Or compute a single best-estimate position using a numpy statistic:
lc.get_coordinates(method="nanmedian")
# array([331.2052937,  16.8566374])

Filtering data

get_data() accepts band, detection flag, and time-range filters:
filtered = lc.get_data(
    filters="ztfi",
    detected=True,
    time_range=["2020-10-22", "2020-11-15"]
)

Plotting

lc.show()

# Plot with inline filtering
lc.show(filtering=dict(
    filters="ztfi",
    detected=True,
    time_range=["2020-10-22", "2020-11-15"]
))

Storing locally

lc.store("my_lightcurve.csv")   # CSV
lc.store("my_lightcurve.hdf5")  # HDF5
lc.store("my_lightcurve.json")  # JSON
The default store() call (no argument) saves to $ZTFDATA/fritz/lightcurve/fritz_lightcurve_{name}.csv.

Smart loading with from_name

FritzPhotometry.from_name() first checks for a local copy; if found it loads from disk, otherwise it downloads from Fritz:
# First call: downloads from Fritz and caches
lc = fritz.FritzPhotometry.from_name("ZTF20acmzoxo", force_dl=True)
lc.store()

# Subsequent calls: loads from disk instantly
lc = fritz.FritzPhotometry.from_name("ZTF20acmzoxo")

Other Fritz Classes

The following classes are used internally and returned by download functions with get_object=True. Each exposes a .store() method and format-specific I/O classmethods.
ClassCreated byKey attributes
FritzAlertsdownload_alerts(..., get_object=True).data (DataFrame indexed by candid)
FritzSourcedownload_source(..., get_object=True).fritzdict, .ra, .dec, .redshift, .classification, get_metaquery(), view_on_fritz()
FritzSampledownload_sample(..., get_object=True).data, .names, .sources, get_source(name), get_target_metaquery(name)
FritzGroupsdownload_groups(..., get_object=True).accessible (DataFrame of user-accessible groups)

Low-Level API Function

The api() function underlies all download functions and can be used directly for any Fritz/SkyPortal endpoint:
fritz.api(method, endpoint, data=None, load=True, token=None)
ParameterDescription
methodHTTP method string: "get", "post", "put", "delete"
endpointFull URL of the SkyPortal API endpoint
dataRequest body (dict), passed as JSON
loadIf True (default), parse and return the JSON response data
tokenFritz API token; uses stored token if None
# Example: fetch raw photometry for a source
data = fritz.api("get", "https://fritz.science/api/sources/ZTF20acmzoxo/photometry")

Bulk Downloads

For downloading data for many targets in parallel, use fritz.bulk_download():
names = ["ZTF20acmzoxo", "ZTF20acrzwvx", "ZTF20abtmbaz"]

lightcurves = fritz.bulk_download(
    "lightcurve",
    names,
    nprocess=4,       # parallel workers
    store=True,       # cache to $ZTFDATA/fritz/
    as_dict=True      # {name: FritzPhotometry}
)
Supported fobject values: "lightcurve", "photometry", "spectra", "spectrum", "alerts", "source".

Local Storage Layout

All Fritz data stored via store=True or .store() land under $ZTFDATA/fritz/:
$ZTFDATA/fritz/
├── lightcurve/
│   └── fritz_lightcurve_ZTF20acmzoxo.csv
├── spectra/
│   └── ZTF20acmzoxo/
│       └── fritz_spectrum_sedm_<key>_ZTF20acmzoxo.ascii
├── alerts/
│   └── fritz_alerts_ZTF20acmzoxo.csv
├── source/
│   └── fritz_source_ZTF20acmzoxo.json
└── sample/
    └── fritz_sample_<groupid>.csv
Ensure the $ZTFDATA environment variable is set before calling any function with store=True or dirout="default". See the installation guide for details.

Build docs developers (and LLMs) love