The ASDF_PARSE function takes an ASDF (Advanced Scientific Data Format) file and reads it into an IDL variable containing all of the data references in a nested hierarchy. The ASDF 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_parse.pro in the lib/datatypes subdirectory of the IDL distribution.
Tip: The result of ASDF_PARSE is a nested hierarchy of ASDF and YAML objects, arrays, and scalar values. If you print out the result, the output will automatically be printed in YAML format.
Create a simple ASDF file, then read it back into IDL:
a = ASDF_File('mydata', randomu(seed, 100, 50))
ASDF_Write, 'myfile.asdf', a
af = ASDF_Parse('myfile.asdf')
help, af['mydata', 'data']
AF ASDF_FILE <ID=28 NELEMENTS=3> TAG='!core/asdf-1.1.0' GLOBAL_TAGS=1
<Expression> ASDF_NDARRAY <ID=27> float32 [50,100] internal
<Expression> FLOAT = Array[100, 50]
Result = ASDF_PARSE(Filename)
The result is a nested hierarchy of ASDF objects, IDL arrays, and IDL scalar values. See below for the rules on converting ASDF data into IDL datatypes.
Filename must be a string containing the file path to the ASDF file.
When converting ASDF files into IDL variables, the following rules are used:
||IDL Variable Type
||Optional global TAG property
Optional ANCHOR, TAG properties
||Mapping of keys with !NULL values
||Array dimensions will be reversed
|Sequence of mixed types
Optional ANCHOR, TAG properties
|Sequence of same types1
Boolean, LONG64, DOUBLE, DCOMPLEX
||Sequence of ASDF_Maps
|Scalar value with unknown tag3
||TAG and VALUE properties
|Scalar value with an anchor2
ANCHOR, VALUE properties, optional TAG
|~, null, Null, NULL
false, False, FALSE, true, True, TRUE
|Integer from –263 to 263–1
|Integers larger than +/–263
|!!binary with base64
!!python/complex or !core/complex-1.0.0
1A sequence with both integers and floating-point values will be returned as an IDL array of type DOUBLE.
2A YAML scalar with an anchor will be returned as a YAML_Value object. The VALUE property will contain the scalar value as a string, and will not be converted to one of the other scalar types.
3A YAML scalar with an unknown tag will be returned as a YAML_Value object. The VALUE property will contain the scalar value as a string, and will not be converted to one of the other scalar types.
See YAML_PARSE for information on IDL's conformance to the YAML standard.
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
Parse the file and access the data using array indexing:
IDL> file = ASDF_Parse('calibration.asdf')
IDL> help, file['Calibration']
<Expression> YAML_MAP <ID=209 NELEMENTS=4>
IDL> help, file['Calibration', 'title']
<Expression> STRING = 'Calibration Data'
IDL> help, file['Calibration', 'calibration']
<Expression> ASDF_NDARRAY <ID=217> float32  inline
IDL> help, file['Calibration', 'calibration', 'data']
<Expression> DOUBLE = Array
The calibration data only has 10 elements, so it was immediately read in during ASDF_Parse.
The Image data is stored in an internal data block, and is automatically read from the file when the actual array is accessed:
IDL> help, file['Image', 'data']
<Expression> BYTE = Array[3, 100, 50]
ASDF_FILE, ASDF_NDARRAY, ASDF_WRITE