astropy

Perform astronomical calculations, coordinate transformations, and FITS file processing with Python.

Updated Aug 12, 2026
One-click install
npx skills add https://github.com/littlt-momo-c-yfc/skills --skill astropy-littlt-momo-c-yfc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: astropy
Source: https://github.com/littlt-momo-c-yfc/skills/tree/main/skills/scientific-toolkit-skill/references/scientific-skills/astropy
Command: npx skills add https://github.com/littlt-momo-c-yfc/skills --skill astropy-littlt-momo-c-yfc

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires astropy, numpy, and includes references (resource) components.

What problem does it solve? Astronomical data analysis requires handling celestial coordinates, physical units, FITS files, cosmological distances, and precise time scales, which are error-prone to implement manually. This Skill provides guidance for using the Astropy Python library to perform these tasks correctly and consistently. ## Core Features & Use Cases - Coordinate Transformations: Convert positions between ICRS, Galactic, FK5, and observer-dependent AltAz frames, and cross-match catalogs by angular separation. - FITS File Handling: Read, write, and modify FITS images, headers, and binary tables, including memory-mapped access for large files. - Cosmology, Units, and Time: Compute luminosity distances and lookback times with Planck18 or custom cosmologies, convert physical quantities with units, and handle time scales like UTC, TAI, and TDB. - Use Case: Given two source catalogs in FITS format, load them as tables, build SkyCoord objects, match sources within 1 arcsecond, and write the merged catalog back to disk. ## Quick Start Use the astropy skill to convert these RA/Dec coordinates to Galactic coordinates and compute the luminosity distance at redshift 1.5.

Frequently Asked Questions about astropy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert between celestial coordinate systems in Python?

Use astropy.coordinates.SkyCoord to create a coordinate in one frame, then transform it with attributes like .galactic or .fk5, or the transform_to() method. Observer-dependent frames like AltAz also require a Time and EarthLocation.

How do I read and write FITS files with astropy?

Use astropy.io.fits.open() with a context manager to access HDUs, headers, and data as NumPy arrays. Create new files with fits.PrimaryHDU or fits.BinTableHDU and write them with the writeto() method.

How do I calculate luminosity distance from redshift in Python?

Use astropy.cosmology with a built-in model like Planck18 and call luminosity_distance(z). You can also define custom cosmologies with FlatLambdaCDM and compute ages, lookback times, and comoving volumes.

Does astropy support unit conversions like wavelength to frequency?

Yes, astropy.units handles conversions with the .to() method, and domain-specific conversions like wavelength to frequency use equivalencies such as u.spectral(). Quantities carry units through arithmetic automatically.

Why is my astropy coordinate transformation slow for large catalogs?

Transforming coordinates one at a time in a loop is slow. Instead, build a single SkyCoord from arrays of RA and Dec values so transformations are vectorized, and reuse frame objects across calls.

Can astropy handle large FITS files without loading them into memory?

Yes, fits.open uses memory mapping by default so data is loaded on demand. For remote files, use fsspec support and the .section attribute to read cutouts without downloading the entire file.