modelrunner.storage.group module

class StorageGroup(storage, loc=None)[source]

Bases: object

refers to a group within a storage

Parameters:
  • storage (StorageBase or StorageGroup) – The storage where the group is defined. If this is a StorageGroup itself, loc is interpreted relative to that group

  • loc (str or list of str) – Denotes the location (path) of the group within the storage

property attrs: Dict[str, Any]

the attributes associated with this group

Type:

dict

create_dynamic_array(loc, *, arr=None, shape=None, dtype=<class 'float'>, record_array=False, attrs=None, cls=None)[source]

creates a dynamic array of flexible size

Parameters:
  • loc (str or list of str) – The location where the dynamic array is created

  • shape (tuple of int) – The shape of the individual arrays. A singular axis is prepended to the shape, which can then be extended subsequently.

  • dtype (DTypeLike) – The data type of the array to be written

  • record_array (bool) – Flag indicating whether the array is of type recarray

  • attrs (dict, optional) – Attributes stored with the array

  • cls (type) – A class associated with this array

  • arr (np.ndarray | None) –

create_group(loc, *, attrs=None, cls=None)[source]

create a new group at a particular location

Parameters:
  • loc (str or list of str) – The location where the group will be created

  • attrs (dict, optional) – Attributes stored with the group

  • cls (type) – A class associated with this group

Returns:

The reference of the new group

Return type:

StorageGroup

extend_dynamic_array(loc, data)[source]

extend a dynamic array previously created

Parameters:
get(loc, default=None)[source]
Parameters:
Return type:

Any

get_class(loc=None)[source]

get the class associated with a particular location

Class information can be written using the cls attribute of write_array, write_object, and similar functions.

Parameters:

loc (str or list of str) – The location where the class information is read from

Return type:

type | None

Retruns: the class associated with the lcoation

is_group(loc=None)[source]

determine whether the location is a group

Parameters:

loc (sequence of str) – A list of strings determining the location in the storage

Returns:

True if the loation is a group

Return type:

bool

items()[source]

iterate over stored items, yielding the location and item of each

Return type:

Iterator[tuple[str, Any]]

keys()[source]

return name of all stored items in this group

Return type:

Collection[str]

open_group(loc)[source]

open an existing group at a particular location

Parameters:

loc (str or list of str) – The location where the group will be opened

Returns:

The reference to the group

Return type:

StorageGroup

property parent: StorageGroup

Parent group

Raises:

RuntimeError – If current group is root group

Type:

StorageGroup

read_array(loc, *, out=None, index=None)[source]

read an array from a particular location

Parameters:
  • loc (str or list of str) – The location where the array is created

  • out (array, optional) – An array to which the results are written

  • index (int, optional) – An index denoting the subarray that will be read

Returns:

An array containing the data. Identical to out if specified.

Return type:

ndarray

read_attrs(loc=None)[source]

read attributes associated with a particular location

Parameters:

loc (str or list of str) – The location in the storage where the attributes are read

Returns:

A copy of the attributes at this location

Return type:

dict

read_item(loc, *, use_class=True)[source]

read an item from a particular location

Parameters:
  • loc (str or list of str) – The location where the item is read from

  • use_class (bool) – If True, looks for class information in the attributes and evokes a potentially registered hook to instantiate the associated object. If False, only the current data or object is returned.

Returns:

The reconstructed python object

Return type:

Any

read_object(loc)[source]

read an object from a particular location

Parameters:

loc (str or list of str) – The location where the object is created

Returns:

The object that has been read from the storage

Return type:

Any

tree()[source]

print the hierarchical storage as a tree structure

Return type:

None

write_array(loc, arr, *, attrs=None, cls=None)[source]

write an array to a particular location

Parameters:
  • loc (str or list of str) – The location where the array is read

  • arr (ndarray) – The array that will be written

  • attrs (dict, optional) – Attributes stored with the array

  • cls (type) – A class associated with this array

write_attrs(loc=None, attrs=None)[source]

write attributes to a particular location

Parameters:
  • loc (str or list of str) – The location in the storage where the attributes are written

  • attrs (dict) – The attributes to be added to this location

Return type:

None

write_item(loc, item, *, attrs=None, use_class=True)[source]

write an item to a particular location

Parameters:
  • loc (sequence of str) – The location where the item is written to

  • item (Any) – The item that will be written

  • attrs (dict, optional) – Attributes stored with the object

  • use_class (bool) – If True, looks for class information in the attributes and evokes a potentially registered hook to instantiate the associated object. If False, only the current data or object is returned.

Return type:

None

write_object(loc, obj, *, attrs=None, cls=None)[source]

write an object to a particular location

Parameters:
  • loc (str or list of str) – The location where the object is read

  • obj (Any) – The object that will be written

  • attrs (dict, optional) – Attributes stored with the object

  • cls (type) – A class associated with this object