What’s New in Astropy 5.1?


Astropy 5.1 is a major release that adds significant new functionality since the 5.0 LTS release.

In particular, this release includes:

In addition to these major changes, Astropy v5.1 includes a large number of smaller improvements and bug fixes, which are described in the Full Changelog. By the numbers:

  • 1077 commits have been added since 5.0

  • 155 issues have been closed since 5.0

  • 289 pull requests have been merged since 5.0

  • 58 people have contributed since 5.0

  • 13 of which are new contributors

Updates to cosmology

Cosmology is now an abstract base class, and subclasses must override the abstract property is_flat. For FLRW, is_flat checks that Ok0 == 0 and Otot0 == 1.

Astropy v5.0 introduced cosmological equivalency – with method is_equivalent() – where two cosmologies may be equivalent even if not of the same class. For example, an instance of LambdaCDM might have \(\Omega_0=1\) and \(\Omega_k=0\) and therefore be flat, like FlatLambdaCDM. Now the keyword argument format is added to extend the notion of equivalence to any Python object that can be converted to a Cosmology:

>>> from astropy.cosmology import Planck18
>>> tbl = Planck18.to_format("astropy.table")
>>> Planck18.is_equivalent(tbl, format=True)

The list of valid formats, e.g. the Table in this example, may be checked with Cosmology.from_format.list_formats().

A new property nonflat has been added to flat cosmologies (FlatCosmologyMixin subclasses) to get an equivalent Cosmology, but of the corresponding non-flat class:

>>> Planck18.nonflat
LambdaCDM(name="Planck18", H0=67.66 km / (Mpc s), ...

astropy.cosmology.FlatCosmologyMixin.clone() has been enhanced to allow for a flat Cosmology to clone on the equivalent non-flat Cosmology. For example:

>>> Planck18.clone(to_nonflat=True, Ode0=1)
LambdaCDM(name="Planck18 (modified)", H0=67.66 km / (Mpc s), Om0=0.30966, Ode0=1.0, ...

doppler_redshift() equivalency

New astropy.units.equivalencies.doppler_redshift() is added to provide conversion between Doppler redshift and radial velocity.

Specifying data types when reading ASCII tables

The syntax for specifying the data type of columns when reading a table using astropy.io.ascii.read() has been simplified considerably. For instance, to force every column in a table to be read as a float you can now do:

>>> from astropy.table import Table
>>> t = Table.read('table.dat', format='ascii', converters={'*': float})  

Previously, doing the same data type specification required using the convert_numpy() function and providing the dict value as a list even for only one element:

>>> from astropy.io.ascii import convert_numpy
>>> t = Table.read('table.dat', format='ascii',
...                converters={'*': [convert_numpy(float)]})  

Note that the previous syntax is still supported for backwards compatibility and there is no intent to remove this. See Converters for Specifying Dtype for details.

Structured Columns

Columns which are numpy structured arrays are now fully supported, effectively allowing tables within tables. This applies to Column, MaskedColumn, and Quantity columns, and includes possible structured units. These structured data columns can be stored in ECSV, FITS, and HDF5 formats. A new way to specify the formatting of a structured column is now available using parameter substitutions corresponding to the structure field names. See Structured array columns for details and an example.

As part of this update, there is an API change in the behavior when a structured numpy.ndarray is added as a column to a Table. Previously this was converted to an NdarrayMixin subclass of numpy.ndarray and added as a mixin column. This was because saving as a file (e.g. HDF5, FITS, ECSV) was not supported for structured array columns. Now a structured numpy.ndarray is added to a Table as a native Column and saving to file is supported.

New model fitters have been added

New fitters have been added to fitting based around the available algorithms provided by scipy.optimize.least_squares(), which is now the recommended least-squares optimization algorithm from scipy. These new fitters are:

Allow time conversions without predictive Earth rotation data (IERS-A)

Some time conversions like UTC -> UT1 require additional Earth rotation data for full accuracy. These data are provided by the online IERS service as the IERS-A tables and are downloaded as required. In some use cases this download is not desired or possible. Examples include an application where full accuracy is not required, running on a cluster node without internet access, or the rare instances when the IERS server and mirror are not available. For these cases there is a new config item iers.conf.iers_degraded_accuracy that specifies the behavior when times are outside the range of available IERS data. The options are 'error' (default to raise an IERSRangeError), 'warn' (issue an IERSDegradedAccuracyWarning) or 'ignore' (ignore the warning).

In addition, the logic for auto-downloads was changed to guarantee that no matter what happens with the IERS download operations, only warnings will be issued. These warnings can be ignored if desired.

Uncertainty classes can be transformed into each other

Subclasses of astropy.nddata.NDUncertainty can now be converted between each other. This is done via transforming the original uncertainty values into a variance (if possible), and then transforming the variance into the desired uncertainty. A simple example of this is:

>>> import numpy as np
>>> from astropy.nddata import InverseVariance, StdDevUncertainty
>>> StdDevUncertainty(np.arange(1, 10)).represent_as(InverseVariance)
InverseVariance([1.        , 0.25      , 0.11111111, 0.0625    ,
                 0.04      , 0.02777778, 0.02040816, 0.015625  ,

Schechter1D Model

A new astropy.modeling.powerlaws.Schechter1D model, parameterized in terms of magnitudes, for luminosity functions was added.

Full change log

To see a detailed list of all changes in version v5.1, including changes in API, please see the Full Changelog.

Contributors to the v5.0 release

The people who have contributed to the code for this release are:

  • Aarya Patil

  • Adam Broussard *

  • Adam Ginsburg

  • Adrian Price-Whelan

  • Albert Y. Shih

  • Andrii Oriekhov *

  • Brian Soto

  • Chiara Marmo

  • Clare Shanahan

  • Clément Robert

  • David Stansby

  • Derek Homeier

    1. Madison Bray

  • Ed Slavich

  • Eero Vaher

  • Emir Karamehmetoglu

  • Erik Tollerud

  • Francesc Vilardell *

  • Geert Barentsen

  • Hans Moritz Günther

  • Hsin Fan *

  • James Tocknell

  • Jero Bado

  • Jerry Ma

  • Jo Bovy *

  • Jonas Kemmer *

  • Karl Gordon

  • Karl Wessel

  • Kelle Cruz

  • Kyle Conroy *

  • Larry Bradley

  • Laurie Stephey

  • Leo Singer

  • Malynda Chizek Frouard *

  • Marten van Kerkwijk

  • Matteo Bachetti

  • Matthew Craig

  • Maximilian Nöthe

  • Mihai Cara

  • Nabil Freij

  • Nathaniel Starkman

  • Neal McBurnett

  • Ole Streicher

  • Pey Lian Lim

  • Robel Geda

  • Roy Smart

  • Sam Van Kooten

  • Sarah Weissman *

  • Sebastian Meßlinger *

  • Simon Conseil

  • Stuart Mumford

  • Thomas Robitaille

  • Tom Aldcroft

  • William Jamieson

  • github-actions *

  • kYwzor *

  • mzhengxi *

  • orionlee

Where a * indicates that this release contains their first contribution to astropy.