astropy▌
K-Dense-AI/scientific-agent-skills · updated Jun 4, 2026
MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.
### Astropy
- ›name: "astropy"
- ›description: "Core 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 ..."
| name | astropy |
| description | Core 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. |
| license | BSD-3-Clause license |
| metadata | version: "1.1" skill-author: K-Dense Inc. |
Astropy
Overview
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.
When to Use This Skill
Use astropy when tasks involve:
- Converting between celestial coordinate systems (ICRS, Galactic, FK5, AltAz, etc.)
- Working with physical units and quantities (converting Jy to mJy, parsecs to km, etc.)
- Reading, writing, or manipulating FITS files (images or tables)
- Cosmological calculations (luminosity distance, lookback time, Hubble parameter)
- Precise time handling with different time scales (UTC, TAI, TT, TDB) and formats (JD, MJD, ISO)
- Table operations (reading catalogs, cross-matching, filtering, joining)
- WCS transformations between pixel and world coordinates
- Astronomical constants and calculations
Quick Start
import astropy.units as u
from astropy.coordinates import SkyCoord
from astropy.time import Time
from astropy.io import fits
from astropy.table import Table
from astropy.cosmology import Planck18
# Units and quantities
distance = 100 * u.pc
distance_km = distance.to(u.km)
# Coordinates
coord = SkyCoord(ra=10.5*u.degree, dec=41.2*u.degree, frame='icrs')
coord_galactic = coord.galactic
# Time
t = Time('2023-01-15 12:30:00')
jd = t.jd # Julian Date
# FITS files
data = fits.getdata('image.fits')
header = fits.getheader('image.fits')
# Tables
table = Table.read('catalog.fits')
# Cosmology
d_L = Planck18.luminosity_distance(z=1.0)
Core Capabilities
1. Units and Quantities (astropy.units)
Handle physical quantities with units, perform unit conversions, and ensure dimensional consistency in calculations.
Key operations:
- Create quantities by multiplying values with units
- Convert between units using
.to()method - Perform arithmetic with automatic unit handling
- Use equivalencies for domain-specific conversions (spectral, doppler, parallax)
- Work with logarithmic units (magnitudes, decibels)
See: references/units.md for comprehensive documentation, unit systems, equivalencies, performance optimization, and unit arithmetic.
2. Coordinate Systems (astropy.coordinates)
Represent celestial positions and transform between different coordinate frames.
Key operations:
- Create coordinates with
SkyCoordin any frame (ICRS, Galactic, FK5, AltAz, etc.) - Transform between coordinate systems
- Calculate angular separations and position angles
- Match coordinates to catalogs
- Include distance for 3D coordinate operations
- Handle proper motions and radial velocities
- Query named objects from online databases
See: references/coordinates.md for detailed coordinate frame descriptions, transformations, observer-dependent frames (AltAz), catalog matching, and performance tips.
3. Cosmological Calculations (astropy.cosmology)
Perform cosmological calculations using standard cosmological models.
Key operations:
- Use built-in cosmologies (Planck18, WMAP9, etc.)
- Create custom cosmological models
- Calculate distances (luminosity, comoving, angular diameter)
- Compute ages and lookback times
- Determine Hubble parameter at any redshift
- Calculate density parameters and volumes
- Perform inverse calculations (find z for given distance)
See: references/cosmology.md for available models, distance calculations, time calculations, density parameters, and neutrino effects.
4. FITS File Handling (astropy.io.fits)
Read, write, and manipulate FITS (Flexible Image Transport System) files.
Key operations:
- Open FITS files with context managers
- Access HDUs (Header Data Units) by index or name
- Read and modify headers (keywords, comments, history)
- Work with image data (NumPy arrays)
- Handle table data (binary and ASCII tables)
- Create new FITS files (single or multi-extension)
- Use memory mapping for large files
- Access remote FITS files (S3, HTTP)
See: references/fits.md for comprehensive file operations, header manipulation, image and table handling, multi-extension files, and performance considerations.
5. Table Operations (astropy.table)
Work with tabular data with support for units, metadata, and various file formats.
Key operations:
- Create tables from arrays, lists, or dictionaries
- Read/write tables in multiple formats (FITS, CSV, HDF5, VOTable)
- Access and modify columns and rows
- Sort, filter, and index tables
- Perform database-style operations (join, group, aggregate)
- Stack and concatenate tables
- Work with unit-aware columns (QTable)
- Handle missing data with masking
See: references/tables.md for table creation, I/O operations, data manipulation, sorting, filtering, joins, grouping, and performance tips.
6. Time Handling (astropy.time)
Precise time representation and conversion between time scales and formats.
Key operations:
- Create Time objects in various formats (ISO, JD, MJD, Unix, etc.)
- Convert between time scales (UTC, TAI, TT, TDB, etc.)
- Perform time arithmetic with TimeDelta
- Calculate sidereal time for observers
- Compute light travel time corrections (barycentric, heliocentric)
- Work with time arrays efficiently
- Handle masked (missing) times
See: references/time.md for time formats, time scales, conversions, arithmetic, observing features, and precision handling.
7. World Coordinate System (astropy.wcs)
Transform between pixel coordinates in images and world coordinates.
Key operations:
- Read WCS from FITS headers
- Convert pixel coordinates to world coordinates (and vice versa)
- Calculate image footprints
- Access WCS parameters (reference pixel, projection, scale)
- Create custom WCS objects
See: references/wcs_and_other_modules.md for WCS operations and transformations.
Additional Capabilities
The references/wcs_and_other_modules.md file also covers:
NDData and CCDData
Containers for n-dimensional datasets with metadata, uncertainty, masking, and WCS information.
Modeling
Framework for creating and fitting mathematical models to astronomical data.
Visualization
Tools for astronomical image display with appropriate stretching and scaling.
Constants
Physical and astronomical constants with proper units (speed of light, solar mass, Planck constant, etc.).
Convolution
Image processing kernels for smoothing and filtering.
Statistics
Robust statistical functions including sigma clipping and outlier rejection.
Installation
# Reproducible install against the current stable release
uv pip install "astropy==7.2.0"
# Recommended optional dependencies for plotting and common workflows
uv pip install "astropy[recommended]==7.2.0"
# Full optional dependency set for broad astronomy workflows
uv pip install "astropy[all]==7.2.0"
Astropy 7.2.0 requires Python 3.11+ and depends on NumPy, PyERFA, PyYAML, and packaging. Use an isolated virtual environment; do not install Astropy with elevated privileges.
Common Workflows
Converting Coordinates Between Systems
from astropy.coordinates import SkyCoord
import astropy.units as u
# Create coordinate
c = SkyCoord(ra='05h23m34.5s', dec='-69d45m22s', frame='icrs')
# Transform to galactic
c_gal = c.galactic
print(f"l={c_gal.l.deg}, b={c_gal.b.deg}")
# Transform to alt-az (requires time and location)
from astropy.time import Time
from astropy.coordinates import EarthLocation, AltAz
observing_time = Time('2023-06-15 23:00:00')
observing_location = EarthLocation(lat=40*u.deg, lon=-120*u.deg)
aa_frame = AltAz(obstime=observing_time, location=observing_location)
c_altaz = c.transform_to(aa_frame)
print(f"Alt={c_altaz.alt.deg}, Az={c_altaz.az.deg}")
Reading and Analyzing FITS Files
from astropy.io import fits
import numpy as np
# Open FITS file
with fits.open('observation.fits') as hdul:
# Display structure
hdul.info()
# Get image data and header
data = hdul[1].data
header = hdul[1].header
# Access header values
exptime = header['EXPTIME']
filter_name = header['FILTER']
# Analyze data
mean = np.mean(data)
median = np.median(data)
print(f"Mean: {mean}, Median: {median}")
Cosmological Distance Calculations
from astropy.cosmology import Planck18
import astropy.units as u
import numpy as np
# Calculate distances at z=1.5
z = 1.5
d_L = Planck18.luminosity_distance(z)
d_A = Planck18.angular_diameter_distance(z)
print(f"Luminosity distance: {d_L}")
print(f"Angular diameter distance: {d_A}")
# Age of universe at that redshift
age = Planck18.age(z)
print(f"Age at z={z}: {age.to(u.Gyr)}")
# Lookback time
t_lookback = Planck18.lookback_time(z)
print(f"Lookback time: {t_lookback.to(u.Gyr)}")
Cross-Matching Catalogs
from astropy.table import Table
from astropy.coordinates import SkyCoord, match_coordinates_sky
import astropy.units as u
# Read catalogs
cat1 = Table.read('catalog1.fits')
cat2 = Table.read('catalog2.fits')
# Create coordinate objects
coords1 = SkyCoord(ra=cat1['RA']*u.degree, dec=cat1['DEC']*u.degree)
coords2 = SkyCoord(ra=cat2['RA']*u.degree, dec=cat2['DEC']*u.degree)
# Find matches
idx, sep, _ = coords1.match_to_catalog_sky(coords2)
# Filter by separation threshold
max_sep = 1 * u.arcsec
matches = sep < max_sep
# Create matched catalogs
cat1_matched = cat1[matches]
cat2_matched = cat2[idx[matches]]
print(f"Found {len(cat1_matched)} matches")
Best Practices
- Always use units: Attach units to quantities to avoid errors and ensure dimensional consistency
- Use context managers for FITS files: Ensures proper file closing
- Prefer arrays over loops: Process multiple coordinates/times as arrays for better performance
- Check coordinate frames: Verify the frame before transformations
- Use appropriate cosmology: Choose the right cosmological model for your analysis
- Handle missing data: Use masked columns for tables with missing values
- Specify time scales: Be explicit about time scales (UTC, TT, TDB) for precise timing
- Use QTable for unit-aware tables: When table columns have units
- Check WCS validity: Verify WCS before using transformations
- Cache frequently used values: Expensive calculations (e.g., cosmological distances) can be cached
- Be explicit about network access:
SkyCoord.from_name(),EarthLocation.of_site(refresh_cache=True),EarthLocation.of_address(),download_file(), remote FITS reads, and some IERS time/coordinate transforms can contact external services or update local caches. Avoid sending sensitive target names, addresses, URLs, or proprietary file locations to third-party services. - Pin for reproducibility: Use pinned versions such as
astropy==7.2.0for shared environments; update pins intentionally after reviewing release notes.
Current-Version Notes
- Current stable release researched: Astropy 7.2.0 (released 2025-11-25)
- Python requirement: 3.11+
- Recent 7.x changes to watch for: Astropy 7.0 removed older deprecated FITS APIs such as
(Bin)Table.update,_ExtensionHDU,_NonstandardExtHDU, and thetile_sizeargument forCompImageHDU;CompImageHeaderis deprecated. Avoid those legacy patterns in new examples. - The recommended optional extras are
recommendedfor common plotting/scientific dependencies andallonly when a broad optional feature set is needed.
Documentation and Resources
- Official Astropy Documentation: https://docs.astropy.org/en/stable/
- Tutorials: https://learn.astropy.org/
- GitHub: https://github.com/astropy/astropy
Reference Files
For detailed information on specific modules:
references/units.md- Units, quantities, conversions, and equivalenciesreferences/coordinates.md- Coordinate systems, transformations, and catalog matchingreferences/cosmology.md- Cosmological models and calculationsreferences/fits.md- FITS file operations and manipulationreferences/tables.md- Table creation, I/O, and operationsreferences/time.md- Time formats, scales, and calculationsreferences/wcs_and_other_modules.md- WCS, NDData, modeling, visualization, constants, and utilities
How to use astropy on Cursor
AI-first code editor with Composer
Prerequisites
Before installing skills in Cursor, ensure your development environment meets these requirements:
- ›Cursor installed and configured on your development machine
- ›Node.js version 16.0+ with npm package manager (verify with
node --version) - ›Active project directory or workspace where you want to add astropy
Execute installation command
Execute the skills CLI command in your project's root directory to begin installation:
The skills CLI fetches astropy from GitHub repository K-Dense-AI/scientific-agent-skills and configures it for Cursor.
Select Cursor when prompted
The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:
Verify installation
Confirm successful installation by checking the skill directory location:
Reload or restart Cursor to activate astropy. Access the skill through slash commands (e.g., /astropy) or your agent's skill management interface.
Security & Verification Notice
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.
List & Monetize Your Skill
Submit your Claude Code skill and start earning
Use Cases▌
Task Automation & Efficiency
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Knowledge Enhancement
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Quality Improvement
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
Implementation Guide▌
Prerequisites
- ›Claude Desktop or compatible AI client with skill support
- ›Clear understanding of task or problem to solve
- ›Willingness to iterate and refine outputs
Time Estimate
15-45 minutes depending on use case complexity
Installation Steps
- 1.Install skill using provided installation command
- 2.Test with simple use case relevant to your work
- 3.Evaluate output quality and relevance
- 4.Iterate on prompts to improve results
- 5.Integrate into regular workflow if valuable
Common Pitfalls
- ⚠Expecting perfect results without iteration
- ⚠Not providing enough context in prompts
- ⚠Using skill for tasks outside its intended scope
- ⚠Accepting outputs without review and validation
Best Practices▌
✓ Do
- +Start with clear, specific prompts
- +Provide relevant context and constraints
- +Review and refine all outputs before using
- +Iterate to improve output quality
- +Document successful prompt patterns
✗ Don't
- −Don't use without understanding skill limitations
- −Don't skip validation of outputs
- −Don't share sensitive information in prompts
- −Don't expect skill to replace human judgment
💡 Pro Tips
- ★Be specific about desired format and style
- ★Ask for multiple options to choose from
- ★Request explanations to understand reasoning
- ★Combine AI efficiency with human expertise
When to Use This▌
✓ Use When
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid When
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
Learning Path▌
- 1Familiarize yourself with skill capabilities and limitations
- 2Start with low-risk, non-critical tasks
- 3Progress to more complex and valuable use cases
- 4Build expertise through regular use and experimentation
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.6★★★★★60 reviews- ★★★★★Kaira Li· Dec 16, 2024
astropy fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Amelia Lopez· Dec 12, 2024
Keeps context tight: astropy is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Yusuf Brown· Dec 8, 2024
I recommend astropy for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Hana Park· Dec 8, 2024
astropy fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Ganesh Mohane· Dec 4, 2024
Registry listing for astropy matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Fatima Khanna· Nov 27, 2024
Useful defaults in astropy — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Advait Chen· Nov 27, 2024
astropy has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Rahul Santra· Nov 23, 2024
Solid pick for teams standardizing on skills: astropy is focused, and the summary matches what you get after install.
- ★★★★★Aditi Yang· Nov 23, 2024
astropy fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Daniel Thomas· Nov 3, 2024
astropy is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
showing 1-10 of 60