darts_preprocessing
¶
Data preprocessing and feature engineering for the DARTS dataset.
calculate_aspect
¶
Calculate aspect (compass direction) of the terrain surface from an ArcticDEM Dataset.
Aspect indicates the downslope direction of the maximum rate of change in elevation.
Parameters:
Returns:
-
xarray.Dataset–xr.Dataset: Input Dataset with new data variable added:
-
xarray.Dataset–-
aspect (float32): Aspect in degrees clockwise from north [0-360], or -1 for flat areas.
-
long_name: "Aspect"
- units: "degrees"
- description: Compass direction of slope
- source: "ArcticDEM"
-
Note
Aspect values:
- 0° or 360°: North-facing
- 90°: East-facing
- 180°: South-facing
- 270°: West-facing
- -1: Flat (no dominant direction)
Example
Source code in darts-preprocessing/src/darts_preprocessing/engineering/arcticdem.py
calculate_ctvi
¶
Calculate CTVI (Corrected Transformed Vegetation Index) from spectral bands.
CTVI is a corrected version of TVI that maintains the sign of the original NDVI values while applying the transformation.
Parameters:
-
optical(xarray.Dataset) –Dataset containing: - ndvi (float32): NDVI values (will be calculated if not present) - nir, red (float32): Required if NDVI not present
Returns:
Note
Formula: CTVI = (NDVI + 0.5) / |NDVI + 0.5| * sqrt(|NDVI + 0.5|)
If NDVI is already in the dataset, it will be reused to avoid recalculation.
References
Lemenkova, Polina. "Hyperspectral Vegetation Indices Calculated by Qgis Using Landsat Tm Image: a Case Study of Northern Iceland" Advanced Research in Life Sciences, vol. 4, no. 1, Sciendo, 2020, pp. 70-78. https://doi.org/10.2478/arls-2020-0021
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_curvature
¶
Calculate curvature of the terrain surface from an ArcticDEM Dataset.
Curvature measures the rate of change of slope, indicating terrain convexity or concavity.
Parameters:
Returns:
-
xarray.Dataset–xr.Dataset: Input Dataset with new data variable added:
-
xarray.Dataset–-
curvature (float32): Curvature values.
-
long_name: "Curvature"
- description: Rate of change of slope
- source: "ArcticDEM"
-
Note
Curvature interpretation:
- Positive values: Convex terrain (hills, ridges)
- Negative values: Concave terrain (valleys, depressions)
- Near zero: Planar terrain
Example
Source code in darts-preprocessing/src/darts_preprocessing/engineering/arcticdem.py
calculate_dissection_index
¶
calculate_dissection_index(
arcticdem_ds: xarray.Dataset, neighborhood_size: int
) -> xarray.Dataset
Calculate the Dissection Index (DI) from an ArcticDEM Dataset.
DI measures the degree to which a landscape has been cut by valleys and ravines. Values range from 0 (smooth, undissected) to 1 (highly dissected).
Parameters:
-
arcticdem_ds(xarray.Dataset) –Dataset containing: - dem (float32): Digital Elevation Model
-
neighborhood_size(int) –Neighborhood window size for DI calculation. Can be specified as string with units (e.g., "100m" or "10px").
Returns:
-
xarray.Dataset–xr.Dataset: Input Dataset with new data variable added:
-
xarray.Dataset–-
di (float32): Dissection Index [0-1].
-
long_name: "Dissection Index"
- description: Documents neighborhood size used
- source: "ArcticDEM"
-
Note
The dissection index quantifies landscape dissection by comparing elevation ranges within the neighborhood window. Higher values indicate more deeply incised terrain with greater vertical relief.
The neighborhood_size parameter is converted to pixels based on DEM resolution.
Example
Source code in darts-preprocessing/src/darts_preprocessing/engineering/arcticdem.py
calculate_evi
¶
calculate_evi(
optical: xarray.Dataset,
g: float = 2.5,
c1: float = 6,
c2: float = 7.5,
l: float = 1,
) -> xarray.DataArray
Calculate EVI (Enhanced Vegetation Index) from spectral bands.
EVI is optimized to enhance vegetation signal with improved sensitivity in high biomass regions and improved vegetation monitoring through decoupling of canopy background signal and reducing atmospheric influences.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - nir (float32): Near-infrared reflectance [0-1] - red (float32): Red reflectance [0-1] - blue (float32): Blue reflectance [0-1]
-
g(float, default:2.5) –Gain factor. Defaults to 2.5.
-
c1(float, default:6) –Aerosol resistance coefficient for red band. Defaults to 6.
-
c2(float, default:7.5) –Aerosol resistance coefficient for blue band. Defaults to 7.5.
-
l(float, default:1) –Canopy background adjustment. Defaults to 1.
Returns:
Note
Formula: EVI = G * (NIR - Red) / (NIR + C1 * Red - C2 * Blue + L)
Input bands are clipped to [0, 1] to avoid numerical instabilities.
References
A Huete, K Didan, T Miura, E.P Rodriguez, X Gao, L.G Ferreira, Overview of the radiometric and biophysical performance of the MODIS vegetation indices, Remote Sensing of Environment, Volume 83, Issues 1-2, 2002, Pages 195-213, ISSN 0034-4257, https://doi.org/10.1016/S0034-4257(02)00096-2.
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_exg
¶
Calculate EXG (Excess Green Index) from spectral bands.
EXG highlights green vegetation by emphasizing the green band relative to red and blue. Widely used for crop/weed discrimination and precision agriculture.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - green (float32): Green reflectance [0-1] - red (float32): Red reflectance [0-1] - blue (float32): Blue reflectance [0-1]
Returns:
Note
Formula: EXG = 2 * Green - Red - Blue
Input bands are clipped to [0, 1] to avoid numerical instabilities.
References
Upendar, K., Agrawal, K.N., Chandel, N.S. et al. Greenness identification using visible spectral colour indices for site specific weed management. Plant Physiol. Rep. 26, 179-187 (2021). https://doi.org/10.1007/s40502-020-00562-0
Example
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_gli
¶
Calculate GLI (Green Leaf Index) from spectral bands.
GLI emphasizes green reflectance for vegetation detection using only visible bands. Suitable for RGB sensors and aerial imagery.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - green (float32): Green reflectance - red (float32): Red reflectance - blue (float32): Blue reflectance
Returns:
Note
Formula: GLI = (2 * Green - Red - Blue) / (2 * Green + Red + Blue)
References
Eng, L.S., Ismail, R., Hashim, W., Baharum, A., 2019. The Use of VARI, GLI, and VIgreen Formulas in Detecting Vegetation In aerial Images. International Journal of Technology. Volume 10(7), pp. 1385-1394 https://doi.org/10.14716/ijtech.v10i7.3275
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_gndvi
¶
Calculate GNDVI (Green Normalized Difference Vegetation Index) from spectral bands.
GNDVI is similar to NDVI but uses the green band instead of red, making it more sensitive to chlorophyll content and useful for mid to late season vegetation monitoring.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - nir (float32): Near-infrared reflectance [0-1] - green (float32): Green reflectance [0-1]
Returns:
-
xarray.DataArray–xr.DataArray: GNDVI values with attributes: - long_name: "GNDVI" - Values clipped to [-1, 1] range
Note
Formula: GNDVI = (NIR - Green) / (NIR + Green)
Input bands are clipped to [0, 1] to avoid numerical instabilities.
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_grvi
¶
Calculate GRVI (Green Red Vegetation Index) from spectral bands.
GRVI uses visible bands to detect vegetation, useful for high-resolution imagery where NIR may not be available or for specific vegetation discrimination tasks.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - green (float32): Green reflectance [0-1] - red (float32): Red reflectance [0-1]
Returns:
Note
Formula: GRVI = (Green - Red) / (Green + Red)
Input bands are clipped to [0, 1] to avoid numerical instabilities.
References
Eng, L.S., Ismail, R., Hashim, W., Baharum, A., 2019. The Use of VARI, GLI, and VIgreen Formulas in Detecting Vegetation In aerial Images. International Journal of Technology. Volume 10(7), pp. 1385-1394 https://doi.org/10.14716/ijtech.v10i7.3275
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_hillshade
¶
calculate_hillshade(
arcticdem_ds: xarray.Dataset,
azimuth: int = 225,
angle_altitude: int = 25,
) -> xarray.Dataset
Calculate hillshade of the terrain surface from an ArcticDEM Dataset.
Hillshade simulates illumination of terrain from a specified sun position, useful for visualization and terrain analysis.
Parameters:
-
arcticdem_ds(xarray.Dataset) –Dataset containing: - dem (float32): Digital Elevation Model
-
azimuth(int, default:225) –Light source azimuth in degrees clockwise from north [0-360]. Defaults to 225 (southwest).
-
angle_altitude(int, default:25) –Light source altitude angle in degrees above horizon [0-90]. Defaults to 25.
Returns:
-
xarray.Dataset–xr.Dataset: Input Dataset with new data variable added:
-
xarray.Dataset–-
hillshade (float32): Illumination values [0-255], where 0 is shadow and 255 is fully lit.
-
long_name: "Hillshade"
- description: Documents azimuth and angle_altitude used
- source: "ArcticDEM"
-
Note
Common azimuth/altitude combinations:
- 315°/45°: Classic northwest illumination (default for many GIS applications)
- 225°/25°: Southwest with low sun (better for visualizing subtle features)
The hillshade calculation accounts for both slope and aspect of the terrain.
Example
Source code in darts-preprocessing/src/darts_preprocessing/engineering/arcticdem.py
calculate_ndvi
¶
Calculate NDVI (Normalized Difference Vegetation Index) from spectral bands.
NDVI is a widely-used vegetation index that indicates photosynthetic activity and vegetation health. Values range from -1 to 1, with higher values indicating denser, healthier vegetation.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - nir (float32): Near-infrared reflectance [0-1] - red (float32): Red reflectance [0-1]
Returns:
Note
Formula: NDVI = (NIR - Red) / (NIR + Red)
Input bands are clipped to [0, 1] before calculation to avoid numerical instabilities from negative reflectance values or sensor artifacts. The final result is also clipped to ensure values remain in the valid [-1, 1] range.
Example
Calculate NDVI from optical data:
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_nrvi
¶
Calculate NRVI (Normalized Ratio Vegetation Index) from spectral bands.
NRVI normalizes RVI to a range similar to NDVI, making it more comparable across different vegetation densities.
Parameters:
-
optical(xarray.Dataset) –Dataset containing: - rvi (float32): RVI values (will be calculated if not present) - nir, red (float32): Required if RVI not present
Returns:
Note
Formula: NRVI = (RVI - 1) / (RVI + 1) where RVI = Red / NIR
If RVI is already in the dataset, it will be reused to avoid recalculation.
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_rvi
¶
Calculate RVI (Ratio Vegetation Index) from spectral bands.
RVI is a simple ratio index sensitive to vegetation amount and biomass. Values typically range from 0 to over 30 for dense vegetation.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - nir (float32): Near-infrared reflectance [0-1] - red (float32): Red reflectance [0-1]
Returns:
Note
Formula: RVI = Red / NIR
Input bands are clipped to [0, 1] to avoid numerical instabilities.
References
Lemenkova, Polina. "Hyperspectral Vegetation Indices Calculated by Qgis Using Landsat Tm Image: a Case Study of Northern Iceland" Advanced Research in Life Sciences, vol. 4, no. 1, Sciendo, 2020, pp. 70-78. https://doi.org/10.2478/arls-2020-0021
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_savi
¶
Calculate SAVI (Soil Adjusted Vegetation Index) from spectral bands.
SAVI minimizes soil brightness influences using a soil-brightness correction factor. Useful in areas with sparse vegetation or exposed soil.
Parameters:
-
optical(xarray.Dataset) –Dataset containing: - ndvi (float32): NDVI values (will be calculated if not present) - nir, red (float32): Required if NDVI not present
-
s(float, default:0.5) –Soil adjustment factor. Common values: - 0.5: moderate vegetation cover (default) - 0.25: high vegetation cover - 1.0: low vegetation cover
Returns:
Note
Formula: SAVI = NDVI * (1 + s)
References
Lemenkova, Polina. "Hyperspectral Vegetation Indices Calculated by Qgis Using Landsat Tm Image: a Case Study of Northern Iceland" Advanced Research in Life Sciences, vol. 4, no. 1, Sciendo, 2020, pp. 70-78. https://doi.org/10.2478/arls-2020-0021
Example
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_slope
¶
Calculate slope of the terrain surface from an ArcticDEM Dataset.
Slope represents the rate of change of elevation, indicating terrain steepness.
Parameters:
Returns:
-
xarray.Dataset–xr.Dataset: Input Dataset with new data variable added:
-
xarray.Dataset–-
slope (float32): Slope in degrees [0-90].
-
long_name: "Slope"
- units: "degrees"
- source: "ArcticDEM"
-
Note
Slope is calculated using finite difference methods on the DEM. Values approaching 90° indicate near-vertical terrain.
Example
Source code in darts-preprocessing/src/darts_preprocessing/engineering/arcticdem.py
calculate_spyndex
¶
calculate_spyndex(
ds_optical: xarray.Dataset,
index: str,
**kwargs: dict[str, typing.Any],
) -> xarray.DataArray
Compute a spectral index using the spyndex library.
This wrapper provides access to 200+ spectral indices from the spyndex library with automatic band mapping and parameter handling.
Parameters:
-
ds_optical(xarray.Dataset) –Dataset containing spectral bands. Band names should match spyndex common names (e.g., 'red', 'nir', 'blue', 'green').
-
index(str) –Name of the spectral index to compute. Run
spyndex.indicesto see all available indices (e.g., 'NDVI', 'EVI', 'SAVI'). -
**kwargs(dict[str, typing.Any], default:{}) –Additional parameters or band overrides: - Band values: Override bands from ds_optical with scalar or array values (e.g., red=0.2) - Constants: Override default values for index-specific constants (e.g., L=0.5 for SAVI)
Returns:
-
xarray.DataArray–xr.DataArray: Computed spectral index with attributes: - source: "spyndex" - long_name: Full name of the index - reference: Citation for the index - formula: Mathematical formula - author: Index contributor
Raises:
-
ValueError–If a required band is missing from both ds_optical and kwargs.
-
ValueError–If all bands are provided as scalar values.
Note
Band resolution priority:
- Bands in ds_optical (with common_name matching spyndex.bands)
- Values in kwargs (override ds_optical bands)
- Default values for constants (from spyndex.constants)
All optical bands are automatically clipped to [0, 1] before calculation.
At least one band must come from ds_optical as a DataArray (not all scalars).
Example
Compute various indices with spyndex:
from darts_preprocessing import calculate_spyndex
import spyndex
# List all available indices
print(list(spyndex.indices.keys()))
# Basic NDVI
ndvi = calculate_spyndex(ds_optical, "NDVI")
# SAVI with custom soil adjustment factor
savi = calculate_spyndex(ds_optical, "SAVI", L=0.5)
# EVI with custom parameters
evi = calculate_spyndex(ds_optical, "EVI", g=2.5, C1=6, C2=7.5, L=1)
Source code in darts-preprocessing/src/darts_preprocessing/engineering/spyndex.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 116 117 | |
calculate_terrain_ruggedness_index
¶
calculate_terrain_ruggedness_index(
arcticdem_ds: xarray.Dataset, neighborhood_size: int
) -> xarray.Dataset
Calculate the Terrain Ruggedness Index (TRI) from an ArcticDEM Dataset.
TRI quantifies topographic heterogeneity by measuring elevation differences between a cell and its surrounding cells. Higher values indicate more rugged terrain.
Parameters:
-
arcticdem_ds(xarray.Dataset) –Dataset containing: - dem (float32): Digital Elevation Model
-
neighborhood_size(int) –Neighborhood window size for TRI calculation. Can be specified as string with units (e.g., "100m" or "10px").
Returns:
-
xarray.Dataset–xr.Dataset: Input Dataset with new data variable added:
-
xarray.Dataset–-
tri (float32): Terrain Ruggedness Index in meters.
-
long_name: "Terrain Ruggedness Index"
- units: "m"
- description: Documents kernel size used
- source: "ArcticDEM"
-
Note
TRI methodology from Riley et al (1999):
- Measures elevation difference from center cell to 8 surrounding cells
- Squares and averages these differences
- Takes square root for final TRI value
The neighborhood_size parameter controls the kernel size. A square kernel is used, with the actual size rounded to the nearest pixel based on DEM resolution.
References
Riley, S.J., DeGloria, S.D., Elliot, R., 1999. A Terrain Ruggedness Index That Quantifies Topographic Heterogeneity. Intermountain Journal of Sciences, vol. 5, No. 1-4, pp. 23-27.
Example
Source code in darts-preprocessing/src/darts_preprocessing/engineering/arcticdem.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
calculate_tgi
¶
Calculate TGI (Triangular Greenness Index) from spectral bands.
TGI is sensitive to chlorophyll content and can estimate leaf area index without calibration. Particularly useful for crop monitoring.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - red (float32): Red reflectance [0-1] - green (float32): Green reflectance [0-1] - blue (float32): Blue reflectance [0-1]
Returns:
Note
Formula: TGI = -0.5 * [190 * (Red - Green) - 120 * (Red - Blue)]
Input bands are clipped to [0, 1] to avoid numerical instabilities.
References
E. Raymond Hunt, Paul C. Doraiswamy, James E. McMurtrey, Craig S.T. Daughtry, Eileen M. Perry, Bakhyt Akhmedov, A visible band index for remote sensing leaf chlorophyll content at the canopy scale, International Journal of Applied Earth Observation and Geoinformation, Volume 21, 2013, Pages 103-112, ISSN 1569-8432, https://doi.org/10.1016/j.jag.2012.07.020.
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_topographic_position_index
¶
calculate_topographic_position_index(
arcticdem_ds: xarray.Dataset,
outer_radius: int,
inner_radius: int,
) -> xarray.Dataset
Calculate the Topographic Position Index (TPI) from an ArcticDEM Dataset.
TPI measures the relative topographic position of a point by comparing its elevation to the mean elevation of the surrounding neighborhood. Positive values indicate higher positions (ridges), negative values indicate lower positions (valleys).
Parameters:
-
arcticdem_ds(xarray.Dataset) –The ArcticDEM Dataset containing the 'dem' variable (float32).
-
outer_radius(int) –The outer radius of the neighborhood in meters. Can also be specified as string with units (e.g., "100m" or "10px").
-
inner_radius(int) –The inner radius of the annulus kernel in meters. If > 0, creates an annulus (ring) instead of a circle. Set to 0 for a circular kernel. Can also be specified as string with units (e.g., "50m" or "5px").
Returns:
-
xarray.Dataset–xr.Dataset: The input Dataset with a new data variable added:
-
xarray.Dataset–-
tpi (float32): Topographic Position Index values.
-
long_name: "Topographic Position Index (TPI)"
- description: Details about the kernel used
-
Note
Kernel shape combinations:
- inner_radius=0: Circular kernel comparing each cell to all neighbors within outer_radius
- inner_radius>0: Annulus kernel comparing each cell to neighbors in a ring between inner_radius and outer_radius. Useful for multi-scale terrain analysis.
The actual radii used are rounded to the nearest pixel based on the DEM resolution.
Example
Calculate TPI with circular and annulus kernels:
from darts_preprocessing import calculate_topographic_position_index
# Circular kernel (100m radius)
arcticdem_with_tpi = calculate_topographic_position_index(
arcticdem_ds=arcticdem,
outer_radius=100,
inner_radius=0
)
# Annulus kernel (50-100m ring)
arcticdem_multi_scale = calculate_topographic_position_index(
arcticdem_ds=arcticdem,
outer_radius=100,
inner_radius=50
)
Source code in darts-preprocessing/src/darts_preprocessing/engineering/arcticdem.py
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
calculate_ttvi
¶
Calculate TTVI (Thiam's Transformed Vegetation Index) from spectral bands.
TTVI applies an absolute value transformation to NDVI before the square root, making it suitable for both positive and negative NDVI values.
Parameters:
-
optical(xarray.Dataset) –Dataset containing: - ndvi (float32): NDVI values (will be calculated if not present) - nir, red (float32): Required if NDVI not present
Returns:
Note
Formula: TTVI = sqrt(|NDVI| + 0.5)
If NDVI is already in the dataset, it will be reused to avoid recalculation.
References
Lemenkova, Polina. "Hyperspectral Vegetation Indices Calculated by Qgis Using Landsat Tm Image: a Case Study of Northern Iceland" Advanced Research in Life Sciences, vol. 4, no. 1, Sciendo, 2020, pp. 70-78. https://doi.org/10.2478/arls-2020-0021
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_tvi
¶
Calculate TVI (Transformed Vegetation Index) from spectral bands.
TVI applies a transformation to NDVI to enhance contrast and improve discrimination of vegetation conditions.
Parameters:
-
optical(xarray.Dataset) –Dataset containing: - ndvi (float32): NDVI values (will be calculated if not present) - nir, red (float32): Required if NDVI not present
Returns:
Note
Formula: TVI = sqrt(NDVI + 0.5)
If NDVI is already in the dataset, it will be reused to avoid recalculation.
References
Lemenkova, Polina. "Hyperspectral Vegetation Indices Calculated by Qgis Using Landsat Tm Image: a Case Study of Northern Iceland" Advanced Research in Life Sciences, vol. 4, no. 1, Sciendo, 2020, pp. 70-78. https://doi.org/10.2478/arls-2020-0021
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_vari
¶
Calculate VARI (Visible Atmospherically Resistant Index) from spectral bands.
VARI uses only visible bands, designed to minimize atmospheric effects. Useful for RGB imagery without NIR band or for atmospheric correction validation.
Parameters:
-
optical(xarray.Dataset) –Dataset containing spectral bands: - green (float32): Green reflectance [0-1] - red (float32): Red reflectance [0-1] - blue (float32): Blue reflectance [0-1]
Returns:
Note
Formula: VARI = (Green - Red) / (Green + Red - Blue)
Input bands are clipped to [0, 1] to avoid numerical instabilities.
References
Eng, L.S., Ismail, R., Hashim, W., Baharum, A., 2019. The Use of VARI, GLI, and VIgreen Formulas in Detecting Vegetation In aerial Images. International Journal of Technology. Volume 10(7), pp. 1385-1394 https://doi.org/10.14716/ijtech.v10i7.3275
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_vdvi
¶
Alias for GLI (Green Leaf Index) from an xarray Dataset containing spectral bands.
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
calculate_vector_ruggedness_measure
¶
calculate_vector_ruggedness_measure(
arcticdem_ds: xarray.Dataset, neighborhood_size: int
) -> xarray.Dataset
Calculate the Vector Ruggedness Measure (VRM) from an ArcticDEM Dataset.
VRM quantifies terrain ruggedness using vector analysis of slope and aspect, providing a measure independent of absolute elevation. Values range from 0 (smooth) to 1 (rugged).
Parameters:
-
arcticdem_ds(xarray.Dataset) –Dataset containing: - dem (float32): Digital Elevation Model - slope (float32): Slope in degrees (will be calculated if not present) - aspect (float32): Aspect in degrees (will be calculated if not present)
-
neighborhood_size(int) –Neighborhood window size for VRM calculation. Can be specified as string with units (e.g., "100m" or "10px").
Returns:
-
xarray.Dataset–xr.Dataset: Input Dataset with new data variable added:
-
xarray.Dataset–-
vrm (float32): Vector Ruggedness Measure [0-1].
-
long_name: "Vector Ruggedness Measure"
- description: Documents neighborhood size used
- source: "ArcticDEM"
-
Note
VRM calculation:
- Converts slope and aspect to 3D unit vectors (x, y, z components)
- Sums vectors in the neighborhood window
- Calculates magnitude of resultant vector
- VRM = 1 - resultant magnitude
Flat areas (aspect = -1) are handled by setting aspect to 0.
Requires slope and aspect to be already calculated on the dataset.
References
Sappington, J.M., K.M. Longshore, and D.B. Thomson. 2007. Quantifying Landscape Ruggedness for Animal Habitat Analysis: A case Study Using Bighorn Sheep in the Mojave Desert. Journal of Wildlife Management. 71(5): 1419-1426.
Example
from darts_preprocessing import (
calculate_slope, calculate_aspect,
calculate_vector_ruggedness_measure
)
# VRM requires slope and aspect
arcticdem = calculate_slope(arcticdem)
arcticdem = calculate_aspect(arcticdem)
arcticdem_with_vrm = calculate_vector_ruggedness_measure(
arcticdem_ds=arcticdem,
neighborhood_size=100
)
Source code in darts-preprocessing/src/darts_preprocessing/engineering/arcticdem.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
calculate_vigreen
¶
Alias for VIGREEN (Vegetation Index Green) from an xarray Dataset containing spectral bands.
Source code in darts-preprocessing/src/darts_preprocessing/engineering/indices.py
preprocess_legacy_fast
¶
preprocess_legacy_fast(
ds_optical: xarray.Dataset,
ds_arcticdem: xarray.Dataset,
ds_tcvis: xarray.Dataset,
tpi_outer_radius: int = 100,
tpi_inner_radius: int = 0,
device: typing.Literal["cuda", "cpu"]
| int = darts_utils.cuda.DEFAULT_DEVICE,
) -> xarray.Dataset
Preprocess optical data with legacy (DARTS v1) preprocessing steps, but with new data concepts.
The processing steps are: - Calculate NDVI - Calculate slope and relative elevation from ArcticDEM - Merge everything into a single ds.
The main difference to preprocess_legacy is the new data concept of the arcticdem. Instead of using already preprocessed arcticdem data which are loaded from a VRT, this step expects the raw arcticdem data and calculates slope and relative elevation on the fly.
Parameters:
-
ds_optical(xarray.Dataset) –The Planet scene optical data or Sentinel 2 scene optical dataset including data_masks.
-
ds_arcticdem(xarray.Dataset) –The ArcticDEM dataset.
-
ds_tcvis(xarray.Dataset) –The TCVIS dataset.
-
tpi_outer_radius(int, default:100) –The outer radius of the annulus kernel for the tpi calculation in m. Defaults to 100m.
-
tpi_inner_radius(int, default:0) –The inner radius of the annulus kernel for the tpi calculation in m. Defaults to 0.
-
device(typing.Literal['cuda', 'cpu'] | int, default:darts_utils.cuda.DEFAULT_DEVICE) –The device to run the tpi and slope calculations on. If "cuda" take the first device (0), if int take the specified device. Defaults to "cuda" if cuda is available, else "cpu".
Returns:
Source code in darts-preprocessing/src/darts_preprocessing/legacy.py
preprocess_v2
¶
preprocess_v2(
ds_optical: xarray.Dataset,
ds_arcticdem: xarray.Dataset | None,
ds_tcvis: xarray.Dataset | None,
tpi_outer_radius: int = 100,
tpi_inner_radius: int = 0,
device: typing.Literal["cuda", "cpu"]
| int = darts_utils.cuda.DEFAULT_DEVICE,
) -> xarray.Dataset
Preprocess optical data with modern (DARTS v2) preprocessing steps.
This function combines optical imagery with terrain (ArcticDEM) and temporal vegetation indices (TCVIS) to create a multi-source feature dataset for segmentation. All auxiliary data sources are reprojected and cropped to match the optical data's extent and resolution.
Processing steps
- Calculate NDVI from optical bands
- If TCVIS provided: Reproject and merge Tasseled Cap trends
- If ArcticDEM provided: Calculate terrain features (TPI, slope, hillshade, aspect, curvature) using solar geometry from optical data attributes
Parameters:
-
ds_optical(xarray.Dataset) –Optical imagery dataset (PlanetScope or Sentinel-2) containing: - Required variables: blue, green, red, nir (float32, reflectance values) - Required variables: quality_data_mask, valid_data_mask (uint8) - Required attributes: azimuth (float), elevation (float) for hillshade calculation
-
ds_arcticdem(xarray.Dataset | None) –ArcticDEM dataset containing 'dem' (float32) and 'arcticdem_data_mask' (uint8). If None, terrain features are skipped.
-
ds_tcvis(xarray.Dataset | None) –TCVIS dataset containing tc_brightness, tc_greenness, tc_wetness (float). If None, TCVIS features are skipped.
-
tpi_outer_radius(int, default:100) –Outer radius for TPI calculation in meters. Defaults to 100m.
-
tpi_inner_radius(int, default:0) –Inner radius for TPI annulus kernel in meters. Set to 0 for circular kernel. Defaults to 0.
-
device(typing.Literal['cuda', 'cpu'] | int, default:darts_utils.cuda.DEFAULT_DEVICE) –Device for GPU-accelerated computations (NDVI, TPI, slope). Use "cuda" for first GPU, int for specific GPU, or "cpu". Defaults to "cuda" if available, else "cpu".
Returns:
-
xarray.Dataset–xr.Dataset: Preprocessed dataset with all input optical variables plus:
-
xarray.Dataset–Added from optical processing: - ndvi (float32): Normalized Difference Vegetation Index Attributes: long_name="NDVI"
-
xarray.Dataset–Added from TCVIS (if ds_tcvis provided): - tc_brightness (float): Tasseled Cap brightness trend - tc_greenness (float): Tasseled Cap greenness trend - tc_wetness (float): Tasseled Cap wetness trend
-
xarray.Dataset–Added from ArcticDEM (if ds_arcticdem provided): - dem (float32): Elevation in meters - relative_elevation (float32): Topographic Position Index (TPI) Attributes: long_name="Topographic Position Index (TPI)" - slope (float32): Slope in degrees [0-90] Attributes: long_name="Slope" - hillshade (uint8): Hillshade values [0-255] Attributes: long_name="Hillshade" - aspect (float32): Aspect in degrees [0-360] Attributes: long_name="Aspect" - curvature (float32): Surface curvature Attributes: long_name="Curvature" - arcticdem_data_mask (uint8): DEM validity mask
Note
Attribute usage:
- azimuth attribute from ds_optical: Used for hillshade calculation (solar azimuth angle).
Falls back to 225° if missing or invalid.
- elevation attribute from ds_optical: Used for hillshade calculation (solar elevation angle).
Falls back to 25° if missing or invalid.
Processing behavior: - If both ds_tcvis and ds_arcticdem are None, only NDVI is calculated. - ArcticDEM is buffered by tpi_outer_radius before reprojection to avoid edge effects, then cropped back to optical extent after terrain feature calculation. - Reprojection uses cubic resampling for smooth terrain features. - GPU acceleration (if device="cuda") significantly speeds up TPI and slope calculations.
Example
Complete preprocessing with all data sources:
from darts_preprocessing import preprocess_v2
from darts_acquisition import load_cdse_s2_sr_scene, load_arcticdem, load_tcvis
# Load optical data
optical = load_cdse_s2_sr_scene(s2_scene_id, ...)
# Load auxiliary data
arcticdem = load_arcticdem(optical.odc.geobox, ...)
tcvis = load_tcvis(optical.odc.geobox, ...)
# Preprocess
preprocessed = preprocess_v2(
ds_optical=optical,
ds_arcticdem=arcticdem,
ds_tcvis=tcvis,
tpi_outer_radius=100,
tpi_inner_radius=0,
device="cuda"
)
# Result contains: blue, green, red, nir, ndvi, tc_brightness, tc_greenness,
# tc_wetness, dem, relative_elevation, slope, hillshade, aspect, curvature
Source code in darts-preprocessing/src/darts_preprocessing/v2.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |