or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdconstants.mdconvolution.mdcoordinates.mdcosmology.mdfits-io.mdindex.mdmodeling.mdnddata.mdsamp.mdstatistics.mdtables.mdtime.mdtimeseries.mduncertainty.mdunits-quantities.mdutils.mdvisualization.mdwcs.md
tile.json

tessl/pypi-astropy

Astronomy and astrophysics core library providing comprehensive tools for astronomical computations and data handling

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/astropy@6.1.x

To install, run

npx @tessl/cli install tessl/pypi-astropy@6.1.0

index.mddocs/

Astropy

A comprehensive Python library for astronomy and astrophysics that provides a unified framework for common astronomical computations and data handling. It includes modules for coordinate systems, astronomical units, time handling, FITS file I/O, WCS transformations, statistical functions, cosmological calculations, table operations, modeling and fitting, and visualization tools.

Package Information

  • Package Name: astropy
  • Package Type: pypi
  • Language: Python
  • Installation: pip install astropy
  • Version: 6.1.7
  • Documentation: https://docs.astropy.org

Core Imports

import astropy

Common imports for specific functionality:

# Units and quantities
from astropy import units as u
from astropy.units import Quantity

# Coordinates
from astropy.coordinates import SkyCoord
from astropy import coordinates as coord

# Time
from astropy.time import Time

# Tables
from astropy.table import Table, QTable

# Constants
from astropy import constants as const

# FITS I/O
from astropy.io import fits

# Cosmology
from astropy.cosmology import Planck18, WMAP9

# Configuration and logging
from astropy import config, log

Basic Usage

import astropy.units as u
from astropy.coordinates import SkyCoord
from astropy.time import Time
from astropy.table import Table

# Working with units and quantities
distance = 10 * u.pc
velocity = 50 * u.km / u.s
print(distance.to(u.lightyear))

# Coordinate transformations
c = SkyCoord(ra=10.625*u.degree, dec=41.2*u.degree, frame='icrs')
c_galactic = c.galactic
print(f"Galactic coordinates: l={c_galactic.l}, b={c_galactic.b}")

# Time handling
t = Time('2023-01-01T00:00:00', format='isot', scale='utc')
print(f"Julian Date: {t.jd}")

# Table operations
data = Table({'name': ['star1', 'star2'], 'magnitude': [12.5, 13.2]})
data['distance'] = [100, 150] * u.pc
print(data)

Architecture

Astropy is built around several key design principles:

  • Units and Quantities: Physical units are integrated throughout all functionality using the astropy.units system
  • Coordinate Systems: Comprehensive support for celestial coordinate transformations via astropy.coordinates
  • High-Precision Time: Astronomical time scales and formats through astropy.time
  • Standards Compliance: Native support for FITS, VOTable, and other astronomical standards
  • Extensibility: Framework design allows affiliated packages to extend core functionality
  • Performance: Critical computations implemented in Cython/C for speed

The package is designed for maximum interoperability across the scientific Python ecosystem, particularly with NumPy, SciPy, and Matplotlib.

Capabilities

Units and Quantities

Complete physical unit system with quantity objects supporting all astronomical and physical units, unit conversions, and equivalencies for spectroscopic, photometric, and distance measurements.

class Quantity:
    def __init__(self, value, unit=None, dtype=None, copy=True): ...
    def to(self, unit, equivalencies=[]): ...
    
class Unit:
    def __init__(self, s, parse_strict='raise'): ...
    
def def_unit(s, represents=None, doc=None, format=None): ...

Units and Quantities

Coordinate Systems

Comprehensive celestial coordinate system framework with transformations between reference frames, sky coordinate matching, and integration with observational astronomy.

class SkyCoord:
    def __init__(self, *args, frame=None, **kwargs): ...
    def transform_to(self, frame): ...
    def match_to_catalog_sky(self, catalogcoord): ...
    
class ICRS(BaseCoordinateFrame): ...
class Galactic(BaseCoordinateFrame): ...
class AltAz(BaseCoordinateFrame): ...

