larray.Session.summary

Session.summary(self, template=None)[source]

Returns a summary of the content of the session.

Parameters:
template: dict {object type: str} or dict {object type: func}

Template describing how items and metadata are summarized. For each object type, it is possible to provide either a string template or a function taking the the key and value of a session item as parameters and returning a string (see examples). A string template contains specific arguments written inside brackets {}. Available arguments are:

  • for groups: ‘key’, ‘name’, ‘axis_name’, ‘labels’ and ‘length’,
  • for axes: ‘key’, ‘name’, ‘labels’ and ‘length’,
  • for arrays: ‘key’, ‘axes_names’, ‘shape’, ‘dtype’ and ‘title’,
  • for session metadata: ‘key’, ‘value’,
  • for all other types: ‘key’, ‘value’.
Returns:
str

Short representation of the content of the session.

Examples

>>> axis1 = Axis("a=a0..a2")
>>> group1 = axis1['a0,a1'] >> 'a01'
>>> arr1 = ndtest((2, 2), dtype=np.int64, meta=[('title', 'array 1')])
>>> arr2 = ndtest(4, dtype=np.int64, meta=[('title', 'array 2')])
>>> arr3 = ndtest((3, 2), dtype=np.int64, meta=[('title', 'array 3')])
>>> s = Session([('axis1', axis1), ('group1', group1), ('arr1', arr1), ('arr2', arr2), ('arr3', arr3)])
>>> s.meta.title = 'my title'
>>> s.meta.author = 'John Smith'

Default template

>>> print(s.summary())  # doctest: +NORMALIZE_WHITESPACE
Metadata:
    title: my title
    author: John Smith
axis1: a ['a0' 'a1' 'a2'] (3)
group1: a['a0', 'a1'] >> a01 (2)
arr1: a, b (2 x 2) [int64]
arr2: a (4) [int64]
arr3: a, b (3 x 2) [int64]

Using a specific template

>>> def print_array(key, array):
...     axes_names = ', '.join(array.axes.display_names)
...     shape = ' x '.join(str(i) for i in array.shape)
...     return "{} -> {} ({})\n  title = {}\n  dtype = {}".format(key, axes_names, shape,
...                                                                 array.meta.title, array.dtype)
>>> template = {Axis:  "{key} -> {name} [{labels}] ({length})",
...             Group: "{key} -> {name}: {axis_name}{labels} ({length})",
...             Array: print_array,
...             Metadata: "\t{key} -> {value}"}
>>> print(s.summary(template))   # doctest: +NORMALIZE_WHITESPACE
Metadata:
    title -> my title
    author -> John Smith
axis1 -> a ['a0' 'a1' 'a2'] (3)
group1 -> a01: a['a0', 'a1'] (2)
arr1 -> a, b (2 x 2)
  title = array 1
  dtype = int64
arr2 -> a (4)
  title = array 2
  dtype = int64
arr3 -> a, b (3 x 2)
  title = array 3
  dtype = int64