ASDF_WRITE

The ASDF_WRITE procedure takes an ASDF_File object and writes the header plus all of the associated data. The ASDF (Advanced Scientific Data Format) file format consists of a YAML header followed by zero or more binary data blocks. Binary data can also be stored separately in external files that are linked to the main ASDF file.

This routine is written in the IDL language. Its source code can be found in the file asdf_write.pro in the lib/datatypes subdirectory of the IDL distribution.

Examples

Create an ASDF file containing a single variable and write the data out to a file:

file = ASDF_File('mydata', findgen(100,50))

ASDF_Write, 'myfile.asdf', file

Print out the YAML headers from the file:

IDL> print, ASDF_Parse('myfile.asdf')

#ASDF 1.0.0

... standard ASDF headers ...

mydata: !core/ndarray-1.0.0

  shape: [50,100]

  byteorder: little

  datatype: float32

  source: 0

Syntax

ASDF_WRITE, Filename, Asdf

Arguments

Filename

Filename must be a string containing the file path to the ASDF file to be written. Any "external" data blocks within the ASDF_File will be written to the same directory and filename with a file suffix of nnnn.asdf, where nnnn is the index number of the data block, starting at zero. For example, if your filename is myfilename.asdf, then external blocks will be written to files myfilename0000.asdf, myfilename0001.asdf, myfilename0002.asdf, etc.

Asdf

Set this argument to an ASDF_File object containing a nested hierarchy of data blocks.

Note: During the write process, IDL will recursively walk the ASDF_File. For each ASDF_NDArray object that is found, the data will first be read in from any external files. The ASDF_NDArray object will then be updated with a new source property value (either a new index for internal data blocks, or a new filename for external data blocks), and then the data block will be written out to the file.

Note: During write, any scalars that are type complex or double complex will be converted into YAML_Value objects with the !core/complex-1.0.0 tag.

Keywords

None

Conversion Rules

When converting IDL variables into ASDF files, the following rules are used:

IDL Variable Type ASDF Item Notes
ASDF_File Main Document  
ASDF_NDArray

ASDF !core/ndarray-1.0.0

 
IDL numeric array

ASDF !core/ndarray-1.0.0

 

YAML_Map

Mapping

Optional ANCHOR, TAG properties

OrderedHash, Dictionary, or Hash Mapping  
YAML_Sequence Sequence

Optional ANCHOR, TAG properties

List Sequence  
Byte array (not boolean) !!binary with base64  
YAML_Value Scalar value

Optional ANCHOR, TAG properties

YAML_Alias Alias (reference) ALIAS property
String String

Strings that might match a number or null will be quoted

!NULL null  
Boolean

false or true

 
Scalar byte or integer value Integer  
BigInteger Integer  
Floating-point scalar number Floating-point number  

Complex or Double complex scalar

!core/complex-1.0.0  

Additional Examples

You can construct ASDF files from regular IDL arrays, scalars, hashes, or lists. Using hashes or lists allows you to create a nested hierarchy of data. ASDF_Write will automatically search for IDL arrays within the nested hierarchy and will write them out as ASDF ndarray blocks. For example:

cal = OrderedHash()

cal['title'] = 'Calibration Data'

cal['date'] = 2023

cal['telescope'] = 'JWST'

cal['calibration'] = findgen(10)

file = ASDF_File('Calibration', cal)

Add another data block to the same file using array indexing, and then write out the data to a file:

file['Image'] = bindgen(3, 100, 50)

ASDF_Write, 'calibration.asdf', file

Print out the YAML headers from the file:

print, ASDF_Parse('calibration.asdf')

IDL prints:

#ASDF 1.0.0

... standard ASDF headers ...

Calibration:

  title: Calibration Data

  date: 2023

  telescope: JWST

  calibration: !core/ndarray-1.0.0

    data: [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0]

    shape: [10]

    byteorder: little

    datatype: float32

Image: !core/ndarray-1.0.0

  shape: [50,100,3]

  byteorder: little

  datatype: uint8

  source: 0

Version History

8.9

Introduced

See Also

ASDF_FILE, ASDF_NDARRAY, ASDF_PARSE