# verde.block_split¶

verde.block_split(coordinates, spacing=None, adjust='spacing', region=None, shape=None)[source]

Split a region into blocks and label points according to where they fall.

The labels are integers corresponding to the index of the block. Also returns the coordinates of the center of each block (following the same index as the labels).

The size of the blocks can be specified by the spacing parameter. Alternatively, the number of blocks in the South-North and West-East directions can be specified using the shape parameter.

Note

If installed, package pykdtree will be used instead of scipy.spatial.cKDTree for better performance.

Parameters
• coordinates (tuple of arrays) – Arrays with the coordinates of each data point. Should be in the following order: (easting, northing, vertical, …). Only easting and northing will be used, all subsequent coordinates will be ignored.

• shape (tuple = (n_north, n_east) or None) – The number of blocks in the South-North and West-East directions, respectively.

• spacing (float, tuple = (s_north, s_east), or None) – The block size in the South-North and West-East directions, respectively. A single value means that the size is equal in both directions.

• adjust ({'spacing', 'region'}) – Whether to adjust the spacing or the region if required. Ignored if shape is given instead of spacing. Defaults to adjusting the spacing.

• region (list = [W, E, S, N]) – The boundaries of a given region in Cartesian or geographic coordinates. If not region is given, will use the bounding region of the given points.

Returns

• block_coordinates (tuple of arrays) – (easting, northing) arrays with the coordinates of the center of each block.

• labels (array) – integer label for each data point. The label is the index of the block to which that point belongs.

BlockReduce

Apply a reduction operation to the data in blocks (windows).

rolling_window

Select points on a rolling (moving) window.

expanding_window

Select points on windows of changing size.

Examples

>>> from verde import grid_coordinates
>>> coords = grid_coordinates((-5, 0, 5, 10), spacing=1)
>>> block_coords, labels = block_split(coords, spacing=2.5)
>>> for coord in block_coords:
...     print(', '.join(['{:.2f}'.format(i) for i in coord]))
-3.75, -1.25, -3.75, -1.25
6.25, 6.25, 8.75, 8.75
>>> print(labels.reshape(coords[0].shape))
[[0 0 0 1 1 1]
[0 0 0 1 1 1]
[0 0 0 1 1 1]
[2 2 2 3 3 3]
[2 2 2 3 3 3]
[2 2 2 3 3 3]]
>>> # Use the shape instead of the block size
>>> block_coords, labels = block_split(coords, shape=(4, 2))
>>> for coord in block_coords:
...     print(', '.join(['{:.3f}'.format(i) for i in coord]))
-3.750, -1.250, -3.750, -1.250, -3.750, -1.250, -3.750, -1.250
5.625, 5.625, 6.875, 6.875, 8.125, 8.125, 9.375, 9.375
>>> print(labels.reshape(coords[0].shape))
[[0 0 0 1 1 1]
[0 0 0 1 1 1]
[2 2 2 3 3 3]
[4 4 4 5 5 5]
[6 6 6 7 7 7]
[6 6 6 7 7 7]]