What’s New in Astropy 5.2?


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

In particular, this release includes:

Quantity data types

The default dtype argument for Quantity has been changed, so that one can now explicitly give dtype=None to get the same behaviour as numpy. Without an explicit argument, any integer values are still upcast to floating point, since that makes more sense for physical quantities.

Updates to astropy.cosmology

A new comparison function has been added – astropy.cosmology.cosmology_equal() – that mirrors its numpy counterparts but allows for the arguments to be converted to a Cosmology and to compare flat cosmologies with their non-flat equivalents.

>>> from astropy.cosmology import cosmology_equal
>>> from astropy.cosmology import FlatLambdaCDM, LambdaCDM
>>> cosmo1 = FlatLambdaCDM(70, 0.3)
>>> cosmo2 = LambdaCDM(70, 0.3, 0.7)
>>> cosmology_equal(cosmo1.to_format("mapping"), cosmo2,
...                 format=("mapping", None), allow_equivalent=True)

Topocentric ITRS Frame

A topocentric ITRS frame has been added that makes dealing with near-Earth objects easier and more intuitive.:

>>> from astropy.coordinates import EarthLocation, AltAz, ITRS
>>> from astropy.time import Time
>>> from astropy import units as u

>>> t = Time('J2010')
>>> obj = EarthLocation(-1*u.deg, 52*u.deg, height=10.*u.km)
>>> home = EarthLocation(-1*u.deg, 52*u.deg, height=0.*u.km)

>>> # Direction of object from GEOCENTER
>>> itrs_geo = obj.get_itrs(t).cartesian

>>> # now get the Geocentric ITRS position of observatory
>>> obsrepr = home.get_itrs(t).cartesian

>>> # topocentric ITRS position of a straight overhead object
>>> itrs_repr = itrs_geo - obsrepr

>>> # create an ITRS object that appears straight overhead for a TOPOCENTRIC OBSERVER
>>> itrs_topo = ITRS(itrs_repr, obstime=t, location=home)

>>> # convert to AltAz
>>> aa = itrs_topo.transform_to(AltAz(obstime=t, location=home))

Enhanced Fixed Width ASCII Tables

It is now possible to read and write a fixed width ASCII table that includes additional header rows specifying any or all of the column dtype, unit, format, and description. This is available in the fixed_width and fixed_width_two_line formats via the new header_rows keyword argument:

>>> from astropy.io import ascii
>>> from astropy.table.table_helpers import simple_table
>>> dat = simple_table(size=3, cols=4)
>>> dat["b"].info.unit = "m"
>>> dat["d"].info.unit = "m/s"
>>> dat["b"].info.format = ".2f"
>>> ascii.write(
...     dat,
...     format="fixed_width_two_line",
...     header_rows=["name", "unit", "format"]
... )
a    b c     d
     m   m / s
- ---- - -----
1 1.00 c     4
2 2.00 d     5
3 3.00 e     6

Accessing cloud-hosted FITS files

A use_fsspec argument has been added to astropy.io.fits.open which enables users to seamlessly extract data from FITS files stored on a web server or in the cloud without downloading the entire file to local storage. This feature uses a new optional dependency, fsspec, which supports a range of remote and distributed storage backends including Amazon and Google Cloud Storage. For example, you can now access a Hubble Space Telescope image located in Hubble’s public Amazon S3 bucket as follows:

>>> from astropy.io import fits
>>> uri = "s3://stpubdata/hst/public/j8pu/j8pu0y010/j8pu0y010_drc.fits"
>>> with fits.open(uri, fsspec_kwargs={"anon": True}) as hdul:  
...     # Download a single header
...     header = hdul[1].header
...     # Download a single image
...     mydata = hdul[1].data
...     # Download a small cutout
...     cutout = hdul[1].section[10:20, 30:50]

Note that the example above obtains a cutout image using the section attribute rather than the traditional data attribute. The use of .section ensures that only the necessary parts of the FITS image are transferred from the server, rather than downloading the entire data array. This trick can significantly speed up your code if you require small subsets of large FITS files located on slow (remote) storage systems. See Obtaining subsets from cloud-hosted FITS files for additional information on working with FITS files in this way.

Full change log

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

Renamed/removed functionality