0
# Astropy
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: astropy
7
- **Package Type**: pypi
8
- **Language**: Python
9
- **Installation**: `pip install astropy`
10
- **Version**: 6.1.7
11
- **Documentation**: https://docs.astropy.org
12
13
## Core Imports
14
15
```python
16
import astropy
17
```
18
19
Common imports for specific functionality:
20
21
```python
22
# Units and quantities
23
from astropy import units as u
24
from astropy.units import Quantity
25
26
# Coordinates
27
from astropy.coordinates import SkyCoord
28
from astropy import coordinates as coord
29
30
# Time
31
from astropy.time import Time
32
33
# Tables
34
from astropy.table import Table, QTable
35
36
# Constants
37
from astropy import constants as const
38
39
# FITS I/O
40
from astropy.io import fits
41
42
# Cosmology
43
from astropy.cosmology import Planck18, WMAP9
44
45
# Configuration and logging
46
from astropy import config, log
47
```
48
49
## Basic Usage
50
51
```python
52
import astropy.units as u
53
from astropy.coordinates import SkyCoord
54
from astropy.time import Time
55
from astropy.table import Table
56
57
# Working with units and quantities
58
distance = 10 * u.pc
59
velocity = 50 * u.km / u.s
60
print(distance.to(u.lightyear))
61
62
# Coordinate transformations
63
c = SkyCoord(ra=10.625*u.degree, dec=41.2*u.degree, frame='icrs')
64
c_galactic = c.galactic
65
print(f"Galactic coordinates: l={c_galactic.l}, b={c_galactic.b}")
66
67
# Time handling
68
t = Time('2023-01-01T00:00:00', format='isot', scale='utc')
69
print(f"Julian Date: {t.jd}")
70
71
# Table operations
72
data = Table({'name': ['star1', 'star2'], 'magnitude': [12.5, 13.2]})
73
data['distance'] = [100, 150] * u.pc
74
print(data)
75
```
76
77
## Architecture
78
79
Astropy is built around several key design principles:
80
81
- **Units and Quantities**: Physical units are integrated throughout all functionality using the `astropy.units` system
82
- **Coordinate Systems**: Comprehensive support for celestial coordinate transformations via `astropy.coordinates`
83
- **High-Precision Time**: Astronomical time scales and formats through `astropy.time`
84
- **Standards Compliance**: Native support for FITS, VOTable, and other astronomical standards
85
- **Extensibility**: Framework design allows affiliated packages to extend core functionality
86
- **Performance**: Critical computations implemented in Cython/C for speed
87
88
The package is designed for maximum interoperability across the scientific Python ecosystem, particularly with NumPy, SciPy, and Matplotlib.
89
90
## Capabilities
91
92
### Units and Quantities
93
94
Complete physical unit system with quantity objects supporting all astronomical and physical units, unit conversions, and equivalencies for spectroscopic, photometric, and distance measurements.
95
96
```python { .api }
97
class Quantity:
98
def __init__(self, value, unit=None, dtype=None, copy=True): ...
99
def to(self, unit, equivalencies=[]): ...
100
101
class Unit:
102
def __init__(self, s, parse_strict='raise'): ...
103
104
def def_unit(s, represents=None, doc=None, format=None): ...
105
```
106
107
[Units and Quantities](./units-quantities.md)
108
109
### Coordinate Systems
110
111
Comprehensive celestial coordinate system framework with transformations between reference frames, sky coordinate matching, and integration with observational astronomy.
112
113
```python { .api }
114
class SkyCoord:
115
def __init__(self, *args, frame=None, **kwargs): ...
116
def transform_to(self, frame): ...
117
def match_to_catalog_sky(self, catalogcoord): ...
118
119
class ICRS(BaseCoordinateFrame): ...
120
class Galactic(BaseCoordinateFrame): ...
121
class AltAz(BaseCoordinateFrame): ...
122
```
123
124
[Coordinate Systems](./coordinates.md)
125
126
### Time and Time Scales
127
128
High-precision time handling with support for multiple time scales (UTC, TAI, TT, etc.), time formats (JD, MJD, ISO), and astronomical time calculations.
129
130
```python { .api }
131
class Time:
132
def __init__(self, val, val2=None, format=None, scale=None): ...
133
@property
134
def jd(self): ...
135
@property
136
def mjd(self): ...
137
138
class TimeDelta:
139
def __init__(self, val, val2=None, format=None, scale=None): ...
140
```
141
142
[Time Handling](./time.md)
143
144
### Tables and Data Structures
145
146
Flexible table data structure with metadata support, advanced I/O capabilities, table operations (join, stack, group), and integration with units and coordinates.
147
148
```python { .api }
149
class Table:
150
def __init__(self, data=None, masked=None, names=None, meta=None): ...
151
def read(cls, *args, **kwargs): ...
152
def write(self, *args, **kwargs): ...
153
154
def join(left, right, keys=None, join_type='inner'): ...
155
def vstack(tables, join_type='outer'): ...
156
```
157
158
[Tables](./tables.md)
159
160
### FITS File I/O
161
162
Complete FITS (Flexible Image Transport System) file support for reading, writing, and manipulating astronomical data files with headers, image data, and binary tables.
163
164
```python { .api }
165
def open(name, mode='readonly', **kwargs): ...
166
def getdata(filename, *args, **kwargs): ...
167
def getheader(filename, *args, **kwargs): ...
168
def writeto(filename, data, header=None, **kwargs): ...
169
170
class HDUList:
171
def __init__(self, hdus=[], file=None): ...
172
def writeto(self, fileobj, **kwargs): ...
173
```
174
175
[FITS I/O](./fits-io.md)
176
177
### Constants
178
179
Physical and astronomical constants with proper units and uncertainty handling, including support for different constant systems (CODATA, IAU).
180
181
```python { .api }
182
class Constant(Quantity):
183
def __init__(self, abbrev, name, value, unit, uncertainty): ...
184
@property
185
def uncertainty(self): ...
186
```
187
188
[Constants](./constants.md)
189
190
### World Coordinate Systems (WCS)
191
192
World Coordinate System transformations between pixel and world coordinates for astronomical images, supporting the full FITS WCS standard.
193
194
```python { .api }
195
class WCS:
196
def __init__(self, header=None, fobj=None, key=' ', **kwargs): ...
197
def pixel_to_world(self, *pixel_arrays): ...
198
def world_to_pixel(self, *world_arrays): ...
199
def all_pix2world(self, pixcrd, origin): ...
200
```
201
202
[WCS Transformations](./wcs.md)
203
204
### Cosmology
205
206
Cosmological calculations and standard cosmological models for distance measurements, age calculations, and cosmological parameters.
207
208
```python { .api }
209
class FLRW:
210
def __init__(self, H0, Om0, Ode0=None, **kwargs): ...
211
def age(self, z): ...
212
def luminosity_distance(self, z): ...
213
def angular_diameter_distance(self, z): ...
214
215
class FlatLambdaCDM(FLRW): ...
216
```
217
218
[Cosmology](./cosmology.md)
219
220
### Statistical Functions
221
222
Statistical tools specifically designed for astronomical data analysis, including sigma clipping, robust statistics, and confidence intervals.
223
224
```python { .api }
225
def sigma_clip(data, sigma=3, maxiters=5, **kwargs): ...
226
def mad_std(data, axis=None, func=None, ignore_nan=False): ...
227
def biweight_location(data, c=6.0, M=None, axis=None): ...
228
```
229
230
[Statistics](./statistics.md)
231
232
### Modeling and Fitting
233
234
Model fitting framework with astronomical models (Gaussian, Sérsic, etc.) and fitting algorithms for data analysis and parameter estimation.
235
236
```python { .api }
237
class Model:
238
def __init__(self, *args, **kwargs): ...
239
def __call__(self, *args, **kwargs): ...
240
241
class Gaussian1D(Fittable1DModel): ...
242
class Sersic2D(Fittable2DModel): ...
243
244
class LinearLSQFitter: ...
245
class LevMarLSQFitter: ...
246
```
247
248
[Modeling and Fitting](./modeling.md)
249
250
### Configuration and Logging
251
252
Package configuration system and structured logging for astronomical applications with persistent settings and runtime control.
253
254
```python { .api }
255
class ConfigNamespace:
256
def __init__(self): ...
257
258
class ConfigItem:
259
def __init__(self, defaultvalue, description='', cfgtype=None): ...
260
261
def get_config(packageormod=None, reload=False): ...
262
```
263
264
[Configuration](./configuration.md)
265
266
### Image Convolution
267
268
Convolution and filtering operations for astronomical images with kernels optimized for astronomical data analysis.
269
270
```python { .api }
271
def convolve(array, kernel, boundary='fill', fill_value=0.0): ...
272
def convolve_fft(array, kernel, boundary='fill', fill_value=0.0): ...
273
274
class Kernel:
275
def __init__(self, array): ...
276
277
class Gaussian2DKernel(Kernel): ...
278
class Tophat2DKernel(Kernel): ...
279
```
280
281
[Image Convolution](./convolution.md)
282
283
### N-Dimensional Data
284
285
Framework for handling N-dimensional astronomical data with metadata, masks, and uncertainty propagation.
286
287
```python { .api }
288
class NDData:
289
def __init__(self, data, uncertainty=None, mask=None, meta=None): ...
290
291
class CCDData(NDData):
292
def __init__(self, data, unit=None, **kwargs): ...
293
294
class StdDevUncertainty:
295
def __init__(self, array, unit=None): ...
296
```
297
298
[N-Dimensional Data](./nddata.md)
299
300
### Time Series
301
302
Time series data structures and analysis tools for astronomical time-domain observations.
303
304
```python { .api }
305
class TimeSeries:
306
def __init__(self, time=None, data=None, **kwargs): ...
307
def fold(self, period, epoch_time=None): ...
308
309
class LombScargle:
310
def __init__(self, t, y, dy=None): ...
311
def power(self, frequency): ...
312
```
313
314
[Time Series](./timeseries.md)
315
316
### Uncertainty Propagation
317
318
Framework for propagating uncertainties through calculations with support for correlated and uncorrelated errors.
319
320
```python { .api }
321
class Distribution:
322
def __init__(self, samples): ...
323
324
def normal(center, std=None, n_samples=None): ...
325
def uniform(lower=None, upper=None, center=None, width=None): ...
326
```
327
328
[Uncertainty Propagation](./uncertainty.md)
329
330
### Visualization
331
332
Tools for creating astronomical plots and visualizations with matplotlib integration and astronomy-specific features.
333
334
```python { .api }
335
def quantity_support():
336
"""Enable matplotlib to work with astropy Quantity objects."""
337
338
class ImageNormalize:
339
def __init__(self, data=None, interval=None, vmin=None, vmax=None): ...
340
341
class LogStretch: ...
342
class SqrtStretch: ...
343
class AsinhStretch: ...
344
```
345
346
[Visualization](./visualization.md)
347
348
### Utilities
349
350
Common utility functions and classes used throughout the astropy ecosystem including data downloading, metadata handling, and helper functions.
351
352
```python { .api }
353
def data_dir():
354
"""Return the data directory for astropy."""
355
356
def cache_dir():
357
"""Return the cache directory for astropy."""
358
359
class Progress:
360
def __init__(self, total, ipython_widget=False): ...
361
362
def deprecated(since, message='', name='', alternative='', pending=False): ...
363
```
364
365
[Utilities](./utils.md)
366
367
### SAMP (Simple Application Messaging Protocol)
368
369
SAMP client and hub functionality for interoperability with other astronomical software applications.
370
371
```python { .api }
372
class SAMPHubServer:
373
def __init__(self, secret=None, addr=None, port=0): ...
374
def start(self, wait=False): ...
375
376
class SAMPIntegratedClient:
377
def __init__(self, name=None, description=None, metadata=None): ...
378
def connect(self, hub=None): ...
379
```
380
381
[SAMP Protocol](./samp.md)
382
383
## Types
384
385
```python { .api }
386
# Core quantity and unit types
387
Quantity = Union[float, int, np.ndarray] * Unit
388
Unit = astropy.units.Unit
389
390
# Coordinate types
391
SkyCoord = astropy.coordinates.SkyCoord
392
BaseCoordinateFrame = astropy.coordinates.BaseCoordinateFrame
393
394
# Time types
395
Time = astropy.time.Time
396
TimeDelta = astropy.time.TimeDelta
397
398
# Table types
399
Table = astropy.table.Table
400
Column = astropy.table.Column
401
402
# FITS types
403
HDUList = astropy.io.fits.HDUList
404
Header = astropy.io.fits.Header
405
406
# WCS types
407
WCS = astropy.wcs.WCS
408
409
# Configuration types
410
ConfigNamespace = astropy.config.ConfigNamespace
411
ConfigItem = astropy.config.ConfigItem
412
413
# Convolution types
414
Kernel = astropy.convolution.Kernel
415
Gaussian2DKernel = astropy.convolution.Gaussian2DKernel
416
417
# NDData types
418
NDData = astropy.nddata.NDData
419
CCDData = astropy.nddata.CCDData
420
StdDevUncertainty = astropy.nddata.StdDevUncertainty
421
422
# Time series types
423
TimeSeries = astropy.timeseries.TimeSeries
424
LombScargle = astropy.timeseries.LombScargle
425
426
# Uncertainty types
427
Distribution = astropy.uncertainty.Distribution
428
429
# Visualization types
430
ImageNormalize = astropy.visualization.ImageNormalize
431
432
# Utility types
433
Progress = astropy.utils.Progress
434
435
# SAMP types
436
SAMPHubServer = astropy.samp.SAMPHubServer
437
SAMPIntegratedClient = astropy.samp.SAMPIntegratedClient
438
```