pninexus.h5cpp.attribute

AttributeManager

class pninexus.h5cpp.attribute.AttributeManager

Every instance of Node has an instance of AttributeManager attached to it which provides access to the attributes attached to the particular node.

size

Read-only property returning the number of attributs of a node.

Returns

number of attributes

Return type

integer

create()

Creates a new attribute on the node to which the manager instance is attached.

Parameters
  • name (str) – the name of the new attribute

  • type (pni.io.h5cpp.datatype.Datatype) – a datatype instance

  • space (pni.io.h5cpp.dataspace.Dataspace) – the dataspace for the attribute

  • pni.io.h5cpp.property.AttributeCreationList – an optional attribute creation property list

Returns

a new instance of Attribute

Return type

pni.io.h5cpp.attribute.Attribute

Raises

RuntimeError – in case of an error

remove()

Removes an attribute from a node. Raises RuntimeError if the node does not exist.

Parameters

index (object) – the index of the node to remove. This can either be a numerical index or the name of the attribute.

Raises

RuntimeError – in case of a failure

__len__()

The attribute manager supports the __len__ protocol so one can use the len() function to determine the number of attributes attached to a node.

root = file.root()
print("Number of attributes: {}".format(len(root.attributes)))
exists()

Takes the name of an attribute as its sole argument and returns True if an attribute of that name exists, otherwise it returns False.

Parameters

name (str) – the name of an attribute

Returns

True if the attribute exists, False otherwise

Return type

bool

__getitem__()

Reads data from an attribute and allows slicing.

data = dataset.attributes["tensor"][1,2,2]

A numpy array is returned.

Parameters

index (slice) – the selection for the data to read

Returns

numpy array with the data

Return type

numpy.ndarray

Attribute

class pninexus.h5cpp.attribute.Attribute
a = dataset.attribtues.create()
a.write("m")

Attributes can be obtained with

a = dataset.attributes["temperature"]
print(a.read())
dataspace

read-only property returning the dataspace for the attribute

datatype

read-only property returning the HDF5 datatype of the attribute

name

read-only property returning the name of the attribute as an instance of str

is_valid

read-only property returning True if the attribute is a valid HDF5 object, and False otherwise

read-only property returning a link to the parent node of the attribute as an instance of pni.io.h5cpp.node.Link.

close()

closes the current attribute

read()

Reads attribute data and returns it as an instance of numpy.ndarray.

write(data)

Takes an instance of a Python object and writes it to the attribute.