
Astropy
Represent and transform celestial coordinates with SkyCoord for astronomy apps, catalogs, and agent-generated analysis scripts.
Install
npx skills add https://github.com/k-dense-ai/scientific-agent-skills --skill astropyWhat is this skill?
- SkyCoord as the recommended high-level interface for ICRS, galactic, and mixed sexagesimal inputs
- Vectorized coordinate arrays with slicing and shape-aware operations
- Component access for ra, dec, hourangle, and hms/dms tuples
- String formatting helpers: decimal, dms, and hmsd-style outputs
- Unit-safe construction using astropy.units on scalar and array coordinates
Adoption & trust: 513 installs on skills.sh; 27.6k GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Journey fit
Canonical shelf is Build because the skill teaches library integration for coordinate objects and frame transforms inside scientific software, not early audience discovery. Integrations fits wiring astropy.coordinates SkyCoord APIs, unit-aware arrays, and frame conversions into Python tooling agents author.
Common Questions / FAQ
Is Astropy safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Astropy
# Astronomical Coordinates (astropy.coordinates) The `astropy.coordinates` package provides tools for representing celestial coordinates and transforming between different coordinate systems. ## Creating Coordinates with SkyCoord The high-level `SkyCoord` class is the recommended interface: ```python from astropy import units as u from astropy.coordinates import SkyCoord # Decimal degrees c = SkyCoord(ra=10.625*u.degree, dec=41.2*u.degree, frame='icrs') # Sexagesimal strings c = SkyCoord(ra='00h42m30s', dec='+41d12m00s', frame='icrs') # Mixed formats c = SkyCoord('00h42.5m +41d12m', unit=(u.hourangle, u.deg)) # Galactic coordinates c = SkyCoord(l=120.5*u.degree, b=-23.4*u.degree, frame='galactic') ``` ## Array Coordinates Process multiple coordinates efficiently using arrays: ```python # Create array of coordinates coords = SkyCoord(ra=[10, 11, 12]*u.degree, dec=[41, -5, 42]*u.degree) # Access individual elements coords[0] coords[1:3] # Array operations coords.shape len(coords) ``` ## Accessing Components ```python c = SkyCoord(ra=10.68*u.degree, dec=41.27*u.degree, frame='icrs') # Access coordinates c.ra # <Longitude 10.68 deg> c.dec # <Latitude 41.27 deg> c.ra.hour # Convert to hours c.ra.hms # Hours, minutes, seconds tuple c.dec.dms # Degrees, arcminutes, arcseconds tuple ``` ## String Formatting ```python c.to_string('decimal') # '10.68 41.27' c.to_string('dms') # '10d40m48s 41d16m12s' c.to_string('hmsdms') # '00h42m43.2s +41d16m12s' # Custom formatting c.ra.to_string(unit=u.hour, sep=':', precision=2) ``` ## Coordinate Transformations Transform between reference frames: ```python c_icrs = SkyCoord(ra=10.68*u.degree, dec=41.27*u.degree, frame='icrs') # Simple transformations (as attributes) c_galactic = c_icrs.galactic c_fk5 = c_icrs.fk5 c_fk4 = c_icrs.fk4 # Explicit transformations c_icrs.transform_to('galactic') c_icrs.transform_to(FK5(equinox='J1975')) # Custom frame parameters ``` ## Common Coordinate Frames ### Celestial Frames - **ICRS**: International Celestial Reference System (default, most common) - **FK5**: Fifth Fundamental Catalogue (equinox J2000.0 by default) - **FK4**: Fourth Fundamental Catalogue (older, requires equinox specification) - **GCRS**: Geocentric Celestial Reference System - **CIRS**: Celestial Intermediate Reference System ### Galactic Frames - **Galactic**: IAU 1958 galactic coordinates - **Supergalactic**: De Vaucouleurs supergalactic coordinates - **Galactocentric**: Galactic center-based 3D coordinates ### Horizontal Frames - **AltAz**: Altitude-azimuth (observer-dependent) - **HADec**: Hour angle-declination ### Ecliptic Frames - **GeocentricMeanEcliptic**: Geocentric mean ecliptic - **BarycentricMeanEcliptic**: Barycentric mean ecliptic - **HeliocentricMeanEcliptic**: Heliocentric mean ecliptic ## Observer-Dependent Transformations For altitude-azimuth coordinates, specify observation time and location: ```python from astropy.time import Time from astropy.coordinates import EarthLocation, AltAz # Define observer location observing_location = EarthLocation(lat=40.8*u.deg, lon=-121.5*u.deg, height=1060*u.m) # Or use named observatory observing_location = EarthLocation.of_site('Apache Point Observatory') # Define observation time observing_time = Time('2023-01-15 23:00:00') # Transform to alt-az aa_frame = AltAz(obstime=observing_time, location=observing_location) aa = c_icrs.transform_to(aa_frame) print(f"Altitude: {aa.alt}") print(f"Azimuth: {aa.az}") ``` ## Working with Distances Add distance information for 3D coordinates: ```python # With distance c = SkyCoord(ra=10*u.degree, dec=9*u.degree, distance=770*u.kpc, frame='icrs') # Access 3D Cartesian coordinates c.cartesian.x c.cartesian.y c.cartesian.z # Distance from origin c.distance # 3D separation c1 = SkyCoord(ra=10*u.degree, dec=9*u.degree, distance=10*u.pc) c2 = SkyCoord(ra=11*u.degree, dec=10*u.degree, distance=11.5*u.pc) sep_3d =