Tiling#
The satrain.tiling module provides functionality for tiling datasets and managing spatial data organization.
ipwgml.tiling#
Provides functionality for tiling input data and assembling tiled results.
- class DatasetTiler(dataset: Dataset, tile_size: int | None = 512, overlap: int = 32, spatial_dims: Tuple[str, str] | None = None)[source]#
Bases:
objectThis tiler provides functionality for tiling an xarray.Dataset into equal-sized tiles.
- Parameters:
dataset – List of input tensors for the retrieval.
tile_size – The size of a single tile. If this is None the tiler returns a single tile extending over the full spatial extent of the dataset.
overlap – The overlap between two subsequent tiles.
spatial_dims – A tuple containing the names of the spatial dimensions along which to tile the dataset. If not set, will use the two lattermost dimensions in the datset.
- assemble(tiles)[source]#
Assemble slices back to original shape using linear interpolation in overlap regions.
- Parameters:
tiles – A list of lists containing the results for each tile.
- Returns:
The data in ‘tiles’ reassembled along the last to dimensions to match the initial dimenions of the input.
- assemble_tile(row_index, col_index, results, results_t)[source]#
Assembles results from a single tile into the assembled result containers in ‘results’.
- Parameters:
row_index – The row index identifying the current tile.
col_index – The column index identifying the current tile.
results – Container for the assembled results.
results_t – Results for the current tile.
- get_slices(row_ind: int, col_ind) Tuple[slice, slice][source]#
Return slices for the clipping of the tiles.
- Parameters:
row_ind – The 0-based row index of the tile.
col_ind – The 0-based column index of the tile.
- Returns:
Tuple of slices that can be used to clip the retrieval results to obtain non-overlapping tiles.
- get_tile(row_ind: int, col_ind: int) Dataset[source]#
Get tile in the ‘row_ind’th row and ‘col_ind’th column of the two dimensional tiling.
- Parameters:
row_ind – The 0-based row index of the tile.
col_ind – The 0-based column index of the tile.
- Returns:
An xarray.Dataset containing the requested tile.
- get_weights(row_ind: int, col_ind, like: ndarray | None = None) ndarray[source]#
Get weights to reassemble results.
- Parameters:
row_ind – Row-index of the tile.
col_ind – Column-index of the tile.
like – An optional numpy.ndarray to infer the dtype of the results.
- Returns:
Numpy array containing weights for the corresponding tile.
- initialize_results(results_t)[source]#
Initialize containers for assembled results from the results from the first tile.
- Parameters:
results_t – Retrieval results returned from the first tile.
- Returns:
Depending of the structure of ‘results_t’, a single numpy.ndarray, or a (potentially nested) list or dict of numpy.ndarrays.
- predict(predict_fun)[source]#
Applies a prediction function to all tiles in the input and assembles the results.
- Parameters:
predict_fun – A callable that takes the input from a single tile and returns the corresponding predicted results.
- Returns:
The tile-wise results from ‘predict_fun’ assembled to the original size.
- get_starts_and_clips(extent: int, tile_size: int, overlap: int) Tuple[List[int], List[int]][source]#
Calculate start indices and numbers of clipped pixels for a given side length, tile size and overlap.
- Parameters:
extent – The extent of the dimension to tile.
tile_size – The size of each tile.
overlap – The number of pixels of overlap.
soft_end – Allow the last tile to go beyond
n, see notes for details
- Returns:
A tuple
(start, clip)containing the start indices of each tile and the number of pixels to clip between each neighboring tiles.