What’s New in Astropy 2.0?

Easier use of efficient bytestring Table columns in Python 3

Working with bytestring Table columns (numpy 'S' dtype) in Python 3 has been made more convenient because it is now possible to compare and set array elements with the natural Python string (str) type. Previously one had to use the Python bytes type and bytestring literals like b'hello'. This change allows working with ASCII data columns in Python 3 using only 1-byte per character instead of the default 4-bytes per character for the numpy 'U' unicode dtype. For large datasets this improves memory performance.

Please see Bytestring columns in Python 3 for details. Note that no change has been made to behavior for Python 2.

Note

This introduces an API change that affects comparison of bytestring column elements in Python 3.

If comparison with str instead of bytes is a problem (and bytes is really more logical), please open an issue on GitHub.

No relativistic species by default in cosmological models

For all of the built in cosmological model types (e.g., FlatLambdaCDM) the default CMB temperature at z=0 is now 0K, which corresponds to no contributions from photons or neutrinos (massive or otherwise). This does not affect built in literature models (such as the WMAP or Planck models). The justification is to avoid including mass-energy components that the user has not explicitly requested. This is a non-backwards compatible change, although the effects are small for most use cases.

Convolution has undergone a significant overhaul to make fft and direct convolution consistent. They keyword arguments have changed and the behavior of convolve is no longer the same as in versions prior to 2.0 (although convolve_fft‘s behavior remains unchanged). The details are given on the astropy convolution.

Cone search module (astropy.vo.conesearch) moved to astroquery

The cone search module has been moved to Astroquery (0.3.5 and later) and will be removed from Astropy in a future version. The API here will be preserved as “classic” API in Astroquery, however some configuration behavior might change; See the Astroquery documentation for new usage details.

SAMP module moved to astropy.samp

The SAMP (Simple Application Messaging Protocol) module, formerly available in astropy.samp, has now been moved to astropy.samp, so you should update any imports to this module.

New SigmaClip class

A new SigmaClip class was added as an object-oriented interface for sigma clipping:

>>> from astropy.stats import SigmaClip
>>> data = [1, 5, 6, 8, 100, 5, 3, 2]
>>> sigclip = SigmaClip(sigma=2, iters=5)
>>> print(sigclip)  
<SigmaClip>
    sigma: 3
    sigma_lower: None
    sigma_upper: None
    iters: 10
    cenfunc: <function median at 0x108dbde18>
    stdfunc: <function std at 0x103ab52f0>
>>> sigclip(data)
masked_array(data = [1 5 6 8 -- 5 3 2],
             mask = [False False False False  True False False False],
       fill_value = 999999)

Note that once the sigclip instance is defined above, it can be applied to other data, using the same, already-defined, sigma-clipping parameters.

New std_ddof keyword to sigma_clipped_stats()

A new std_ddof keyword option was added to sigma_clipped_stats(). This keyword represents the delta degrees of freedom for the standard deviation calculation. Specifically, the divisor used in the calculation is N - std_ddof, where N represents the number of array elements. The std_ddof default value is zero.

New biweight_midcovariance function in astropy.stats

A new biweight_midcovariance function was added to astropy.stats. This is a robust and resistant estimator of the covariance matrix. For example:

>>> import numpy as np
>>> from astropy.stats import biweight_midcovariance
>>> # Generate 2D normal sampling of points
>>> rng = np.random.RandomState(1)
>>> d = np.array([rng.normal(0, 1, 200), rng.normal(0, 3, 200)])
>>> # Introduce an obvious outlier
>>> d[0,0] = 30.0
>>> # Calculate biweight covariances
>>> bw_cov = biweight_midcovariance(d)
>>> # Print out recovered standard deviations
>>> print(np.around(np.sqrt(bw_cov.diagonal()), 1))
[ 0.9  3.1]

New statistical estimators for Ripley’s K Function

New statistical estimators for Ripley’s K Function, RipleysKEstimator, in astropy.stats. For example:

(png, svg, pdf)

../_images/2-0-1.png

New way to instantiate a BinTableHDU directly from a Table

A new way to instantiate a FITS BinTableHDU directly from a Table object. For example:

