nanshe.io.hdf5.record module¶
The module record
provides the equivalent of a logger for array data.
Overview¶
Applying the decorator static_subgrouping_array_recorders
with the names of
desired recorders as strings or keyword arguments with a given recorder
instance initializes the recorders
attribute, which contains each recorder
as a dictionary would. Results are stored under a group named after decorated
function. Nested function calls can be paralleled by nesting results within
groups. All that is required is that the recorder be assigned from outer scope
to inner (see example below).
@static_subgrouping_array_recorders("r")
def a(x):
a.r = x
return x * x.T
@static_subgrouping_array_recorders("r")
def b(x, y):
a.r = b.r
return a(x + y)
All recorders default to an instance of EmptyArrayRecorder
unless otherwise
specified. All operations work on them exactly the same, but no recording
occurs. This guarantees that code using recorders will not break if they don’t
have them. A similar strategy can be applied for classes and their methods by
using class_static_array_debug_recorder
.
Todo
Complete documentation with more examples.
API¶
-
nanshe.io.hdf5.record.
class_static_array_debug_recorder
(*args, **kwargs)[source]¶ Creates a decorator that adds a static variable recorders that contains the variable array_debug_recorder to the function it decorates. By default, array_debug_recorder is set to an EmptyArrayRecorder instance. Also, on assignment it automatically creates a subgroup with the same name as the function.
Parameters: a_class (class) – All variables to be named (set to EmptyArrayRecorder()). Returns: - A decorator that adds the static variable
- array_debug_recorder to the given function.
Return type: (class)
-
nanshe.io.hdf5.record.
class_static_subgrouping_array_recorders
(*args, **kwargs)[source]¶ Creates a decorator that adds a static variable, recorders, that holds as many recorders as are supplied.
Parameters: args (tuple of strs) – All variables to be named (set to EmptyArrayRecorder()). Keyword Arguments: kwargs (dict of strs and ArrayRecorders) – All variables to be named with values of type ArrayRecorder. Returns: - A decorator that adds
- the static variable, recorders, to the given function.
Return type: (callable)
-
nanshe.io.hdf5.record.
generate_HDF5_array_recorder
(*args, **kwargs)[source]¶ Generates a function used for writing arrays (structured or otherwise) to a group in an HDF5 file.
Parameters: - hdf5_handle – The HDF5 file group to place the debug contents into.
- group_name – The name of the group within hdf5_handle to save the contents to. (If set to the empty string, data will be saved to hdf5_handle directly)
- enable – Whether to generate a real recorder or a fake one.
- overwrite_group – Whether to overwrite the group where data is stored.
- recorder_constructor – Type of recorder to use if enable is True.
- **kwargs – Other arguments to pass through to the recorder_constructor (won’t pass through if enable is false).
Returns: - A function, which will take a given array
name and value and write them out.
Return type: ArrayRecorder
-
nanshe.io.hdf5.record.
static_array_debug_recorder
(*args, **kwargs)[source]¶ Creates a decorator that adds a static variable recorders that contains the variable array_debug_recorder to the function it decorates. By default, array_debug_recorder is set to an EmptyArrayRecorder instance. Also, on assignment it automatically creates a subgroup with the same name as the function.
Parameters: callable (callable) – All variables to be named (set to EmptyArrayRecorder()). Returns: - A decorator that adds the static variable
- array_debug_recorder to the given function.
Return type: (callable)
-
nanshe.io.hdf5.record.
static_subgrouping_array_recorders
(*args, **kwargs)[source]¶ Creates a decorator that adds a static variable, recorders, that holds as many recorders as are supplied.
Parameters: args (tuple of strs) – All variables to be named (set to EmptyArrayRecorder()). Keyword Arguments: kwargs (dict of strs and ArrayRecorders) – All variables to be named with values of type ArrayRecorder. Returns: - A decorator that adds
- the static variable, recorders, to the given function.
Return type: (callable)