Python implementation of the ASDF Standard, a language-agnostic serialization format for scientific data. It handles serialization of Python objects (including NumPy arrays, Astropy objects, and custom types) into ASDF files, which are YAML-based with support for binary data. The library is actively developed with several releases per year, and the current version is 5.2.0.
pip install asdfVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple ASDF data structure, write it to a file, and then read the data back. It uses a dictionary for the tree structure and includes a NumPy array, a common use case for ASDF.
Instead of reassigning `ff.tree`, use `ff.update(new_dict)` to update the tree's content or create a new `AsdfFile` instance with the modified tree.
Upgrade your Python environment to version 3.10 or newer. Refer to the official Python documentation for upgrade instructions.
Open the file in read mode (`'r'`), make any necessary modifications to the loaded data, and then write the data to a new file or overwrite the existing one using `AsdfFile.write_to()`.
Implement a custom `asdf.extension.Extension` (which typically includes a `Tag` and `Converter`) and register it using `asdf.converters.add_extension` or by installing a package that provides the extension.
Use `asdf_file.update(new_dict)` to modify the contents of the tree, or create a new `asdf.AsdfFile` instance if a complete replacement of the tree structure is needed.
Ensure that the custom type has a corresponding `asdf.extension.Tag` and `asdf.extension.Converter` registered with ASDF. This usually involves defining an `asdf.extension.Extension` and adding it to the ASDF context.
Remove the `mode='r+'` argument. Open the file in read-only mode (`'r'`), then if modifications are required, load the data, apply changes, and save the updated data to a new ASDF file using `AsdfFile.write_to()`.