ChipClassificationLabelSource#

class ChipClassificationLabelSource[source]#

Bases: LabelSource

A source of chip classification labels.

Ideally the vector_source contains a square for each cell in the grid. But in reality, it can be difficult to label imagery in such an exhaustive way. So, this can also handle sources with non-overlapping polygons that do not necessarily cover the entire extent. It infers the grid of cells and associated class_ids using the extent and options if infer_cells is set to True.

Attributes

bbox

Bounding box applied to the source.

crs_transformer

Associated CRSTransformer.

extent

Extent of the LabelSource.

__init__(label_source_config: ChipClassificationLabelSourceConfig, vector_source: VectorSource, bbox: Optional[Box] = None, lazy: bool = False)[source]#

Constructs a LabelSource for chip classification.

Parameters
  • label_source_config (ChipClassificationLabelSourceConfig) – Config for class inference.

  • vector_source (VectorSource) – Source of vector labels.

  • bbox (Optional[Box], optional) – User-specified crop of the extent. If None, the full extent available in the source file is used.

  • lazy (bool) – If True, labels are not populated during initialization. Defaults to False.

Methods

__init__(label_source_config, vector_source)

Constructs a LabelSource for chip classification.

get_labels([window])

Return labels overlapping with window.

infer_cells([cells])

Infer labels for a list of cells.

populate_labels([cells])

Populate self.labels by either reading or inferring.

set_bbox(bbox)

Set self.extent to the given value.

validate_labels(df)

__getitem__(key: Any) int[source]#

Return label for a window, inferring it if it is not already known.

Parameters

key (Any) –

Return type

int

__init__(label_source_config: ChipClassificationLabelSourceConfig, vector_source: VectorSource, bbox: Optional[Box] = None, lazy: bool = False)[source]#

Constructs a LabelSource for chip classification.

Parameters
  • label_source_config (ChipClassificationLabelSourceConfig) – Config for class inference.

  • vector_source (VectorSource) – Source of vector labels.

  • bbox (Optional[Box], optional) – User-specified crop of the extent. If None, the full extent available in the source file is used.

  • lazy (bool) – If True, labels are not populated during initialization. Defaults to False.

get_labels(window: Optional[Box] = None) ChipClassificationLabels[source]#

Return labels overlapping with window.

Parameters

window (Optional[Box]) – Box

Returns

Labels overlapping with window. If window is None, returns all labels.

Return type

ChipClassificationLabels

infer_cells(cells: Optional[Iterable[Box]] = None) ChipClassificationLabels[source]#

Infer labels for a list of cells. Only cells whose labels are not already known are inferred.

Parameters

cells (Optional[Iterable[Box]], optional) – Cells whose labels are to be inferred. Defaults to None.

Returns

labels

Return type

ChipClassificationLabels

populate_labels(cells: Optional[Iterable[Box]] = None) None[source]#

Populate self.labels by either reading or inferring.

If cfg.infer_cells is True or specific cells are given, the labels are inferred. Otherwise, they are read from the geojson.

Parameters

cells (Optional[Iterable[Box]]) –

Return type

None

set_bbox(bbox: Box) None[source]#

Set self.extent to the given value.

Note

This method is idempotent.

Parameters
  • extent (Box) – User-specified extent in pixel coordinates.

  • bbox (Box) –

Return type

None

validate_labels(df: geopandas.GeoDataFrame) None[source]#
Parameters

df (geopandas.GeoDataFrame) –

Return type

None

property bbox: Box#

Bounding box applied to the source.

property crs_transformer: CRSTransformer#

Associated CRSTransformer.

property extent: Box#

Extent of the LabelSource.