Coordinate Systems

Time and Time Scales

High-precision time handling with support for multiple time scales (UTC, TAI, TT, etc.), time formats (JD, MJD, ISO), and astronomical time calculations.

class Time:
    def __init__(self, val, val2=None, format=None, scale=None): ...
    @property
    def jd(self): ...
    @property
    def mjd(self): ...
    
class TimeDelta:
    def __init__(self, val, val2=None, format=None, scale=None): ...

Time Handling

Tables and Data Structures

Flexible table data structure with metadata support, advanced I/O capabilities, table operations (join, stack, group), and integration with units and coordinates.

class Table:
    def __init__(self, data=None, masked=None, names=None, meta=None): ...
    def read(cls, *args, **kwargs): ...
    def write(self, *args, **kwargs): ...
    
def join(left, right, keys=None, join_type='inner'): ...
def vstack(tables, join_type='outer'): ...

Tables

FITS File I/O

Complete FITS (Flexible Image Transport System) file support for reading, writing, and manipulating astronomical data files with headers, image data, and binary tables.

def open(name, mode='readonly', **kwargs): ...
def getdata(filename, *args, **kwargs): ...
def getheader(filename, *args, **kwargs): ...
def writeto(filename, data, header=None, **kwargs): ...

class HDUList:
    def __init__(self, hdus=[], file=None): ...
    def writeto(self, fileobj, **kwargs): ...

FITS I/O

Constants

Physical and astronomical constants with proper units and uncertainty handling, including support for different constant systems (CODATA, IAU).

class Constant(Quantity):
    def __init__(self, abbrev, name, value, unit, uncertainty): ...
    @property
    def uncertainty(self): ...

Constants

World Coordinate Systems (WCS)

World Coordinate System transformations between pixel and world coordinates for astronomical images, supporting the full FITS WCS standard.

class WCS:
    def __init__(self, header=None, fobj=None, key=' ', **kwargs): ...
    def pixel_to_world(self, *pixel_arrays): ...
    def world_to_pixel(self, *world_arrays): ...
    def all_pix2world(self, pixcrd, origin): ...

WCS Transformations

Cosmology

Cosmological calculations and standard cosmological models for distance measurements, age calculations, and cosmological parameters.

class FLRW:
    def __init__(self, H0, Om0, Ode0=None, **kwargs): ...
    def age(self, z): ...
    def luminosity_distance(self, z): ...
    def angular_diameter_distance(self, z): ...

class FlatLambdaCDM(FLRW): ...

Cosmology

Statistical Functions

Statistical tools specifically designed for astronomical data analysis, including sigma clipping, robust statistics, and confidence intervals.

def sigma_clip(data, sigma=3, maxiters=5, **kwargs): ...
def mad_std(data, axis=None, func=None, ignore_nan=False): ...
def biweight_location(data, c=6.0, M=None, axis=None): ...

Statistics

Modeling and Fitting

Model fitting framework with astronomical models (Gaussian, Sérsic, etc.) and fitting algorithms for data analysis and parameter estimation.

class Model:
    def __init__(self, *args, **kwargs): ...
    def __call__(self, *args, **kwargs): ...

class Gaussian1D(Fittable1DModel): ...
class Sersic2D(Fittable2DModel): ...

class LinearLSQFitter: ...
class LevMarLSQFitter: ...

Modeling and Fitting

Configuration and Logging

Package configuration system and structured logging for astronomical applications with persistent settings and runtime control.

class ConfigNamespace:
    def __init__(self): ...

class ConfigItem:
    def __init__(self, defaultvalue, description='', cfgtype=None): ...

def get_config(packageormod=None, reload=False): ...

Configuration

Image Convolution

Convolution and filtering operations for astronomical images with kernels optimized for astronomical data analysis.

def convolve(array, kernel, boundary='fill', fill_value=0.0): ...
def convolve_fft(array, kernel, boundary='fill', fill_value=0.0): ...

