Work with astronomical data using Astropy for FITS file I/O, coordinate transformations, physical units, precise time handling, and catalog operations. Use when processing telescope images, matching celestial catalogs, handling time-series observations, or building photometry/spectroscopy pipelines. Ideal for astronomy research requiring proper unit handling, coordinate frame transformations, and astronomical time scales.
/plugin marketplace add uw-ssec/rse-agents/plugin install python-development@rse-agentsThis skill is limited to using the following tools:
references/COMMON_ISSUES.mdreferences/EXAMPLES.mdreferences/PATTERNS.mdMaster Astropy, the foundational Python library for astronomy and astrophysics. Learn to work with astronomical data formats, coordinate systems, physical units, precise time calculations, and scientific tables - the essential toolkit for modern astronomical computing.
Official Documentation: https://docs.astropy.org/en/stable/
GitHub: https://github.com/astropy/astropy
# Using pixi (recommended for scientific projects)
pixi add astropy photutils specutils
# Using pip
pip install astropy[all]
# Optional affiliated packages
pixi add photutils specutils astroquery reproject
import astropy.units as u
from astropy.io import fits
from astropy.coordinates import SkyCoord
from astropy.time import Time
from astropy.table import Table, QTable
from astropy.wcs import WCS
# Units and Quantities
distance = 10 * u.parsec
wavelength = 5000 * u.angstrom
freq = wavelength.to(u.Hz, equivalencies=u.spectral())
# FITS I/O
with fits.open('image.fits') as hdul:
data = hdul[0].data
header = hdul[0].header
# Coordinates
coord = SkyCoord(ra=10.625*u.degree, dec=41.2*u.degree, frame='icrs')
galactic = coord.galactic
separation = coord.separation(other_coord)
# Time
t = Time('2024-01-01T00:00:00', format='isot', scale='utc')
jd = t.jd
future = t + 1*u.day
# Tables
tbl = Table([ra_col, dec_col, flux_col], names=['ra', 'dec', 'flux'])
filtered = tbl[tbl['flux'] > 100]
# WCS
wcs = WCS(header)
ra, dec = wcs.pixel_to_world(x_pix, y_pix)
Working with astronomical data?
├─ FITS files → astropy.io.fits
├─ Celestial coordinates → astropy.coordinates (SkyCoord)
├─ Physical quantities → astropy.units
├─ Astronomical time → astropy.time
├─ Catalogs/tables → astropy.table
├─ Image coordinates → astropy.wcs
├─ Photometry → photutils
└─ Spectroscopy → specutils
Need coordinate transformation?
├─ Simple conversions → SkyCoord.transform_to()
├─ Sky separations → SkyCoord.separation()
├─ Matching catalogs → match_to_catalog_sky()
└─ Custom frames → Define new frame class
Working with units?
├─ Standard units → multiply by u.unit
├─ Unit conversions → quantity.to()
├─ Wavelength/frequency → Use u.spectral() equivalency
└─ Dimensionless → quantity.decompose()
Need precise time?
├─ Single instant → Time()
├─ Arrays of times → Time(array)
├─ Time scales → specify scale='utc', 'tai', etc.
└─ Time formats → specify format='jd', 'isot', etc.
Use Astropy fundamentals when working with:
Physical quantities with dimensional correctness. Attach units to values and convert automatically.
Key operations:
distance = 10 * u.parsecdistance.to(u.lightyear)wavelength.to(u.Hz, equivalencies=u.spectral())See references/PATTERNS.md for custom units, logarithmic units, and advanced equivalencies.
Standard format for astronomical data. Read/write images and tables with headers.
Key operations:
fits.open('file.fits') with context managerhdul[0].data, hdul[0].headerfits.open('file.fits', memmap=True) for large filesSee references/PATTERNS.md for multi-extension FITS, header inheritance, and large file handling.
Celestial positions with automatic frame transformations.
Key operations:
SkyCoord(ra=10*u.deg, dec=20*u.deg, frame='icrs')coord.galactic, coord.transform_to('fk5')coord1.separation(coord2)coord.match_to_catalog_sky(catalog)See references/PATTERNS.md for custom frames, catalog cross-matching, and observer-dependent coordinates.
Sub-nanosecond precision with multiple time scales and formats.
Key operations:
Time('2024-01-01', scale='utc').jd, .mjd, .iso, .datetime.utc, .tai, .tt, .tdbt + 1*u.daySee references/PATTERNS.md for high-precision calculations, time series, and barycentric corrections.
Flexible tabular data with units and metadata.
Key operations:
Table([col1, col2], names=['a', 'b'])tbl[tbl['mag'] < 15]join(tbl1, tbl2, keys='id').read(), .write() for FITS, CSV, HDF5See references/PATTERNS.md for masked tables, joins, metadata, and indexing.
Maps pixel coordinates to sky coordinates.
Key operations:
WCS(header)wcs.pixel_to_world(x, y) returns SkyCoordwcs.world_to_pixel(coord)wcs.all_pix2world(x, y, 0) for arraysSee references/PATTERNS.md for creating WCS, SIP distortions, and cutouts.
Source detection and aperture photometry.
Key operations:
DAOStarFinder(fwhm=3.0, threshold=5*std)CircularAperture(positions, r=5.0)aperture_photometry(image, apertures)CircularAnnulus for local backgroundSee references/PATTERNS.md for PSF photometry and grouped sources.
1D spectroscopy with wavelength calibration and line analysis.
Key operations:
Spectrum1D(spectral_axis=wavelength, flux=flux)Spectrum1D.read('spec.fits').with_spectral_axis_unit(u.Hz)line_flux(spectrum, region)See references/PATTERNS.md for line fitting, continuum normalization, and redshift measurement.
See references/PATTERNS.md for detailed patterns including:
FITS Manipulation:
Units and Quantities:
Coordinates:
Time:
Tables:
WCS:
Photometry:
Spectroscopy:
See references/EXAMPLES.md for complete workflows:
Telescope Image Processing Pipeline: FITS loading → background subtraction → source detection → aperture photometry → catalog creation with WCS
Catalog Cross-Matching: Multi-catalog matching with coordinate transformations, quality filtering, and color calculations
Light Curve Analysis: Time series handling, period search with Lomb-Scargle, phase folding, and binning
Multi-Wavelength SED Construction: Combining multi-band photometry with proper unit handling and flux conversions
Spectroscopic Redshift Measurement: Emission line identification, template cross-correlation, and redshift refinement
Observability Calculation: Target visibility from specific location, airmass calculation, sun/moon constraints
See references/COMMON_ISSUES.md for troubleshooting:
FITS I/O Issues:
Unit Problems:
Coordinate Issues:
Time Issues:
Table Issues:
WCS Problems:
Performance:
.to() for explicit conversionswith fits.open()) for safe file handlingmemmap=True for files larger than RAMastropyAstropy is the foundational library for astronomical computing in Python, providing essential tools for FITS files, coordinates, units, time, tables, and more.
Key takeaways:
Progressive Learning Path:
For detailed patterns, complete examples, and troubleshooting, see the reference files in the references/ directory.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.