{"id":7005,"library":"asdf-astropy","title":"ASDF Astropy Serialization Support","description":"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.","status":"active","version":"0.11.0","language":"en","source_language":"en","source_url":"https://github.com/astropy/asdf-astropy","tags":["astronomy","serialization","ASDF","astropy","data-format"],"install":[{"cmd":"pip install asdf-astropy","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Core ASDF library for file format parsing and serialization. asdf-astropy provides converters for Astropy types to be used with ASDF.","package":"asdf"},{"reason":"The core astronomy library whose objects (e.g., coordinates, units, models) are serialized by asdf-astropy.","package":"astropy"}],"imports":[{"note":"Main class for creating and managing ASDF files.","symbol":"AsdfFile","correct":"from asdf import AsdfFile"},{"note":"Function for loading an ASDF file.","symbol":"open","correct":"from asdf import open"},{"note":"Example of an Astropy object commonly serialized (no direct asdf-astropy import needed, as plugins auto-register).","symbol":"SkyCoord","correct":"from astropy.coordinates import SkyCoord"}],"quickstart":{"code":"import asdf\nfrom astropy.coordinates import SkyCoord\nfrom astropy import units as u\n\n# Create an Astropy object (e.g., a SkyCoord)\ncoord = SkyCoord(ra=10.68458 * u.deg, dec=41.26917 * u.deg, frame='icrs')\n\n# Create an ASDF tree (a dictionary mapping keys to objects)\ntree = {'my_coordinate': coord}\n\n# Create an AsdfFile object\nff = asdf.AsdfFile(tree)\n\n# Save the ASDF tree to a file\nfile_path = 'my_astropy_coord.asdf'\nff.write_to(file_path)\nprint(f\"Saved SkyCoord to {file_path}\")\n\n# Load the ASDF file and access the object\nwith asdf.open(file_path) as af:\n    loaded_coord = af['my_coordinate']\n    print(f\"Loaded SkyCoord: {loaded_coord}\")\n    assert loaded_coord == coord","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade Python to 3.11 or newer (`python -m pip install --upgrade python` or via conda/system package manager).","message":"asdf-astropy 0.11.0 drops support for Python versions older than 3.11. Users on Python 3.8 or 3.10 must upgrade their Python environment to use this version.","severity":"breaking","affected_versions":"<0.11.0"},{"fix":"Ensure `asdf-astropy` is installed and rely on its auto-registered converters rather than explicit imports or usage of `astropy.io.misc.asdf`.","message":"The `astropy.io.misc.asdf` module's functionality is superseded by `asdf-astropy`. When `asdf-astropy` is installed, Astropy's built-in plugins are ignored. The `astropy.io.misc.asdf` module will be removed in a future version of Astropy.","severity":"breaking","affected_versions":"All versions when `astropy.io.misc.asdf` is used"},{"fix":"Instead of `astropy.test()`, use `pytest` from your terminal (e.g., `pytest --pyargs astropy` or `pytest path/to/astropy/tests`).","message":"Running tests directly via `astropy.test()` can fail when `asdf-astropy` is installed, due to conflicts in test discovery or execution. Running `pytest` from the command line, however, typically works correctly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all custom Astropy/SunPy map subclasses are imported and registered *before* any ASDF file operations (loading or saving) involving them.","message":"When saving custom Astropy map subclasses to ASDF, they may be loaded back as `sunpy.map.GenericMap` instead of their specific class if the custom subclass is not registered with `sunpy.map.Map` upon loading, or if ASDF is invoked before the custom map sources are imported.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Use the `pytest` command-line tool to run tests instead of `astropy.test()`. For example: `pytest --pyargs astropy`.","cause":"Conflict or incompatibility in how astropy's internal test runner interacts with the `asdf-astropy` package's test setup, specifically affecting doctests.","error":"Running tests from astropy.test() fails when asdf-astropy is installed #16165"},{"fix":"Ensure `asdf-astropy` is installed in your environment (`pip install asdf-astropy`). If using custom Astropy-like classes, verify that `asdf-astropy` supports them or consider writing a custom ASDF converter.","cause":"Attempting to serialize an Astropy object for which `asdf-astropy` does not have a registered converter, or `asdf-astropy` is not correctly installed/loaded. The 'xxx' would be a specific type like 'complex' or a custom Astropy object.","error":"asdf.exceptions.ValidationError: tag:stsci.edu:asdf/core/xxx-1.0.0 is not a valid tag"},{"fix":"This is generally not a critical error, but it signals a deprecated path. Ensure you are relying on `asdf-astropy` for serialization. The `astropy.io.misc.asdf` module will eventually be removed from Astropy, so transition any explicit usage away from it.","cause":"This is a warning indicating that you have both the older, built-in Astropy ASDF plugins and `asdf-astropy` installed. `asdf-astropy` takes precedence.","error":"UserWarning: The plugins in astropy.io.misc.asdf are superseded by asdf-astropy"}]}