Utilities

util Module

Utility functions for nsdf.

nsdf.util.find(a, predicate, chunk_size=1024)[source]

Find the indices of array elements that match the predicate.

Parameters:
  • a (array_like) – Input data, must be 1D.
  • predicate (function) – A function which operates on sections of the given array, returning element-wise True or False for each data value.
  • chunk_size (integer) – The length of the chunks to use when searching for matching indices. For high probability predicates, a smaller number will make this function quicker, similarly choose a larger number for low probabilities.
Returns:

index_generator – A generator of (indices, data value) tuples which make the predicate True.

Return type:

generator

See also

where(), nonzero()

Notes

This function is best used for finding the first, or first few, data values which match the predicate.

Examples

>>> a = np.sin(np.linspace(0, np.pi, 200))
>>> result = find(a, lambda arr: arr > 0.9)
>>> next(result)
((71, ), 0.900479032457)
>>> np.where(a > 0.9)[0][0]
71

Author:

Phil Elson (https://github.com/pelson). Code taken from numpy issue tracker: https://github.com/numpy/numpy/issues/2269# on Wed Jul 30 11:20:23 IST 2014
nsdf.util.node_finder(container_list, match_fn)[source]

Return a function that can be passed to h5py.Group.visititem to collect all nodes satisfying match_fn collect in container_list

nsdf.util.printtree(root, vchar='|', hchar='__', vcount=1, depth=0, prefix='', is_last=False)[source]

Pretty-print an HDF5 tree.

Parameters:
  • root (h5py.Group) – path of the root element of the HDF5 subtree to be printed.
  • vchar (str) – the character printed to indicate vertical continuation of a parent child relationship.
  • hchar (str) – the character printed just before the node name.
  • vcount (int) – determines how many lines will be printed between two successive nodes.
  • depth (int) – for internal use - should not be explicitly passed.
  • prefix (str) – for internal use - should not be explicitly passed.
  • is_last (bool) – for internal use - should not be explicitly passed.