precompute_raveled_slices

odl.trafos.backends.pywt_bindings.precompute_raveled_slices(coeff_shapes, axes=None)[source]

Return slices and shapes for raveled multilevel wavelet coefficients.

The output is equivalent to the coeff_slices output of pywt.ravel_coeffs, but this function does not require computing a wavelet transform first.

Parameters:
coeff_shapesarray-like

A list of multilevel wavelet coefficient shapes as returned by pywt.wavedecn_shapes.

axessequence of ints, optional

Axes over which the DWT that created coeffs was performed. The default value of None corresponds to all axes.

Returns:
coeff_sliceslist

List of slices corresponding to each coefficient. As a 2D example, coeff_arr[coeff_slices[1]['dd']] would extract the first level detail coefficients from coeff_arr.

Examples

>>> import pywt
>>> data_shape = (64, 64)
>>> coeff_shapes = pywt.wavedecn_shapes(data_shape, wavelet='db2', level=3,
...                                     mode='periodization')
>>> coeff_slices = precompute_raveled_slices(coeff_shapes)
>>> print(coeff_slices[0])  # approximation coefficients
slice(None, 64, None)
>>> d1_coeffs = coeff_slices[-1]  # first level detail coefficients
>>> (d1_coeffs['ad'], d1_coeffs['da'], d1_coeffs['dd'])
(slice(1024, 2048, None), slice(2048, 3072, None), slice(3072, 4096, None))