NDArrayType

class asdf.tags.core.NDArrayType(source, shape, dtype, offset, strides, order, mask, asdffile)[source]

Bases: AsdfType

Attributes Summary

block

dtype

has_required_modules

name

shape

supported_versions

types

validators

version

yaml_tag

Methods Summary

assert_allclose(old, new)

assert_equal(old, new)

copy_to_new_asdf(node, asdffile)

from_tree(node, ctx)

Converts basic types representing YAML trees into custom types.

get_actual_shape(shape, strides, dtype, ...)

Get the actual shape of an array, by computing it against the block_size if it contains a *.

reserve_blocks(data, ctx)

to_tree(data, ctx)

Converts instances of custom types into YAML representations.

Attributes Documentation

block
dtype
has_required_modules = True
name = 'core/ndarray'
shape
supported_versions = [AsdfVersion('1.0.0'), AsdfVersion('1.1.0')]
types = [<class 'numpy.ndarray'>, <class 'numpy.ma.core.MaskedArray'>]
validators = {'datatype': <function validate_datatype>, 'max_ndim': <function validate_max_ndim>, 'ndim': <function validate_ndim>}
version = AsdfVersion('1.0.0')
yaml_tag = 'tag:stsci.edu:asdf/core/ndarray-1.0.0'

Methods Documentation

classmethod assert_allclose(old, new)[source]
classmethod assert_equal(old, new)[source]
classmethod copy_to_new_asdf(node, asdffile)[source]
classmethod from_tree(node, 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. Typically the method will return an instance of the original custom type. It is also permitted to return a generator, which yields a partially constructed result, then completes construction once the generator is drained. This is useful when constructing objects that contain reference cycles.

This method is called as part of the process of reading an ASDF file in order to construct an asdf.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
treeobject representing YAML tree

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

ctxasdf.AsdfFile

An instance of the asdf.AsdfFile object that is being constructed.

Returns
An instance of the custom type represented by this extension class,
or a generator that yields that instance.
get_actual_shape(shape, strides, dtype, block_size)[source]

Get the actual shape of an array, by computing it against the block_size if it contains a *.

classmethod reserve_blocks(data, ctx)[source]
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 asdf.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
nodeobject

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.

ctxasdf.AsdfFile

An instance of the asdf.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.