.. _whatsnew-5.1:

**************************
What's New in Astropy 5.1?
**************************

Overview
========

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

In particular, this release includes:

* :ref:`whatsnew-5.1-cosmology`
* :ref:`whatsnew-doppler-redshift-eq`
* :ref:`whatsnew-io-ascii-converters`
* :ref:`whatsnew-structured-columns`
* :ref:`whatsnew-fitters`
* :ref:`whatsnew-iers-handling`
* :ref:`whatsnew-uncertainty-represent`
* :ref:`whatsnew-schechter1d-model`

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

.. _whatsnew-5.1-cosmology:

Updates to :mod:`~astropy.cosmology`
====================================

|Cosmology| is now an abstract base class, and subclasses must override the
abstract property :attr:`~astropy.cosmology.Cosmology.is_flat`. For |FLRW|,
:attr:`~astropy.cosmology.FLRW.is_flat` checks that ``Ok0 == 0`` and ``Otot0 ==
1``.

Astropy v5.0 introduced cosmological equivalency -- with method
:meth:`~astropy.cosmology.Cosmology.is_equivalent` -- where two cosmologies may
be equivalent even if not of the same class. For example, an instance of
|LambdaCDM| might have :math:`\Omega_0=1` and :math:`\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)
    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 :attr:`~astropy.cosmology.FlatCosmologyMixin.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), ...


:meth:`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, ...


.. _whatsnew-doppler-redshift-eq:

:func:`~astropy.units.equivalencies.doppler_redshift` equivalency
=================================================================

New :func:`astropy.units.equivalencies.doppler_redshift` is added to
provide conversion between Doppler redshift and radial velocity.

.. _whatsnew-io-ascii-converters:

Specifying data types when reading ASCII tables
===============================================

The syntax for specifying the data type of columns when reading a table using
:func:`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})  # doctest: +SKIP

Previously, doing the same data type specification required using the
:func:`~astropy.io.ascii.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)]})  # doctest: +SKIP

Note that the previous syntax is still supported for backwards compatibility
and there is no intent to remove this. See :ref:`io-ascii-read-converters` for
details.

.. _whatsnew-structured-columns:

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 :ref:`format_stuctured_array_columns` for details and an example.

As part of this update, there is an API change in the behavior when a structured
|ndarray| is added as a column to a |Table|. Previously this was
converted to an :class:`~astropy.table.NdarrayMixin` subclass of |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 |ndarray| is
added to a |Table| as a native |Column| and saving to file is supported.

.. _whatsnew-fitters:

New model fitters have been added
=================================

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

* :class:`~astropy.modeling.fitting.TRFLSQFitter`, which uses the Trust Region
  Reflective (TRF) algorithm.
* :class:`~astropy.modeling.fitting.LMLSQFitter`, which uses the
  Levenberg-Marquardt (LM) algorithm, via the
  :func:`scipy.optimize.least_squares` function.
* :class:`~astropy.modeling.fitting.DogBoxLSQFitter`, which uses the dogleg algorithm.

.. _whatsnew-iers-handling:

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
<astropy.utils.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 :class:`~astropy.utils.iers.IERSRangeError`),
``'warn'`` (issue an :class:`~astropy.utils.iers.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.

.. _whatsnew-uncertainty-represent:

Uncertainty classes can be transformed into each other
======================================================

Subclasses of :class:`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  ,
                     0.01234568])

.. _whatsnew-schechter1d-model:

Schechter1D Model
=================

A new :class:`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 :ref:`changelog`.

Contributors to the v5.0 release
================================

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

.. hlist::
  :columns: 4

  -  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
  -  E. 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.
