$npx -y skills add K-Dense-AI/scientific-agent-skills --skill astropyCore Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.
| 1 | # Astropy |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis. Use astropy for coordinate transformations, unit and quantity calculations, FITS file operations, cosmological calculations, precise time handling, tabular data manipulation, and astronomical image processing. |
| 6 | |
| 7 | ## When to Use This Skill |
| 8 | |
| 9 | Use astropy when tasks involve: |
| 10 | - Converting between celestial coordinate systems (ICRS, Galactic, FK5, AltAz, etc.) |
| 11 | - Working with physical units and quantities (converting Jy to mJy, parsecs to km, etc.) |
| 12 | - Reading, writing, or manipulating FITS files (images or tables) |
| 13 | - Cosmological calculations (luminosity distance, lookback time, Hubble parameter) |
| 14 | - Precise time handling with different time scales (UTC, TAI, TT, TDB) and formats (JD, MJD, ISO) |
| 15 | - Table operations (reading catalogs, cross-matching, filtering, joining) |
| 16 | - WCS transformations between pixel and world coordinates |
| 17 | - Astronomical constants and calculations |
| 18 | |
| 19 | ## Quick Start |
| 20 | |
| 21 | ```python |
| 22 | import astropy.units as u |
| 23 | from astropy.coordinates import SkyCoord |
| 24 | from astropy.time import Time |
| 25 | from astropy.io import fits |
| 26 | from astropy.table import Table |
| 27 | from astropy.cosmology import Planck18 |
| 28 | |
| 29 | # Units and quantities |
| 30 | distance = 100 * u.pc |
| 31 | distance_km = distance.to(u.km) |
| 32 | |
| 33 | # Coordinates |
| 34 | coord = SkyCoord(ra=10.5*u.degree, dec=41.2*u.degree, frame='icrs') |
| 35 | coord_galactic = coord.galactic |
| 36 | |
| 37 | # Time |
| 38 | t = Time('2023-01-15 12:30:00') |
| 39 | jd = t.jd # Julian Date |
| 40 | |
| 41 | # FITS files |
| 42 | data = fits.getdata('image.fits') |
| 43 | header = fits.getheader('image.fits') |
| 44 | |
| 45 | # Tables |
| 46 | table = Table.read('catalog.fits') |
| 47 | |
| 48 | # Cosmology |
| 49 | d_L = Planck18.luminosity_distance(z=1.0) |
| 50 | ``` |
| 51 | |
| 52 | ## Core Capabilities |
| 53 | |
| 54 | ### 1. Units and Quantities (`astropy.units`) |
| 55 | |
| 56 | Handle physical quantities with units, perform unit conversions, and ensure dimensional consistency in calculations. |
| 57 | |
| 58 | **Key operations:** |
| 59 | - Create quantities by multiplying values with units |
| 60 | - Convert between units using `.to()` method |
| 61 | - Perform arithmetic with automatic unit handling |
| 62 | - Use equivalencies for domain-specific conversions (spectral, doppler, parallax) |
| 63 | - Work with logarithmic units (magnitudes, decibels) |
| 64 | |
| 65 | **See:** `references/units.md` for comprehensive documentation, unit systems, equivalencies, performance optimization, and unit arithmetic. |
| 66 | |
| 67 | ### 2. Coordinate Systems (`astropy.coordinates`) |
| 68 | |
| 69 | Represent celestial positions and transform between different coordinate frames. |
| 70 | |
| 71 | **Key operations:** |
| 72 | - Create coordinates with `SkyCoord` in any frame (ICRS, Galactic, FK5, AltAz, etc.) |
| 73 | - Transform between coordinate systems |
| 74 | - Calculate angular separations and position angles |
| 75 | - Match coordinates to catalogs |
| 76 | - Include distance for 3D coordinate operations |
| 77 | - Handle proper motions and radial velocities |
| 78 | - Query named objects from online databases |
| 79 | |
| 80 | **See:** `references/coordinates.md` for detailed coordinate frame descriptions, transformations, observer-dependent frames (AltAz), catalog matching, and performance tips. |
| 81 | |
| 82 | ### 3. Cosmological Calculations (`astropy.cosmology`) |
| 83 | |
| 84 | Perform cosmological calculations using standard cosmological models. |
| 85 | |
| 86 | **Key operations:** |
| 87 | - Use built-in cosmologies (Planck18, WMAP9, etc.) |
| 88 | - Create custom cosmological models |
| 89 | - Calculate distances (luminosity, comoving, angular diameter) |
| 90 | - Compute ages and lookback times |
| 91 | - Determine Hubble parameter at any redshift |
| 92 | - Calculate density parameters and volumes |
| 93 | - Perform inverse calculations (find z for given distance) |
| 94 | |
| 95 | **See:** `references/cosmology.md` for available models, distance calculations, time calculations, density parameters, and neutrino effects. |
| 96 | |
| 97 | ### 4. FITS File Handling (`astropy.io.fits`) |
| 98 | |
| 99 | Read, write, and manipulate FITS (Flexible Image Transport System) files. |
| 100 | |
| 101 | **Key operations:** |
| 102 | - Open FITS files with context managers |
| 103 | - Access HDUs (Header Data Units) by index or name |
| 104 | - Read and modify headers (keywords, comments, history) |
| 105 | - Work with image data (NumPy arrays) |
| 106 | - Handle table data (binary and ASCII tables) |
| 107 | - Create new FITS files (single or multi-extension) |
| 108 | - Use memory mapping for large files |
| 109 | - Access remote FITS files (S3, HTTP) |
| 110 | |
| 111 | **See:** `references/fits.md` for comprehensive file operations, header manipulation, image and table handling, multi-extension files, and performance considerations. |
| 112 | |
| 113 | ### 5. Table Operations (`astropy.table`) |
| 114 | |
| 115 | Work with tabular data with support for units, metadata, and various file formats. |
| 116 | |
| 117 | **K |