Astropy

7.2.0 · active · verified Thu Apr 09

Astropy is a community-developed core Python package for astronomy and astrophysics. It provides a wide range of tools for common astronomical tasks, including units, coordinates, FITS file I/O, and cosmology. The library is actively maintained, with major releases annually, minor releases every six months, and bugfix releases as needed. The current version is 7.2.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates key Astropy functionalities: defining celestial coordinates with `SkyCoord`, performing unit-aware calculations using `Quantity` and `astropy.units`, accessing physical constants via `astropy.constants`, and working with tabular data using `astropy.table`.

import numpy as np
from astropy import units as u
from astropy import constants as const
from astropy.coordinates import SkyCoord
from astropy.table import Table

# Define a SkyCoord object
pos = SkyCoord(ra=10.68458 * u.deg, dec=41.26917 * u.deg, frame='icrs')
print(f"Sky position: {pos}\n")

# Create a Quantity and perform a calculation
mass = 5.972e24 * u.kg # Earth's mass
radius = 6371 * u.km # Earth's radius
density = mass / (4/3 * np.pi * radius**3)
print(f"Calculated density: {density.to(u.g / u.cm**3):.2f}\n")

# Access a physical constant
c = const.c
print(f"Speed of light: {c.to(u.km/u.s):.0f}\n")

# Create a simple table
data = [
    (1, 'NGC 10', 12.5),
    (2, 'M 31', 3.4),
    (3, 'Abell 2744', 16.0)
]
t = Table(rows=data, names=('id', 'name', 'magnitude'))
print("Example Table:")
print(t)

view raw JSON →