Stream

class asdf.Stream(shape, dtype, strides=None)[source]

Bases: asdf.tags.core.ndarray.NDArrayType

Used to put a streamed array into the tree.

Examples

Save a double-precision array with 1024 columns, one row at a time:

>>> from asdf import AsdfFile, Stream
>>> import numpy as np
>>> ff = AsdfFile()
>>> ff.tree['streamed'] = Stream([1024], np.float64)
>>> with open('test.asdf', 'wb') as fd:
...     ff.write_to(fd)
...     for i in range(200):
...         nbytes = fd.write(
...                      np.array([i] * 1024, np.float64).tostring())

Attributes Summary

block
dtype
handle_dynamic_subclasses
has_required_modules
name
organization
requires
shape
standard
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(data, ctx)
from_tree_tagged(tree, ctx) Converts from tagged tree into custom type.
get_actual_shape(shape, strides, dtype, …) Get the actual shape of an array, by computing it against the block_size if it contains a *.
incompatible_version(version) Indicates if given version is known to be incompatible with this type.
make_yaml_tag(name[, versioned]) Given the name of a type, returns a string representing its YAML tag.
names() Returns the name(s) represented by this tag type as a list.
reserve_blocks(data, ctx)
tag_base() Returns the base of the YAML tag for types represented by this class.
to_tree(data, ctx)
to_tree_tagged(node, ctx) Converts instances of custom types into tagged objects.

Attributes Documentation

block
dtype
handle_dynamic_subclasses = False
has_required_modules = True
name = None
organization = 'stsci.edu'
requires = []
shape
standard = 'asdf'
supported_versions = []
types = []
validators = {'datatype': <function validate_datatype at 0x7f74b5cb6b70>, 'max_ndim': <function validate_max_ndim at 0x7f74b5cb6ae8>, 'ndim': <function validate_ndim at 0x7f74b5cb6a60>}
version = Version('1.0.0')
yaml_tag = 'tag:stsci.edu:asdf/core/ndarray-1.0.0'

Methods Documentation

assert_allclose(old, new)
assert_equal(old, new)
copy_to_new_asdf(node, asdffile)
classmethod from_tree(data, ctx)[source]
from_tree_tagged(tree, ctx)

Converts from tagged tree into custom type.

It is more common for extension classes to override from_tree instead of this method. This method should only be overridden if it is necessary to access the _tag property of the Tagged object directly.

Parameters:

tree : asdf.tagged.Tagged object representing YAML tree

ctx : AsdfFile

An instance of the AsdfFile object that is being constructed.

Returns:

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

get_actual_shape(shape, strides, dtype, block_size)

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

incompatible_version(version)

Indicates if given version is known to be incompatible with this type.

If this tag class explicitly identifies compatible versions then this checks whether a given version is compatible or not (see supported_versions). Otherwise, all versions are assumed to be compatible.

Child classes can override this method to affect how version compatiblity for this type is determined.

Parameters:

version : str or AsdfVersion

The version to test for compatibility.

make_yaml_tag(name, versioned=True)

Given the name of a type, returns a string representing its YAML tag.

Parameters:

name : str

The name of the type. In most cases this will correspond to the name attribute of the tag type. However, it is passed as a parameter since some tag types represent multiple custom types.

versioned : bool

If True, the tag will be versioned. Otherwise, a YAML tag without a version will be returned.

Returns:

str representing the YAML tag

names()

Returns the name(s) represented by this tag type as a list.

While some tag types represent only a single custom type, others represent multiple types. In the latter case, the name attribute of the extension is actually a list, not simply a string. This method normalizes the value of name by returning a list in all cases.

Returns:list of names represented by this tag type
classmethod reserve_blocks(data, ctx)[source]
tag_base()

Returns the base of the YAML tag for types represented by this class.

This method returns the portion of the tag that represents the standard and the organization of any type represented by this class.

Returns:str representing the base of the YAML tag
classmethod to_tree(data, ctx)[source]
to_tree_tagged(node, ctx)

Converts instances of custom types into tagged objects.

It is more common for custom tag types to override to_tree instead of this method. This method should only be overridden if it is necessary to modify the YAML tag that will be used to tag this object.

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:

An instance of asdf.tagged.Tagged.