>>> from astropy.io import fits
>>> from astropy.table import Table
>>> tab = Table([[1, 2, 3], ['a', 'b', 'c'], [2.3, 4.5, 6.7]],
...             names=['a', 'b', 'c'], dtype=['i', 'U1', 'f'])
>>> hdu = fits.BinTableHDU(tab)

New printdiff convenience function for FITS

A new printdiff convenience function was added for comparison between FITS files. For example:

>>> from astropy.io import fits
>>> hdu1 = fits.ImageHDU([1, 2, 3])
>>> hdu2 = fits.ImageHDU([1, 2.1, 3])
>>> fits.printdiff(hdu1, hdu2)

Headers contain differences:
  Keyword BITPIX   has different values:
     a> 64
     b> -64
      ? +

Data contains differences:
  Data differs at [2]:
       (int64) a> 2
     (float64) b> 2.1000000000000001
  1 different pixels found (33.33% different).

New molar_mass_amu unit equivalency

A new equivalency named molar_mass_amu to convert between g/mol unit to atomic mass unit (amu). For example:

>>> from astropy import constants as const
>>> from astropy import units as u
>>> x = 1 * (u.g / u.mol)
>>> y = 1 * u.u
>>> x.to(u.u, equivalencies=u.molar_mass_amu())
<Quantity 1.0 u>
>>> y.to(u.g/u.mol, equivalencies=u.molar_mass_amu())
<Quantity 1.0 g / mol>

New unit support for most models

Most Astropy models now can handle inputs with units, and produce the appropriate outputs with units as well. Some models cannot support this due to their definitions (e.g., Legendre, Hermite, etc), while some will have this capability added in a future release. Example usage:

>>> from astropy import units as u
>>> from astropy.modeling.models import Gaussian1D
>>> g = Gaussian1D(amplitude=1*u.J, mean=1*u.m, stddev=0.1*u.m)
>>> g([3, 4, 5.5] * u.cm)
<Quantity [  3.70353198e-21,  9.72098502e-21,  4.05703276e-20] J>

New n_submodels shared method in single and compound models

A new n_submodels shared method in single and compound models. This enables accurate reporting of number of sub-models in a given model. For example:

>>> from astropy.modeling.models import Gaussian1D, Gaussian2D
>>> g1 = Gaussian1D()
>>> g1.n_submodels()
1
>>> g2 = g1 + Gaussian1D()
>>> g2.n_submodels()
2

Two new optional arguments when evaluating a model - with_bounding_box and fill_value

Two new arguments can be passed when evaluating a model to specify the bounding box should be respected. If with_bounding_box=True and a model has a bounding_box, the output values corresponding to inputs outside the bounding box are set to fill_value. For example:

>>> from astropy.modeling.models import Polynomial1D
>>> import numpy as np
>>> x = np.arange(-5, 5)
>>> p = Polynomial1D(1, c0=2, c1=3)
>>> p.bounding_box = (-1, 5)
>>> p(x, with_bounding_box=True, fill_value=-100)
array([-100., -100., -100., -100.,   -1.,    2.,    5.,    8.,   11.,   14.])

No more bundled pytest with Astropy distribution

The bundled version of pytest has now been removed, but the astropy.tests.helper.pytest import will continue to work properly. Affiliated packages should nevertheless transition to importing pytest directly rather than from astropy.tests.helper. This also means that pytest is now a formal requirement for testing for both Astropy and for affiliated packages.

New image class CCDData added

A new class, CCDData, has been added to the nddata package. It can read from/write to FITS files, provides methods for arithmetic operations with propagation of uncertainty, and support for binary masks.

Store astropy core object types in ASCII ECSV table file

It is now possible to store the following mixin column types in an ASCII ECSV table file. The table file can then be read back into astropy with no loss of object data or attributes.

Barycentric/heliocentric radial velocity corrections

astropy.coordinates.SkyCoord now have a radial_velocity_correction method which can be used to compute heliocentric and barycentric corrections for radial velocity measurements. While in the future this may use the mechanisms described in Experimental velocity support in astropy.coordinates, currently it uses a simpler algorithm for numerical stability.

Experimental velocity support in astropy.coordinates

astropy.coordinates frame objects now contains experimental support for storing and transforming velocities. This includes support for “differential” objects which contain differences of representations.

Full change log

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