Skip to content

Calculate base metrics

calculate_base_metrics(raster, deposits, band=1, negatives=None)

Calculate true positive rate, proportion of area and false positive rate values for different thresholds.

Function calculates true positive rate, proportion of area and false positive rate values for different thresholds which are determined from inputted deposit locations and mineral prospectivity map. Note that calculation of false positive rate is optional and is only done if negative point locations are provided.

Parameters:

Name Type Description Default
raster DatasetReader

Mineral prospectivity map or evidence layer.

required
deposits GeoDataFrame

Mineral deposit locations as points.

required
band int

Band index of the mineral prospectivity map. Defaults to 1.

1
negatives Optional[GeoDataFrame]

Negative locations as points.

None

Returns:

Type Description
DataFrame

DataFrame containing true positive rate, proportion of area, threshold values and false positive rate (optional) values.

Raises:

Type Description
NonMatchingCrsException

The raster and point data are not in the same CRS.

GeometryTypeException

The input geometries contain non-point features.

Source code in eis_toolkit/evaluation/calculate_base_metrics.py
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@beartype
def calculate_base_metrics(
    raster: rasterio.io.DatasetReader,
    deposits: geopandas.GeoDataFrame,
    band: int = 1,
    negatives: Optional[geopandas.GeoDataFrame] = None,
) -> pd.DataFrame:
    """Calculate true positive rate, proportion of area and false positive rate values for different thresholds.

    Function calculates true positive rate, proportion of area and false positive rate values for different thresholds
    which are determined from inputted deposit locations and mineral prospectivity map. Note that calculation of false
    positive rate is optional and is only done if negative point locations are provided.

    Args:
        raster: Mineral prospectivity map or evidence layer.
        deposits: Mineral deposit locations as points.
        band: Band index of the mineral prospectivity map. Defaults to 1.
        negatives: Negative locations as points.

    Returns:
        DataFrame containing true positive rate, proportion of area, threshold values and false positive
            rate (optional) values.

    Raises:
        NonMatchingCrsException: The raster and point data are not in the same CRS.
        GeometryTypeException: The input geometries contain non-point features.
    """
    if negatives is not None:
        geometries = pd.concat([deposits, negatives]).geometry
    else:
        geometries = deposits["geometry"]

    if not check_matching_crs(
        objects=[raster, geometries],
    ):
        raise NonMatchingCrsException("The raster and deposits are not in the same CRS.")

    if not check_geometry_types(
        geometries=geometries,
        allowed_types=["Point"],
    ):
        raise GeometryTypeException("The input geometries contain non-point features.")

    base_metrics = _calculate_base_metrics(raster=raster, deposits=deposits, band=band, negatives=negatives)

    return base_metrics