pyia: a Python package for working with Gaia data#
Source code on GitHub.
pyia provides a class for working with data from the ESA Gaia mission. Here is a short list of
features provided by this package:
Access to Gaia data columns as Astropy
Quantityobjects with units associated (e.g.,data.parallaxwill have associated unitsastropy.units.milliarcsecond).Reconstruct covariance matrices for Gaia sources given errors and correlation coefficients (
pyia.GaiaData.get_cov()).Generate random samples from the astrometric error distribution for each source (a multivariate Gaussian centered on the catalog values) (
pyia.GaiaData.get_error_samples()).Create Astropy
SkyCoordobjects from data (pyia.GaiaData.skycoord).Execute small remote queries via the Gaia science archive and automatically fetch the results (
pyia.GaiaData.from_query()).Read Gaia DR4 parquet tables from a local copy of the bulk download: look up sources by
source_idquickly, select sources from huge tables without loading them, and get epoch photometry and radial velocities as AstropyTimeSeriesand RVS spectra asspecutilsspectra (see Gaia DR4 parquet data).
Installation#
Install pyia with pip or uv. We recommend
installing the latest version from GitHub directly with:
pip install git+https://github.com/adrn/pyia
or, with uv, add it to your project with:
uv add git+https://github.com/adrn/pyia
To install the latest stable version instead, use pip install pyia, uv add pyia,
or uv pip install pyia (to install into the active environment without a uv
project).
pyia requires Python 3.12 or later. A few features need packages that are not
installed with pyia: astroquery for queries to the Gaia archive
(from_query() and from_source_id()), and
dustmaps for extinction (get_ebv() and the methods that use it).
Install them alongside pyia if you need them, e.g.:
uv add pyia astroquery dustmaps
dustmaps also needs the dust map files, which it downloads separately (see the
dustmaps documentation).
To work on pyia itself, see the contributing guide (uv sync
--all-groups sets up a development environment).
Quickstart#
Load a table of Gaia data, here the small subset of Gaia DR3 that comes with the package, and use its columns as Astropy quantities:
>>> import astropy.units as u
>>> import pyia
>>> g = pyia.GaiaData("tests/data/gdr3_sm.fits")
>>> g
<GaiaData: 1000 rows>
>>> g.parallax[:3]
<Quantity [1.08492386, 0.85435642, 1.04200764] mas>
>>> nearby = g.filter(parallax=(1 * u.mas, None), phot_g_mean_mag=(None, 15 * u.mag))
>>> c = nearby.skycoord # an astropy SkyCoord with distances and proper motions
See Working with GaiaData for more, and Gaia DR4 parquet data for working with Gaia DR4 parquet tables.