dpemu.nodes package

Submodules

dpemu.nodes.array module

class dpemu.nodes.array.Array(reshape=None)[source]

Bases: dpemu.nodes.node.LeafNode

An Array node represents a data array of any dimension (>= 0).

One or more filters (error sources) can be added to the node. The filters are applied in the order in which they are added.

You can optionally provide the constructor with a reshape parameter. In that case the filters attached to the node operate on data reshaped to the desired shape. The final shape of the data is unaffected.

Constructor Args:
reshape (tuple, optional): The data shape required by the

node’s filters if different from the actual shape of the data

apply_filters(node_data, random_state, named_dims)[source]

Apply filters to data contained in this array.

Parameters
  • node_data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of numpy.random.RandomState.

  • named_dims (dict) – Named dimensions.

process(data, random_state, index_tuple=(), named_dims={})[source]

Apply all filters in this node.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of numpy.random.RandomState

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

dpemu.nodes.node module

class dpemu.nodes.node.LeafNode[source]

Bases: dpemu.nodes.node.Node

LeafNode is the superclass for all leaf node classes of the error generation tree.

apply_filters(node_data, random_state, named_dims)[source]
class dpemu.nodes.node.Node(children)[source]

Bases: abc.ABC

Node is the superclass for all node classes of the error generation tree.

__init__(children)[source]
Parameters

children (list) – A list of all child nodes of the node.

addfilter(error_filter)[source]

Attach a filter (error source) to the node.

Parameters

error_filter (object) – A pre-existing or user-specified filter

generate_error(data, error_params, random_state=numpy.random.RandomState)[source]

Returns the data with the desired errors introduced.

The original data object is not modified. The error parameters must be provided as a dictionary whose keys are the parameter identifiers (given as parameters to the filters) and whose values are the desired parameter values.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • error_params (dict) – A dictionary containing the parameters for error generation.

  • random_state (mtrand.RandomState, optional) – An instance of numpy.random.RandomState. Defaults to np.random.RandomState(42).

Returns

Errorified data.

Return type

numpy.ndarray

get_parametrized_tree(error_params)[source]

Returns an error generation tree with desired parameter values of the filters.

Parameters

error_params (dict) – A dictionary containing the parameters for error generation.

Returns

A root node of the error generation tree.

Return type

Node

abstract process(data, random_state, index_tuple=(), named_dims={})[source]

Processes the given data by passing it recursively in the error generation tree and applying filters to it.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of mtrand.RandomState to ensure repeatability.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

set_error_params(params_dict)[source]

Set error parameters for the filter.

Parameters

params_dict (dict) – A Python dictionary.

dpemu.nodes.node.assign(data_root, index_tuple, value)[source]

Makes the assignment data_root[index_tuple] = value.

dpemu.nodes.node.get_node_data(data, index_tuple, make_array=True)[source]

Returns some desired subset of the data to the node as well as additional information about its structure.

Parameters
  • data (obj) – The original data the node received.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • make_array (bool, optional) – If True, the data array is typecasted to numpy.ndarray. Defaults to True.

Returns

Data as a numpy array and bools telling if the data is

a list, a scalar or a tuple.

Return type

numpy.ndarray, bool, bool, bool

dpemu.nodes.series module

class dpemu.nodes.series.Series(child, dim_name=None)[source]

Bases: dpemu.nodes.node.Node

The Series node represents the leftmost dimension of any unit of data passed to it.

The Series node is given a child node and the data is passed to it after “removing” the leftmost dimension.

__init__(child, dim_name=None)[source]
Parameters
  • child (Node) – The only child node of the Series node.

  • dim_name (str, optional) – A named dimension with a given name may be given to the node, which it will then pass to its child node. Defaults to None.

process(data, random_state, index_tuple=(), named_dims={})[source]

Processes the given data by passing it recursively in the error generation tree and applying filters to it.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of mtrand.RandomState to ensure repeatability.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

class dpemu.nodes.series.TupleSeries(children, dim_name=None)[source]

Bases: dpemu.nodes.node.Node

The TupleSeries node represents a tuple where the leftmost dimensions of the tuple elements are in some sense “the same”.

The TupleSeries node is given a list of child nodes and the i-th element of data is passed to i-th child and its leftmost dimension is “removed”.

__init__(children, dim_name=None)[source]
Parameters
  • children (list) – List of child nodes of the TupleSeries node.

  • dim_name (str, optional) – A named dimension with a given name may be given to the node, which it will then pass to its child node. Defaults to None.

process(data, random_state, index_tuple=(), named_dims={})[source]

Processes the given data by passing it recursively in the error generation tree and applying filters to it.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of mtrand.RandomState to ensure repeatability.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

dpemu.nodes.tuple module

class dpemu.nodes.tuple.Tuple[source]

Bases: dpemu.nodes.node.LeafNode

The Tuple is a leaf node which represents data whose type is a tuple.

