cfdm.GatheredArray.subarrays

GatheredArray.subarrays(shapes=-1)[source]

Return descriptors for every subarray.

These descriptors are used during subarray decompression.

New in version (cfdm): 1.10.0.0

Parameters
chunks: -1 or sequence, optional

Define the subarray shapes.

Must be either -1, the default, meaning that all non-compressed dimensions in each subarray have the maximum possible size; or a sequence of tuple. In the latter case chunks must be allowed as an input to subarray_shapes.

A valid chunks specification may always be found by normalising an output of subarray_shapes with dask.array.core.normalize_chunks as follows: chunks = dask.array.core.normalize_chunks(a.subarray_shapes(...), shape=a.shape, dtype=a.dtype).

Returns
4-tuple of iterators

Each iterable iterates over a particular descriptor from each subarray.

  1. The indices of the uncompressed array that correspond to each subarray.

  2. The shape of each uncompressed subarray.

  3. The indices of the compressed array that correspond to each subarray.

  4. The location of each subarray on the uncompressed dimensions.

Examples

An original 3-d array with shape (4, 73, 96) has been compressed by gathering the dimensions with sizes 73 and 96 respectively into a single dimension of size 3028.

>>> u_indices, u_shapes, c_indices, locations = x.subarrays()
>>> for i in u_indices:
...    print(i)
...
(slice(0, 4, None), slice(0, 73, None), slice(0, 96, None))
>>> for i in u_shapes
...    print(i)
...
(4, 73, 96)
>>> for i in c_indices:
...    print(i)
...
(slice(0, 4, None), slice(0, 3028, None))
>>> for i in locations:
...    print(i)
...
(0, 0, 0)
>>> (
...  u_indices, u_shapes, c_indices, locations
... )= x.subarrays(shapes="most")
>>> for i in u_indices:
...    print(i)
...
(slice(0, 1, None), slice(0, 73, None), slice(0, 96, None))
(slice(1, 2, None), slice(0, 73, None), slice(0, 96, None))
(slice(2, 3, None), slice(0, 73, None), slice(0, 96, None))
(slice(3, 4, None), slice(0, 73, None), slice(0, 96, None))
>>> for i in u_shapes
...    print(i)
...
(1, 73, 96)
(1, 73, 96)
(1, 73, 96)
(1, 73, 96)
>>> for i in c_indices:
...    print(i)
...
(slice(0, 1, None), slice(0, 3028, None))
(slice(1, 2, None), slice(0, 3028, None))
(slice(2, 3, None), slice(0, 3028, None))
(slice(3, 4, None), slice(0, 3028, None))
>>> for i in locations:
...    print(i)
...
(0, 0, 0)
(1, 0, 0)
(2, 0, 0)
(3, 0, 0)
>>> (
...  u_indices, u_shapes, c_indices, locations
... ) = x.subarrays(shapes=((3, 1), None, None))
>>> for i in u_indices:
...    print(i)
...
(slice(0, 3, None), slice(0, 73, None), slice(0, 96, None))
(slice(3, 4, None), slice(0, 73, None), slice(0, 96, None))
>>> for i in u_shapes
...    print(i)
...
(3, 73, 96)
(1, 73, 96)
>>> for i in c_indices:
...    print(i)
...
(slice(0, 3, None), slice(0, 3028, None))
(slice(3, 4, None), slice(0, 3028, None))
>>> for i in locations:
...    print(i)
...
(0, 0, 0)
(1, 0, 0)