# astropy

> Comprehensive Python library for astronomy and astrophysics covering celestial coordinates, physical units, FITS files, cosmological calculations, time systems, and astronomical data analysis.

**Use case**: Astronomical data analysis and coordinate transforms

**Canonical URL**: https://agentcookbooks.com/skills/astropy/

**Topics**: claude-code, skills, science, science

**Trigger phrases**: "FITS file", "celestial coordinates", "cosmological calculation", "astronomical data"

**Source**: [K-Dense AI](https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/scientific-skills/astropy)

**License**: MIT

---

## What it does

`astropy` is a Claude Code skill from K-Dense AI's [scientific-agent-skills repo](https://github.com/K-Dense-AI/scientific-agent-skills). It turns Claude into a working astronomer's assistant — handling coordinate transformations, unit conversions, FITS file I/O, cosmological distance calculations, time scale conversions, and astronomical table operations using the Astropy library.

The output of a session is correct, unit-aware Python code. Astropy's `Quantity` system propagates physical units through calculations, so the skill generates code that avoids unit mismatch bugs common in hand-rolled astrophysics scripts.

## When to use it

Reach for it when:

- You need to read or write FITS files, extract image data, or parse telescope headers
- You are converting between coordinate systems (ICRS, Galactic, AltAz) or computing angular separations and sky crossmatches
- You need cosmological calculations (luminosity distance, comoving volume) or time scale conversions (UTC, TAI, TDB)

When *not* to reach for it:

- You need specialized radio astronomy or interferometry tooling (reach for CASA or related packages)
- Your task is entirely statistical and has no astronomical-specific data types involved

## Install

Copy the SKILL.md from [scientific-skills/astropy](https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/scientific-skills/astropy) into `.claude/skills/astropy/`.

The skill activates on trigger phrases including "FITS file", "celestial coordinates", and "astronomical data".

## What a session looks like

A typical session has three phases:

1. **Data ingestion.** Claude opens a FITS file with `astropy.io.fits`, reads the primary HDU or table extension, and surfaces the header keywords relevant to the task (WCS, exposure time, filter, telescope).
2. **Computation.** Claude constructs `SkyCoord` objects, applies coordinate frame transforms, computes separations or crossmatches, or evaluates a cosmology model (e.g., Planck18) for distance calculations — all with unit tracking via `astropy.units`.
3. **Output.** Claude serializes results to an `astropy.table.Table` (CSV, FITS, or ECSV format) and generates a summary of derived quantities with their units explicitly stated.

## Receipts

Honest reporting on what `astropy` handles well and where it falls short:

**Where it works well:**
- Crossmatching two sky catalogs by angular separation — `SkyCoord.match_to_catalog_sky` is concise and correct
- FITS header parsing for surveys with non-standard keyword conventions — Claude can map keywords to the right WCS parameters
- Cosmological distance calculations where getting units right manually is error-prone

**Where it backfires:**
- Very large FITS images (multi-GB mosaics) require memory-mapped access; the skill generates correct code but doesn't always pre-empt RAM limit warnings
- Complex WCS with SIP distortions may need `reproject` or `astropy-wcs-utils` beyond what the base astropy skill covers

**Pattern that works:** always attach `astropy.units` to raw numeric inputs at the point of entry — catching unit errors there is far cheaper than debugging downstream calculation failures.

## Source and attribution

Originally authored by [K-Dense, Inc.](https://github.com/K-Dense-AI). The canonical SKILL.md lives in the [`astropy` folder](https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/scientific-skills/astropy) of the scientific-agent-skills repository.

License: MIT. Install, adapt, and redistribute with attribution preserved.

This page documents the skill from a practitioner's perspective. For the formal spec and updates, defer to the source repo.