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.fields module is the central toolkit for working with ZTF’s fixed sky tessellation. ZTF tiles the observable sky into a predefined grid of fields, each observed by a mosaic camera of 16 CCDs, with every CCD subdivided into 4 quadrants (identified by a readout-channel ID, rcid). The module exposes a global pandas DataFrame (FIELD_DATAFRAME) and a flat array of IDs (FIELDSNAMES) loaded from the bundled ztf_fields.txt catalogue, along with a comprehensive set of functions for querying spatial containment, computing polygon geometry, checking reference image availability, and producing publication-quality sky maps.
Global Data Objects
The module exposes two module-level objects that are available immediately after import:| Object | Type | Description |
|---|---|---|
FIELD_DATAFRAME | pandas.DataFrame | All field properties, indexed by field ID. Columns include RA, Dec, Ebv, GalLong, GalLat, EclLong, EclLat. |
FIELDSNAMES | numpy.ndarray | Flat array of all field IDs (integers). |
Grid Structure
ZTF uses two overlapping grids:- Main grid — field IDs below 880. This is the primary survey footprint.
- Secondary (auxiliary) grid — field IDs above 999.
get_grid_field() to retrieve the IDs belonging to each grid:
Querying Field IDs
get_fieldid
Filter the full field list by sky position, coordinate ranges, or dust extinction.
Restrict to a specific grid. Accepts
"main", "secondary", "all", or None (both grids).Declination range in degrees. Three formats are supported:
None— no restriction.[min, max]— inclusive range; either bound can beNonefor open-ended.[[min1, max1], [min2, max2], ...]— union of multiple ranges.
Right-ascension range in degrees. Same format as
decrange.Galactic longitude range in degrees.
Galactic latitude range in degrees.
Milky Way E(B-V) dust extinction range.
Target-to-Field Mapping
get_fields_containing_target
Return every field (and optionally every CCD) that contains a given sky position.
Right ascension of the target in degrees.
Declination of the target in degrees.
If
True, the returned index entries have the form "fieldid_ccdid" instead of plain field IDs.Expand each field polygon by this many degrees before testing containment. Useful to account for the ~0.3 deg inter-CCD gap.
get_fields_containing_target requires shapely (pip install shapely). Performance is greatly improved with geopandas (pip install geopandas), which enables a vectorised GeoSeries lookup. Without geopandas the function falls back to a pure-Python loop over every field polygon.get_field_ccd_qid
Resolve a sky position to its exact field, CCD, quadrant ID, and rcid.
fieldid (int), with each value being a dict containing ccd, qid, and rcid.
spatialjoin_radec_to_fields
Perform a bulk spatial join between a table of coordinates and a set of field polygons. Requires geopandas.
Sky positions to match. Either a DataFrame with
"ra" and "dec" columns, or an (N, 2) array.Field geometries. Accepts a
{fieldid: vertices_array} dict, a GeoSeries indexed by field ID, or a GeoDataFrame with a "fieldid" column.Join type passed to
geopandas.GeoDataFrame.sjoin.Spatial predicate passed to
sjoin (e.g. "contains", "within").spatialjoin_radec_to_fields has a hard dependency on geopandas. Install it with pip install geopandas before calling this function.Field Geometry
get_field_vertices
Return the boundary vertices of one or more fields as (N, 2) arrays of [RA, Dec] pairs.
get_field_centroid
Return the central RA/Dec (or galactic / ecliptic) coordinate of a field.
get_corners
Low-level function that computes the four-edge boundary for one or more fields given explicit (ra_field, dec_field) reference coordinates and an optional CCD/quadrant layout.
CCD and Quadrant Utilities
ZTF’s focal plane contains 16 CCDs, each split into 4 quadrants. Thercid (readout-channel ID) uniquely identifies a quadrant across the entire focal plane (0–63).
Conversions
Centroids
Reference Image Status
ZTF builds reference (template) images by coadding multiple exposures. Not every field has been processed for every filter band.has_field_reference
Check whether a specific field has reference images in each of the three ZTF bands.
The ZTF field ID to query (e.g.
400).If
True, returns a per-rcid count dictionary instead of simple booleans. Useful for identifying partially processed fields.get_fields_with_band_reference
Retrieve all field IDs that have a reference image in a given filter.
Filter code:
"zg" (g-band), "zr" (r-band), or "zi" (i-band).show_reference_map
Convenience function that calls get_fields_with_band_reference and immediately renders a sky map.
Sky Visualisation
show_fields
The primary function for rendering a sky map of ZTF fields, optionally coloured by a numeric quantity.
Either a flat list of field IDs (all drawn with the same colour) or a
{fieldid: value} dict / pandas.Series to colour fields by a continuous quantity.Colour scale minimum. Pass a string (e.g.
"5") to use a percentile of the data.Colour scale maximum. Same percentile-string syntax as
vmin.Matplotlib colormap name.
Overlay the full ZTF field grid as faint outlines.
Draw the Milky Way plane.
If provided, save the figure to this path (at 150 dpi).
show_field_ccds
Display the 16-CCD layout of a single field.
show_gri_fields
Render a three-panel (g / r / i) sky coverage map. Any of the three panels can be omitted by passing None.
Field IDs (or field→value dict) to show in the g-band (green) panel.
Field IDs (or field→value dict) to show in the r-band (red) panel.
Field IDs (or field→value dict) to show in the i-band (orange) panel.
Layout of the three panels.
"horizontal" places them side by side; "classic" uses a two-over-one arrangement.show_ztf_fieldvalues
Show any column from FIELD_DATAFRAME as a coloured sky map.
Visualisation Classes
For programmatic control over plots and animations, the module exposes three classes.FieldPlotter — base visualisation class
FieldPlotter — base visualisation class
FieldPlotter manages a Hammer-projection axes and a combined histogram-colorbar, and is the engine behind show_fields.FieldAnimation — animated survey sequences
FieldAnimation — animated survey sequences
FieldAnimation extends FieldPlotter for animating sequences of ZTF observations. Pass a list of field IDs observed in order and optional per-frame properties.PalomarPlanning — nightly observability tool
PalomarPlanning — nightly observability tool
PalomarPlanning computes which fields are observable from Palomar on a given night given airmass and twilight constraints.