astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

Install

Hot:7

Download and extract to your skills directory

Copy command and send to AI Agent for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=k-dense-ai-skills-astropy&locale=en&source=copy

Astropy - Core Python Library for Astronomy and Astrophysics

Skills Overview


Astropy is a core Python library for astronomy and astrophysics, providing comprehensive functionality for coordinate transformations, unit conversions, FITS file operations, cosmological calculations, time handling, table data, and WCS transformations. It is suitable for astronomical research, observational data processing, and astronomical image analysis.

Use Cases

1. Astronomical Observation Data Processing


When you need to process astronomical observation data, Astropy can read and manipulate images and tabular data in FITS format, perform World Coordinate System (WCS) transformations, calculate celestial object positions, and execute precise time conversions between UTC, TAI, TT, TDB, and other time scales. It is suitable for processing telescope observation data, astronomical image analysis, and astronomical catalog operations.

2. Celestial Coordinate Transformations and Unit Calculations


When you need to transform positions between different celestial coordinate systems, such as ICRS, Galactic, FK5, and AltAz, or convert physical units, such as Jy to mJy or parsecs to km, Astropy provides unified coordinate and unit APIs to ensure computational accuracy and consistency. It is suitable for astronomical positioning, catalog cross-matching, and astronomical numerical calculations.

3. Cosmological Parameter Calculations


When you need to calculate cosmological parameters, Astropy provides built-in cosmological models, such as Planck18 and WMAP9, which can quickly calculate luminosity distance, angular-diameter distance, the age of the universe, lookback time, and the Hubble parameter. It is suitable for high-redshift galaxy research, cosmological parameter estimation, and theoretical prediction validation.

Core Features

1. Coordinate Systems and Unit Management


Astropy’s coordinates and units modules provide comprehensive functionality for celestial coordinate transformations and unit conversions. They support transformations between multiple coordinate systems, including ICRS, Galactic, FK5, and AltAz, as well as unit conversions and arithmetic operations on physical quantities. SkyCoord makes it easy to handle celestial positions, including 3D information such as parallax, proper motion, and radial velocity.

2. FITS Files and Tabular Data Processing


Astropy’s io.fits and table modules can read, write, and manipulate FITS files, the standard astronomical data format, as well as tabular data in various formats, including FITS, CSV, HDF5, and VOTable. They support accessing, modifying, and creating image and tabular data, provide memory-mapped processing for large files, and support reading remote FITS files from S3 and HTTP sources.

3. Cosmology and Time Calculations


Astropy’s cosmology and time modules provide cosmological parameter calculations and precise time handling. Standard cosmological models can be used to quickly calculate various distances, the age of the universe, and density parameters. The modules support conversions between multiple time formats, including JD, MJD, and ISO, and time scales, including UTC, TAI, TT, and TDB, as well as calculations of sidereal time and light-travel-time corrections.

Frequently Asked Questions

What is Astropy? What can it be used for?


Astropy is a core library in the Python ecosystem for astronomy and astrophysics, developed and maintained by the astronomical community. It can be used to process various types of astronomical data, including celestial coordinate transformations, physical unit conversions, FITS file reading and writing, cosmological distance calculations, precise time handling, astronomical table data manipulation, and World Coordinate System transformations. Whether for astronomical observation data processing, theoretical calculations, or astronomical image analysis, Astropy provides comprehensive tool support.

How do I install Astropy? What are its dependency requirements?


Astropy requires Python 3.11 or later. Using uv for installation is recommended:
uv pip install "astropy==7.2.0"

If you need plotting and scientific computing functionality, you can install the recommended extensions:
uv pip install "astropy[recommended]==7.2.0"

Astropy depends on libraries such as NumPy, PyERFA, PyYAML, and packaging. Note that certain features, such as celestial object name resolution, site queries, remote FITS reading, and IERS updates, require a network connection.

Which celestial coordinate systems does Astropy support? How do I perform coordinate transformations?


Astropy supports multiple major celestial coordinate systems, including ICRS (International Celestial Reference System), Galactic, FK5 (Fifth Fundamental Catalog coordinate system), and AltAz (horizontal coordinate system). SkyCoord can be used to easily create coordinate objects and transform between coordinate systems:
from astropy.coordinates import SkyCoord
import astropy.units as u

# Create an ICRS coordinate
coord = SkyCoord(ra=10.5*u.degree, dec=41.2*u.degree, frame='icrs')

# Transform to the Galactic coordinate system
coord_galactic = coord.galactic

For observer-dependent coordinate systems, such as AltAz, you also need to provide the observation time and geographic location.