SpatialSampler#

class torchgeo.samplers.SpatialSampler(dataset, *, roi=None)[source]#

Bases: GeoSampler

Abstract base class for all spatial sampling strategies.

Added in version 0.10.

abstract property strategy: Literal['random', 'sequential']#

Sampling strategy.

All sampling strategies can be categorized as either being random or sequential. This distinction only matters when combining samplers via SpatioTemporalSampler, where either a zip (random) or product (sequential) of all sample locations is taken during each epoch.

Returns:

One of ‘random’ or ‘sequential’.

__init__(dataset, *, roi=None)[source]#

Initialize a new SpatialSampler instance.

Parameters:
  • dataset (GeoDataset) – Dataset to sample from.

  • roi (Polygon | None) – Region of interest to sample from (defaults to the bounds of dataset.index).

abstractmethod __iter__()[source]#

Iterate over generated sample locations for each epoch.

Yields:

[xmin – xmax, ymin:ymax] coordinates to index a dataset.

__matmul__(other)[source]#

Compute the product of two samplers.

Parameters:

other (TemporalSampler) – A temporal sampling strategy.

Returns:

A single spatial and temporal sampler.

Return type:

SpatioTemporalSampler

plot()[source]#

Plot a visualization of the sampling strategy.

Returns:

An animation visualizing the sampling strategy.

Raises:

AssertionError – If self.geometry is not a Polygon.

Return type:

FuncAnimation