ChipClassificationLabels#

class ChipClassificationLabels[source]#

Bases: Labels

Represents a spatial grid of cells associated with classes.

__init__(cell_to_label: Optional[Dict[Box, Tuple[int, Optional[Sequence[float]]]]] = None)[source]#
Parameters

cell_to_label (Optional[Dict[Box, Tuple[int, Optional[Sequence[float]]]]]) –

Methods

__init__([cell_to_label])

extend(labels)

Adds cells contained in labels.

filter_by_aoi(aoi_polygons)

Return a copy of these labels filtered by given AOI polygons.

from_predictions(windows, predictions)

Overrid to convert predictions to (class_id, scores) pairs.

get_cell_class_id(cell)

Return class_id for a cell.

get_cell_scores(cell)

Return scores for a cell.

get_cells()

Return list of all cells (list of Box).

get_class_ids()

Return list of class_ids for all cells.

get_scores()

Return list of scores for all cells.

get_singleton_labels(cell)

Return Labels object representing a single cell.

get_values()

Return list of class_ids and scores for all cells.

make_empty()

Instantiate an empty instance of this class.

save(uri, class_config, crs_transformer[, bbox])

Save labels as a GeoJSON file.

set_cell(cell, class_id[, scores])

Set cell and its class_id.

__add__(other: ChipClassificationLabels) ChipClassificationLabels[source]#

Add labels to these labels.

Returns a concatenation of this and the other labels.

Parameters

other (ChipClassificationLabels) –

Return type

ChipClassificationLabels

__contains__(cell: Box) bool[source]#
Parameters

cell (Box) –

Return type

bool

__getitem__(cell: Box) ClassificationLabel[source]#
Parameters

cell (Box) –

Return type

ClassificationLabel

__init__(cell_to_label: Optional[Dict[Box, Tuple[int, Optional[Sequence[float]]]]] = None)[source]#
Parameters

cell_to_label (Optional[Dict[Box, Tuple[int, Optional[Sequence[float]]]]]) –

__setitem__(window: Box, value: Tuple[int, Optional[Sequence[float]]])[source]#
Parameters
extend(labels: ChipClassificationLabels) None[source]#

Adds cells contained in labels.

Parameters

labels (ChipClassificationLabels) – ChipClassificationLabels

Return type

None

filter_by_aoi(aoi_polygons: Iterable[Polygon])[source]#

Return a copy of these labels filtered by given AOI polygons.

Parameters

aoi_polygons (Iterable[Polygon]) – List of AOI polygons to filter by, in pixel coordinates.

classmethod from_predictions(windows: Iterable[Box], predictions: Iterable[Any]) Labels[source]#

Overrid to convert predictions to (class_id, scores) pairs.

Parameters
Return type

Labels

get_cell_class_id(cell: Box) int[source]#

Return class_id for a cell.

Parameters

cell (Box) – (Box)

Return type

int

get_cell_scores(cell: Box) Optional[Sequence[float]][source]#

Return scores for a cell.

Parameters

cell (Box) – (Box)

Return type

Optional[Sequence[float]]

get_cells() List[Box][source]#

Return list of all cells (list of Box).

Return type

List[Box]

get_class_ids() List[int][source]#

Return list of class_ids for all cells.

Return type

List[int]

get_scores() List[Optional[Sequence[float]]][source]#

Return list of scores for all cells.

Return type

List[Optional[Sequence[float]]]

get_singleton_labels(cell: Box)[source]#

Return Labels object representing a single cell.

Parameters

cell (Box) – (Box)

get_values() List[ClassificationLabel][source]#

Return list of class_ids and scores for all cells.

Return type

List[ClassificationLabel]

classmethod make_empty() ChipClassificationLabels[source]#

Instantiate an empty instance of this class.

Returns

An object of the Label subclass on which this method is called.

Return type

Labels

save(uri: str, class_config: ClassConfig, crs_transformer: CRSTransformer, bbox: Optional[Box] = None) None[source]#

Save labels as a GeoJSON file.

Parameters
  • uri (str) – URI of the output file.

  • class_config (ClassConfig) – ClassConfig to map class IDs to names.

  • crs_transformer (CRSTransformer) – CRSTransformer to convert from pixel-coords to map-coords before saving.

  • bbox (Optional[Box]) – User-specified crop of the extent. Must be provided if the corresponding RasterSource has bbox != extent.

Return type

None

set_cell(cell: Box, class_id: int, scores: Optional[ndarray] = None) None[source]#

Set cell and its class_id.

Parameters
  • cell (Box) – (Box)

  • class_id (int) – int

  • scores (Optional[ndarray]) – 1d numpy array of probabilities for each class

Return type

None