ASDF Coordinates Schemas
ASDF Coordinates Schemas (asdf-coordinates-schemas) provides ASDF schemas specifically for validating astronomical coordinate tags, primarily those defined by `astropy.coordinates`. This package is typically consumed as a dependency by higher-level integration packages like `asdf-astropy` rather than being installed directly by end-users. It is part of the broader ASDF ecosystem, is actively maintained, and is currently at version 0.5.1.
Common errors
-
asdf.exceptions.ValidationError: Tag 'tag:astropy.org:astropy/coordinates/skycoord-1.0.0' not found in schema
cause The ASDF library could not find the schema definition required to validate the `SkyCoord` tag. This typically means the extension that provides this schema (e.g., `asdf-astropy`) is not installed or properly registered.fixInstall `asdf-astropy` to register the necessary schemas and converters: `pip install asdf-astropy`. -
TypeError: 'SkyCoord' object is not ASDF-serializable
cause When attempting to write an `astropy.coordinates.SkyCoord` object to an ASDF file, the `asdf` library reported that it doesn't know how to serialize this Python object. This indicates that the corresponding converter for `SkyCoord` is not registered.fixEnsure that `asdf-astropy` is installed. It provides the necessary converters for `astropy.coordinates` objects to be serialized into ASDF files: `pip install asdf-astropy`.
Warnings
- gotcha Users should generally install `asdf-astropy` instead of `asdf-coordinates-schemas` directly. `asdf-coordinates-schemas` only provides the schema definitions, while `asdf-astropy` provides the necessary Python converters and automatically registers these schemas with the `asdf` library for practical usage.
- breaking Major version changes in ASDF tags (e.g., `skycoord-1.0.0` vs. `skycoord-2.0.0`) signify breaking changes in the schema definition. If you are working with ASDF files created with older versions of `astropy.coordinates` or the ASDF standard, ensure your `asdf` and `asdf-astropy` installations are compatible with the schema versions used in those files.
- deprecated The core `asdf` library, which is fundamental to using `asdf-coordinates-schemas` indirectly, has deprecated `AsdfFile.open` in favor of `asdf.open` (as of ASDF 2.2). While not directly part of `asdf-coordinates-schemas`, users interacting with ASDF files should use the modern `asdf.open` approach.
Install
-
pip install asdf-coordinates-schemas
Imports
- Not applicable for direct import
import asdf_coordinates_schemas
This library primarily provides schema definitions for the ASDF ecosystem. It is not typically imported directly into Python code for use of its classes or functions. Its schemas are automatically registered and used by the `asdf` library when `asdf-astropy` is installed.
Quickstart
import asdf
import astropy.units as u
from astropy.coordinates import SkyCoord, ICRS
# This example relies on asdf-astropy being installed to register the schemas and converters.
# If you run this without asdf-astropy, it will likely fail to serialize SkyCoord.
# Create an Astropy SkyCoord object
coord = SkyCoord(ra=10.68458 * u.deg, dec=41.26917 * u.deg, frame=ICRS())
# Create an ASDF tree with the coordinate object
tree = {'my_coordinate': coord}
# Save the ASDF tree to a file
# This will use the schemas provided by asdf-coordinates-schemas (via asdf-astropy)
with asdf.AsdfFile(tree) as af:
af.write('my_coordinates.asdf')
print("ASDF file 'my_coordinates.asdf' created successfully.")
# Read the ASDF file back
with asdf.open('my_coordinates.asdf') as af_read:
read_coord = af_read['my_coordinate']
print(f"Read coordinate: {read_coord}")
print(f"Type: {type(read_coord)}")