The filters on this node are applied to all elements of the tuple.

process(data, random_state, index_tuple=(), named_dims={})[source]

Processes the given data by passing it recursively in the error generation tree and applying filters to it.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of mtrand.RandomState to ensure repeatability.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

Module contents

class dpemu.nodes.Node(children)[source]

Bases: abc.ABC

Node is the superclass for all node classes of the error generation tree.

__init__(children)[source]
Parameters

children (list) – A list of all child nodes of the node.

addfilter(error_filter)[source]

Attach a filter (error source) to the node.

Parameters

error_filter (object) – A pre-existing or user-specified filter

generate_error(data, error_params, random_state=numpy.random.RandomState)[source]

Returns the data with the desired errors introduced.

The original data object is not modified. The error parameters must be provided as a dictionary whose keys are the parameter identifiers (given as parameters to the filters) and whose values are the desired parameter values.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • error_params (dict) – A dictionary containing the parameters for error generation.

  • random_state (mtrand.RandomState, optional) – An instance of numpy.random.RandomState. Defaults to np.random.RandomState(42).

Returns

Errorified data.

Return type

numpy.ndarray

get_parametrized_tree(error_params)[source]

Returns an error generation tree with desired parameter values of the filters.

Parameters

error_params (dict) – A dictionary containing the parameters for error generation.

Returns

A root node of the error generation tree.

Return type

Node

abstract process(data, random_state, index_tuple=(), named_dims={})[source]

Processes the given data by passing it recursively in the error generation tree and applying filters to it.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of mtrand.RandomState to ensure repeatability.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

set_error_params(params_dict)[source]

Set error parameters for the filter.

Parameters

params_dict (dict) – A Python dictionary.

class dpemu.nodes.LeafNode[source]

Bases: dpemu.nodes.node.Node

LeafNode is the superclass for all leaf node classes of the error generation tree.

apply_filters(node_data, random_state, named_dims)[source]
class dpemu.nodes.Array(reshape=None)[source]

Bases: dpemu.nodes.node.LeafNode

An Array node represents a data array of any dimension (>= 0).

One or more filters (error sources) can be added to the node. The filters are applied in the order in which they are added.

You can optionally provide the constructor with a reshape parameter. In that case the filters attached to the node operate on data reshaped to the desired shape. The final shape of the data is unaffected.

Constructor Args:
reshape (tuple, optional): The data shape required by the

node’s filters if different from the actual shape of the data

apply_filters(node_data, random_state, named_dims)[source]

Apply filters to data contained in this array.

Parameters
  • node_data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of numpy.random.RandomState.

  • named_dims (dict) – Named dimensions.

process(data, random_state, index_tuple=(), named_dims={})[source]

Apply all filters in this node.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of numpy.random.RandomState

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

class dpemu.nodes.Series(child, dim_name=None)[source]

Bases: dpemu.nodes.node.Node

The Series node represents the leftmost dimension of any unit of data passed to it.

The Series node is given a child node and the data is passed to it after “removing” the leftmost dimension.

__init__(child, dim_name=None)[source]
Parameters
  • child (Node) – The only child node of the Series node.

  • dim_name (str, optional) – A named dimension with a given name may be given to the node, which it will then pass to its child node. Defaults to None.

process(data, random_state, index_tuple=(), named_dims={})[source]

Processes the given data by passing it recursively in the error generation tree and applying filters to it.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of mtrand.RandomState to ensure repeatability.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

class dpemu.nodes.TupleSeries(children, dim_name=None)[source]

Bases: dpemu.nodes.node.Node

The TupleSeries node represents a tuple where the leftmost dimensions of the tuple elements are in some sense “the same”.

The TupleSeries node is given a list of child nodes and the i-th element of data is passed to i-th child and its leftmost dimension is “removed”.

__init__(children, dim_name=None)[source]
Parameters
  • children (list) – List of child nodes of the TupleSeries node.

  • dim_name (str, optional) – A named dimension with a given name may be given to the node, which it will then pass to its child node. Defaults to None.

process(data, random_state, index_tuple=(), named_dims={})[source]

Processes the given data by passing it recursively in the error generation tree and applying filters to it.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of mtrand.RandomState to ensure repeatability.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.

class dpemu.nodes.Tuple[source]

Bases: dpemu.nodes.node.LeafNode

The Tuple is a leaf node which represents data whose type is a tuple.

The filters on this node are applied to all elements of the tuple.

process(data, random_state, index_tuple=(), named_dims={})[source]

Processes the given data by passing it recursively in the error generation tree and applying filters to it.

Parameters
  • data (numpy.ndarray) – Data to be modified as a Numpy array.

  • random_state (mtrand.RandomState) – An instance of mtrand.RandomState to ensure repeatability.

  • index_tuple (tuple, optional) – The index of the node. Defaults to ().

  • named_dims (dict, optional) – Named dimensions. Defaults to {}.