ExternalArrayReference

class asdf.ExternalArrayReference(fileuri, target, dtype, shape)[source]

Bases: asdf.asdftypes.AsdfType

Store a reference to an array in an external File.

This class is a simple way of referring to an array in another file. It provides no way to resolve these references, that is left to the user. It also performs no checking to see if any of the arguments are correct. e.g. if the file exits.

Parameters:

fileuri: `str`

The path to the path to be referenced. Can be relative to the file containing the reference.

target: `object`

Some internal target to the data in the file. Examples may include a HDU index, a HDF path or an asdf fragment.

dtype: `str`

The (numpy) dtype of the contained array.

shape: `tuple`

The shape of the array to be loaded.

Examples

>>> import asdf
>>> ref = asdf.ExternalArrayReference("myfitsfile.fits", 1, "float64", (100, 100))
>>> tree = {'reference': ref}
>>> with asdf.AsdfFile(tree) as ff:
...     ff.write_to("test.asdf")

Attributes Summary

has_required_modules
name
supported_versions
types
version
yaml_tag

Methods Summary

from_tree(tree, ctx) Converts basic types representing YAML trees into custom types.
to_tree(data, ctx) Converts instances of custom types into YAML representations.

Attributes Documentation

has_required_modules = True
name = 'core/externalarray'
supported_versions = []
types = []
version = Version('1.0.0')
yaml_tag = 'tag:stsci.edu:asdf/core/externalarray-1.0.0'

Methods Documentation

classmethod from_tree(tree, ctx)[source]

Converts basic types representing YAML trees into custom types.

This method should be overridden by custom extension classes in order to define how custom types are deserialized from the YAML representation back into their original types. The method will return an instance of the original custom type.

This method is called as part of the process of reading an ASDF file in order to construct an AsdfFile object. Whenever a YAML subtree is encountered that has a tag that corresponds to the yaml_tag property of this class, this method will be used to deserialize that tree back into an instance of the original custom type.

Parameters:

tree : object representing YAML tree

An instance of a basic Python type (possibly nested) that corresponds to a YAML subtree.

ctx : AsdfFile

An instance of the AsdfFile object that is being constructed.

Returns:

An instance of the custom type represented by this extension class.

classmethod to_tree(data, ctx)[source]

Converts instances of custom types into YAML representations.

This method should be overridden by custom extension classes in order to define how custom types are serialized into YAML. The method must return a single Python object corresponding to one of the basic YAML types (dict, list, str, or number). However, the types can be nested and combined in order to represent more complex custom types.

This method is called as part of the process of writing an AsdfFile object. Whenever a custom type (or a subclass of that type) that is listed in the types attribute of this class is encountered, this method will be used to serialize that type.

The name to_tree refers to the act of converting a custom type into part of a YAML object tree.

Parameters:

node : object

Instance of a custom type to be serialized. Will be an instance (or an instance of a subclass) of one of the types listed in the types attribute of this class.

ctx : AsdfFile

An instance of the AsdfFile object that is being written out.

Returns:

A basic YAML type (dict, list, str, int, float, or

complex) representing the properties of the custom type to be serialized. These types can be nested in order to represent more complex custom types.