kenjutsu.blocks module

kenjutsu.blocks.num_blocks(space_shape, block_shape)[source]

Computes the number of blocks.

Takes an array with space_shape and block_shape for every dimension. From this, it can compute slicings to use for cutting each block out from the original array, HDF5 dataset, or other.

Parameters:
  • space_shape (tuple) – Shape of array to slice
  • block_shape (tuple) – Size of each block to take
Returns:

Number of blocks per dimension

Return type:

tuple

Examples

>>> num_blocks(
...     (2, 3,), (2, 1,)
... )  
(1, 3)
kenjutsu.blocks.split_blocks(space_shape, block_shape, block_halo=None, index=None)[source]

Return a list of slicings to cut each block out of an array or other.

Takes an array with space_shape and block_shape for every dimension and a block_halo to extend each block on each side. From this, it can compute slicings to use for cutting each block out from the original array, HDF5 dataset or other.

Note

Blocks on the boundary that cannot extend the full range will be truncated to the largest block that will fit. This will raise a warning, which can be converted to an exception, if needed.

Parameters:
  • space_shape (tuple) – Shape of array to slice
  • block_shape (tuple) – Size of each block to take
  • block_halo (tuple) – Halo to tack on to each block
  • index (bool) – Whether to provide an index for each block
Returns:

Provides tuples of slices for retrieving blocks.

Return type:

collections.Sequence of tuples of slices

Examples

>>> split_blocks(
...     (2, 3,), (1, 1,), (1, 1,), True
... )  
([(0, 0),
  (0, 1),
  (0, 2),
  (1, 0),
  (1, 1),
  (1, 2)],

 [(slice(0, 1, 1), slice(0, 1, 1)),
  (slice(0, 1, 1), slice(1, 2, 1)),
  (slice(0, 1, 1), slice(2, 3, 1)),
  (slice(1, 2, 1), slice(0, 1, 1)),
  (slice(1, 2, 1), slice(1, 2, 1)),
  (slice(1, 2, 1), slice(2, 3, 1))],

 [(slice(0, 2, 1), slice(0, 2, 1)),
  (slice(0, 2, 1), slice(0, 3, 1)),
  (slice(0, 2, 1), slice(1, 3, 1)),
  (slice(0, 2, 1), slice(0, 2, 1)),
  (slice(0, 2, 1), slice(0, 3, 1)),
  (slice(0, 2, 1), slice(1, 3, 1))],

 [(slice(0, 1, 1), slice(0, 1, 1)),
  (slice(0, 1, 1), slice(1, 2, 1)),
  (slice(0, 1, 1), slice(1, 2, 1)),
  (slice(1, 2, 1), slice(0, 1, 1)),
  (slice(1, 2, 1), slice(1, 2, 1)),
  (slice(1, 2, 1), slice(1, 2, 1))])