class Kernel:
    def __init__(self, array): ...

class Gaussian2DKernel(Kernel): ...
class Tophat2DKernel(Kernel): ...

Image Convolution

N-Dimensional Data

Framework for handling N-dimensional astronomical data with metadata, masks, and uncertainty propagation.

class NDData:
    def __init__(self, data, uncertainty=None, mask=None, meta=None): ...

class CCDData(NDData):
    def __init__(self, data, unit=None, **kwargs): ...

class StdDevUncertainty:
    def __init__(self, array, unit=None): ...

N-Dimensional Data

Time Series

Time series data structures and analysis tools for astronomical time-domain observations.

class TimeSeries:
    def __init__(self, time=None, data=None, **kwargs): ...
    def fold(self, period, epoch_time=None): ...

class LombScargle:
    def __init__(self, t, y, dy=None): ...
    def power(self, frequency): ...

Time Series

Uncertainty Propagation

Framework for propagating uncertainties through calculations with support for correlated and uncorrelated errors.

class Distribution:
    def __init__(self, samples): ...
    
def normal(center, std=None, n_samples=None): ...
def uniform(lower=None, upper=None, center=None, width=None): ...

Uncertainty Propagation

Visualization

Tools for creating astronomical plots and visualizations with matplotlib integration and astronomy-specific features.

def quantity_support():
    """Enable matplotlib to work with astropy Quantity objects."""

class ImageNormalize:
    def __init__(self, data=None, interval=None, vmin=None, vmax=None): ...

class LogStretch: ...
class SqrtStretch: ...
class AsinhStretch: ...

Visualization

Utilities

Common utility functions and classes used throughout the astropy ecosystem including data downloading, metadata handling, and helper functions.

def data_dir():
    """Return the data directory for astropy."""

def cache_dir():
    """Return the cache directory for astropy."""

class Progress:
    def __init__(self, total, ipython_widget=False): ...

def deprecated(since, message='', name='', alternative='', pending=False): ...

Utilities

SAMP (Simple Application Messaging Protocol)

SAMP client and hub functionality for interoperability with other astronomical software applications.

class SAMPHubServer:
    def __init__(self, secret=None, addr=None, port=0): ...
    def start(self, wait=False): ...

class SAMPIntegratedClient:
    def __init__(self, name=None, description=None, metadata=None): ...
    def connect(self, hub=None): ...

SAMP Protocol

Types

# Core quantity and unit types
Quantity = Union[float, int, np.ndarray] * Unit
Unit = astropy.units.Unit

# Coordinate types  
SkyCoord = astropy.coordinates.SkyCoord
BaseCoordinateFrame = astropy.coordinates.BaseCoordinateFrame

# Time types
Time = astropy.time.Time
TimeDelta = astropy.time.TimeDelta

# Table types
Table = astropy.table.Table
Column = astropy.table.Column

# FITS types
HDUList = astropy.io.fits.HDUList
Header = astropy.io.fits.Header

# WCS types
WCS = astropy.wcs.WCS

# Configuration types
ConfigNamespace = astropy.config.ConfigNamespace
ConfigItem = astropy.config.ConfigItem

# Convolution types
Kernel = astropy.convolution.Kernel
Gaussian2DKernel = astropy.convolution.Gaussian2DKernel

# NDData types
NDData = astropy.nddata.NDData
CCDData = astropy.nddata.CCDData
StdDevUncertainty = astropy.nddata.StdDevUncertainty

# Time series types
TimeSeries = astropy.timeseries.TimeSeries
LombScargle = astropy.timeseries.LombScargle

# Uncertainty types
Distribution = astropy.uncertainty.Distribution

# Visualization types
ImageNormalize = astropy.visualization.ImageNormalize

# Utility types
Progress = astropy.utils.Progress

# SAMP types
SAMPHubServer = astropy.samp.SAMPHubServer
SAMPIntegratedClient = astropy.samp.SAMPIntegratedClient