Skip to content

Latest commit

 

History

History
233 lines (181 loc) · 8.39 KB

5.3.rst

File metadata and controls

233 lines (181 loc) · 8.39 KB

What's New in Astropy 5.3?

Overview

Astropy 5.3 is a major release that adds significant new functionality since the 5.2 release.

In particular, this release includes:

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

  • X issues have been closed since v4.2
  • X pull requests have been merged since v4.2
  • X distinct people have contributed code

New flat astropy.cosmology classes

Two new cosmologies have been added, ~astropy.cosmology.FlatwpwaCDM and ~astropy.cosmology.Flatw0wzCDM, which are the flat variants of ~astropy.cosmology.wpwaCDM and ~astropy.cosmology.w0wzCDM, respectively.

>>> from astropy.cosmology import Flatw0wzCDM >>> cosmo = Flatw0wzCDM(H0=70, Om0=0.3, w0=-0.9, wz=0.2) >>> cosmo.comoving_distance(0.5) # doctest: +SKIP <Quantity 1982.66012926 Mpc>

New union operators for

We have added support for dictionary-style merge (|) and update (|=) of columns in the class. This follows the behavior for dict defined in PEP 584. |= works the same way as ~astropy.table.Table.update and updates the table in place. | return the updated table:

>>> from astropy.table import Table, QTable
>>> t1 = Table({'a': ['foo', 'bar'], 'b': [0., 0.]})
>>> t2 = QTable({'b': [1., 2.], 'c': [7., 11.]})
>>> t3 = t1 | t2  # Create new table which merges columns from t1 and t2
>>> t3
<Table length=2>
a      b       c
str3 float64 float64
---- ------- -------
foo     1.0     7.0
bar     2.0    11.0

>>> t2 |= t1  # Update t2 columns in-place with t1 columns
>>> t2
<QTable length=2>
   b       c     a
float64 float64 str3
------- ------- ----
    0.0     7.0  foo
    0.0    11.0  bar

When using |=, the other object does not need to be a , it can be anything that can be used for construct_table with a compatible number of rows.

Efficient data access for compressed FITS files

In previous astropy versions, when accessing data for a compressed FITS file via the ~astropy.io.fits.CompImageHDU.data property of ~astropy.io.fits.CompImageHDU, the whole data was read in and decompressed even if only a small part of the data was required. The ~astropy.io.fits.CompImageHDU class now has a ~astropy.io.fits.CompImageHDU.section property which can be used to access specific sections of the data and will result in as little data as possible being read in and decompressed. For a compressed image:

>>> hdu.section[300:400, 100:200]

will therefore return the same result as:

>>> hdu.data[300:400, 100:200]

but the former will be faster. The exact speedup will depend on the size of the data and the size of the tiles but could be 10-100x or more.

Added support for NOCOMPRESS for compressed FITS files

It is now possible to read and write compressed FITS files that make use of the NOCOMPRESS compression algorithm. This allows users to store data in uncompressed tiles by specifying compression_type='NOCOMPRESS' in ~astropy.io.fits.CompImageHDU.

New fraction option for representing units as strings

A new formatting option is added to switch between using fractions or using negative powers directly, with the fraction option also allowing to switch between inline and multiline prettyprinting of units:

>>> import astropy.units as u
>>> unit = u.Unit('erg / (s cm2)')
>>> print(unit.to_string('console'))
erg s^-1 cm^-2
>>> print(unit.to_string('console', fraction='inline'))
    erg / (s cm^2)
>>> print(unit.to_string('console', fraction='multiline'))
     erg
    ------
    s cm^2
>>> print(unit.to_string('unicode'))
erg s⁻¹ cm⁻²
>>> print(unit.to_string('unicode', fraction='inline'))
    erg / (s cm²)
>>> print(unit.to_string('unicode', fraction='multiline'))
     erg
    ─────
    s cm²

Note that the 'console' and 'unicode' formats now use fraction=False by default, since this will more reliably produce readable results when printing quantities, table headers and cells, etc. For 'latex' the default remains fraction='display', for an unchanged experience with IPython notebook.

Change in order in unit string representations

In string representations of units, the order of bases now is by decreasing power first, then alphabetical, instead of alphabetical independent of power. This is also how unit bases are stored internally and helps particularly for units without fractions (such as FITS), where a unit like Jy/beam was typeset as beam-1 Jy instead of the more logical Jy beam-1.

For typesetting with fractions, there is usually less effect, but the string representations of complicated units will change (e.g., what previously was erg / (Angstrom cm2 s) will now be erg / (Angstrom s cm2)).

Support for collapse operations on arbitrary axes in nddata

Take the sum, mean, maximum, or minimum along one or more axes, reducing the dimensions of the output, on ~astropy.nddata.NDData objects with appropriate propagation of uncertainties, masks, and units. For example, we can take the sum of ND masked quantities along the 1 axis like so:

>>> import numpy as np
>>> import astropy.units as u
>>> from astropy.nddata import NDDataArray, StdDevUncertainty
>>>
>>> data = [
...     [1, 2, 3],
...     [2, 3, 4]
... ]
>>> mask = [
...     [True, False, False],
...     [False, False, False]
... ]
>>> uncertainty = StdDevUncertainty(np.ones_like(data))
>>> nddata = NDDataArray(data=data, uncertainty=uncertainty, mask=mask, unit='m')
>>> sum_axis_1 = nddata.sum(axis=1)
>>> sum_axis_1, sum_axis_1.mask, sum_axis_1.uncertainty
(NDDataArray([6., 9.], unit='m'),
 array([ True, False]),
 StdDevUncertainty([1.41421356, 1.73205081]))

Refresh cached observatory site registry for methods

The convenience methods ~astropy.coordinates.EarthLocation.of_site and ~astropy.coordinates.EarthLocation.get_site_names use the observatory site registry from the astropy-data repository to return site data by name. Usually, the site registry is cached on the user's computer for quick access. The online version of the registry, however, is updated from time to time to include new locations. The user may refresh their locally cached site registry by passing the new refresh_cache=True option to these two functions.

Support for collapse operations on arbitrary axes in nddata

Propagate measurement uncertainties into the best-fit parameter covariances via the weights keyword argument in non-linear fitters. Decreasing the weights will now increase the uncertainties on the best-fit parameters.

Full change log

To see a detailed list of all changes in version v5.3, including changes in API, please see the changelog.