Skip to content

Classification

classify_aspect(raster, unit='radians', num_classes=8)

Classify an aspect raster data set.

Can classify an aspect raster into 8 or 16 equally spaced directions with intervals of pi/4 and pi/8, respectively.

Exemplary for 8 classes, the center of the intervall for North direction is 0°/360° and edges are [337.5°, 22.5°], counting forward in clockwise direction. For 16 classes, the intervall-width is half with edges at [348,75°, 11,25°].

Directions and interval for 8 classes: N: (337.5, 22.5), NE: (22.5, 67.5), E: (67.5, 112.5), SE: (112.5, 157.5), S: (157.5, 202.5), SW: (202.5, 247.5), W: (247.5, 292.5), NW: (292.5, 337.5)

Directions and interval for 16 classes: N: (348.75, 11.25), NNE: (11.25, 33.75), NE: (33.75, 56.25), ENE: (56.25, 78.75), E: (78.75, 101.25), ESE: (101.25, 123.75), SE: (123.75, 146.25), SSE: (146.25, 168.75), S: (168.75, 191.25), SSW: (191.25, 213.75), SW: (213.75, 236.25), WSW: (236.25, 258.75), W: (258.75, 281.25), WNW: (281.25, 303.75), NW: (303.75, 326.25), NNW: (326.25, 348.75)

Flat pixels (input value: -1) will be kept, the class is called ND (not defined).

Parameters:

Name Type Description Default
raster DatasetReader

The input raster data.

required
unit Literal[radians, degrees]

The unit of the input raster. Either "degrees" or "radians"

'radians'
num_classes int

The number of classes for discretization. Either 8 or 16 classes allowed.

8

Returns:

Type Description
tuple[ndarray, dict, dict]

The classified aspect raster, a class mapping dictionary and the updated metadata.

Raises:

Type Description
InvalidParameterValueException

Invalid number of classes requested.

InvalidRasterBandException

Input raster has more than one band.

Source code in eis_toolkit/raster_processing/derivatives/classification.py
 66
 67
 68
 69
 70
 71
 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
@beartype
def classify_aspect(
    raster: rasterio.io.DatasetReader,
    unit: Literal["radians", "degrees"] = "radians",
    num_classes: int = 8,
) -> tuple[np.ndarray, dict, dict]:
    """
    Classify an aspect raster data set.

    Can classify an aspect raster into 8 or 16 equally spaced directions with
    intervals of pi/4 and pi/8, respectively.

    Exemplary for 8 classes, the center of the intervall for North direction is 0°/360°
    and edges are [337.5°, 22.5°], counting forward in clockwise direction. For 16 classes,
    the intervall-width is half with edges at [348,75°, 11,25°].

    Directions and interval for 8 classes:
    N: (337.5, 22.5), NE: (22.5, 67.5),
    E: (67.5, 112.5), SE: (112.5, 157.5),
    S: (157.5, 202.5), SW: (202.5, 247.5),
    W: (247.5, 292.5), NW: (292.5, 337.5)

    Directions and interval for 16 classes:
    N: (348.75, 11.25), NNE: (11.25, 33.75), NE: (33.75, 56.25), ENE: (56.25, 78.75),
    E: (78.75, 101.25), ESE: (101.25, 123.75), SE: (123.75, 146.25), SSE: (146.25, 168.75),
    S: (168.75, 191.25), SSW: (191.25, 213.75), SW: (213.75, 236.25), WSW: (236.25, 258.75),
    W: (258.75, 281.25), WNW: (281.25, 303.75), NW: (303.75, 326.25), NNW: (326.25, 348.75)

    Flat pixels (input value: -1) will be kept, the class is called ND (not defined).

    Args:
        raster: The input raster data.
        unit: The unit of the input raster. Either "degrees" or "radians"
        num_classes: The number of classes for discretization. Either 8 or 16 classes allowed.

    Returns:
        The classified aspect raster, a class mapping dictionary and the updated metadata.

    Raises:
        InvalidParameterValueException: Invalid number of classes requested.
        InvalidRasterBandException: Input raster has more than one band.
    """

    if raster.count > 1:
        raise InvalidRasterBandException("Only one-band raster supported.")

    if num_classes != 8 and num_classes != 16:
        raise InvalidParameterValueException("Only 8 or 16 classes allowed for classification!")

    return _classify_aspect(raster, unit, num_classes)