ASDF Transform Schemas
asdf-transform-schemas provides ASDF (Advanced Scientific Data Format) schemas primarily for validating transform tags, specifically those related to serializing `astropy.modeling` models into ASDF files. It acts as a dependency for higher-level packages like `asdf-astropy`, which implement the serialization logic. The library is currently at version 0.6.0 and generally follows the release cadence of the broader ASDF Standard.
Common errors
-
AttributeError: 'list' object has no attribute 'get'
cause This error, often accompanied by 'The metaschema specified by $schema was not found', occurred in ASDF when `jsonschema` version 4.10.0 was installed. It indicates a compatibility breakdown in schema validation.fixDowngrade `jsonschema` to a version prior to `4.10.0` (e.g., `pip install 'jsonschema<4.10.0'`) or upgrade your `asdf` core library and associated extensions to their latest versions, which typically include fixes for such incompatibilities. -
asdf.exceptions.ValidationError: tag:stsci.edu:asdf/transform/rotation2d-1.0.0 is not a valid tag
cause This error means that the ASDF file contains a transform tag (e.g., `rotation2d-1.0.0`) that the current ASDF environment cannot validate. This usually happens if the `asdf-astropy` extension, which registers these transform schemas, is not installed or not correctly loaded.fixEnsure `asdf-astropy` is installed (`pip install asdf-astropy`). If it is, verify that it's properly registered with ASDF, which usually happens automatically on import, or by restarting your Python environment. Also, check the version compatibility between `asdf`, `asdf-astropy`, and the ASDF Standard version used in the file.
Warnings
- gotcha This package primarily provides ASDF schema definition files and does not expose a significant Python API for direct user interaction. To utilize these schemas for serializing and deserializing `astropy.modeling` objects, you must install `asdf-astropy`.
- breaking Version 0.2.1 of `asdf-transform-schemas` was yanked from PyPI due to a breaking change affecting JWST (James Webb Space Telescope) data processing. Users encountering issues with this specific version should upgrade to a later, stable release.
- gotcha Older versions of ASDF (the core library) experienced compatibility issues with `jsonschema` version `4.10.0`, leading to `AttributeError` or `DeprecationWarning` regarding missing metaschemas during validation. While `asdf-transform-schemas` is not directly the cause, it relies on `asdf`'s validation mechanisms.
- breaking The broader ASDF ecosystem, including `asdf-standard` versions (which influence schemas), has been dropping support for older Python versions. For instance, `asdf-standard` 1.5.0 (released Feb 2026) dropped Python 3.9 support. Ensure your Python environment meets the minimum requirements of all `asdf` related packages.
Install
-
pip install asdf-transform-schemas -
pip install asdf-astropy astropy
Quickstart
import asdf
from astropy.modeling.models import Rotation2D
import os
# Create an Astropy model
rot_model = Rotation2D(angle=45)
# Save the model to an ASDF file (asdf-astropy extension handles serialization)
afd = asdf.AsdfFile({'rotation_transform': rot_model})
file_path = 'rotation_transform.asdf'
afd.write_to(file_path)
print(f"ASDF file '{file_path}' created successfully.")
# Read the ASDF file back
with asdf.open(file_path) as afd_read:
read_model = afd_read['rotation_transform']
print(f"Read model: {read_model}")
print(f"Angle of read model: {read_model.angle.value}")
# Clean up
os.remove(file_path)