SerializationContext
- class asdf.extension.SerializationContext(version, extension_manager, url, blocks)[source]
Bases:
object
Container for parameters of the current (de)serialization.
This class should not be instantiated directly and instead will be created by the AsdfFile object and provided to extension classes (like Converters) via method arguments.
Attributes Summary
Get the ExtensionManager for enabled extensions.
The URL (if any) of the file being read or written.
Get the ASDF Standard version.
Methods Summary
assign_object
(obj)find_available_block_index
(data_callback[, key])Find the index of an available ASDF block to write data.
Generate a BlockKey used for Converters that wish to use multiple blocks
Get the compression type for the given array data.
get_array_save_base
(arr)Returns the
save_base
option forarr
.get_array_storage
(arr)Get the block type for the given array data.
get_block_data_callback
(index[, key])Generate a callable that when called will read data from an ASDF block at the provided index.
set_array_compression
(arr, compression, ...)Set the compression to use for the given array data.
set_array_save_base
(arr, save_base)Set the
save_base
option forarr
.set_array_storage
(arr, array_storage)Set the block type to use for the given array data.
Attributes Documentation
- extension_manager
Get the ExtensionManager for enabled extensions.
- Returns:
- asdf.extension.ExtensionManager
- url
The URL (if any) of the file being read or written.
Used to compute relative locations of external files referenced by this ASDF file. The URL will not exist in some cases (e.g. when the file is written to an
io.BytesIO
).- Returns:
- str or None
- version
Get the ASDF Standard version.
- Returns:
- str
Methods Documentation
- find_available_block_index(data_callback, key=None)[source]
Find the index of an available ASDF block to write data.
This is typically used inside asdf.extension.Converter.to_yaml_tree.
- Parameters:
- data_callback: callable
Callable that when called will return data (ndarray) that will be written to a block.
- keyBlockKey, optional
BlockKey generated using self.generate_block_key. Only needed for a Converter that uses multiple blocks.
- Returns:
- block_index: int
Index of the ASDF block where data returned from data_callback will be written.
- generate_block_key()[source]
Generate a BlockKey used for Converters that wish to use multiple blocks
- Returns:
- keyBlockKey
A hashable object that will be associated with the serialized/deserialized object and can be used to access multiple blocks within a Converter
- get_array_compression(arr)[source]
Get the compression type for the given array data.
- Parameters:
- arrnumpy.ndarray
- Returns:
- compressionstr or None
- get_array_save_base(arr)[source]
Returns the
save_base
option forarr
. Whenarr
is written to a file, ifsave_base
isTrue
the base array forarr
will be saved.- Parameters:
- arrnumpy.ndarray
- Returns:
- save_basebool
- get_array_storage(arr)[source]
Get the block type for the given array data.
- Parameters:
- arrnumpy.ndarray
- get_block_data_callback(index, key=None)[source]
Generate a callable that when called will read data from an ASDF block at the provided index.
- Parameters:
- indexint
Index of ASDF block.
- keyBlockKey, optional
BlockKey generated using self.generate_block_key. Only needed for a Converter that uses multiple blocks.
- Returns:
- callbackcallable
A callable that when called (with no arguments) returns the block data as a one dimensional array of uint8
- set_array_compression(arr, compression, **compression_kwargs)[source]
Set the compression to use for the given array data.
- Parameters:
- arrnumpy.ndarray
The array to set. If multiple views of the array are in the tree, only the most recent compression setting will be used, since all views share a single block.
- compressionstr or None
Must be one of:
''
orNone
: no compressionzlib
: Use zlib compressionbzp2
: Use bzip2 compressionlz4
: Use lz4 compressioninput
: Use the same compression as in the file read. If there is no prior file, acts as None.
- set_array_save_base(arr, save_base)[source]
Set the
save_base
option forarr
. Whenarr
is written to a file, ifsave_base
isTrue
the base array forarr
will be saved.Note that similar to other array options this setting is linked to the base array if
arr
is a view.- Parameters:
- arrnumpy.ndarray
- save_basebool or None
if
None
thedefault_array_save_base
value from asdf config will be used
- set_array_storage(arr, array_storage)[source]
Set the block type to use for the given array data.
- Parameters:
- arrnumpy.ndarray
The array to set. If multiple views of the array are in the tree, only the most recent block type setting will be used, since all views share a single block.
- array_storagestr
Must be one of:
internal
: The default. The array data will be stored in a binary block in the same ASDF file.external
: Store the data in a binary block in a separate ASDF file.inline
: Store the data as YAML inline in the tree.