asdf
Let's start by taking a look at a few basic ASDF use cases. This will introduce you to some of the core features of ASDF and will show you how to get started with using ASDF in your own projects.
To follow along with this tutorial, you will need to install the asdf
package. See installation
for details.
At its core, ASDF is a way of saving nested data structures to YAML. Here we save a dict
with the key/value pair 'hello': 'world'
.
from asdf import AsdfFile
# Make the tree structure, and create a AsdfFile from it. tree = {'hello': 'world'} ff = AsdfFile(tree) ff.write_to("test.asdf")
# You can also make the AsdfFile first, and modify its tree directly: ff = AsdfFile() ff.tree['hello'] = 'world' ff.write_to("test.asdf")
test.asdf
hidden
import asdf import numpy as np
# Create some data sequence = np.arange(100) squares = sequence**2 random = np.random.random(100)
# Store the data in an arbitrarily nested dictionary tree = { 'foo': 42, 'name': 'Monty', 'sequence': sequence, 'powers': { 'squares' : squares }, 'random': random }
# Create the ASDF file object from our data tree af = asdf.AsdfFile(tree)
# Write the data to a new file af.write_to('example.asdf')
example.asdf no_blocks
A rendering of the binary data contained in the file can be found below. Observe that the value of source
in the metadata corresponds to the block number (e.g. BLOCK 0
) of the block which contains the binary data.
example.asdf no_header