ASDF Astropy Serialization Support

0.11.0 · active · verified Thu Apr 16

asdf-astropy is an extension library that provides ASDF (Advanced Scientific Data Format) serialization support for various Astropy objects. It allows for portable, hierarchical, and human-readable representation of data, including astronomical coordinates, units, and models. This package supersedes older ASDF plugins that were built directly into Astropy. The current version is 0.11.0, with releases generally synchronized with major Astropy and ASDF releases.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to create an Astropy `SkyCoord` object, embed it within an ASDF tree, save it to a `.asdf` file, and then load it back. The `asdf-astropy` package automatically registers the necessary converters upon installation, allowing `asdf` to seamlessly handle Astropy types.

import asdf
from astropy.coordinates import SkyCoord
from astropy import units as u

# Create an Astropy object (e.g., a SkyCoord)
coord = SkyCoord(ra=10.68458 * u.deg, dec=41.26917 * u.deg, frame='icrs')

# Create an ASDF tree (a dictionary mapping keys to objects)
tree = {'my_coordinate': coord}

# Create an AsdfFile object
ff = asdf.AsdfFile(tree)

# Save the ASDF tree to a file
file_path = 'my_astropy_coord.asdf'
ff.write_to(file_path)
print(f"Saved SkyCoord to {file_path}")

# Load the ASDF file and access the object
with asdf.open(file_path) as af:
    loaded_coord = af['my_coordinate']
    print(f"Loaded SkyCoord: {loaded_coord}")
    assert loaded_coord == coord

view raw JSON →