eii.compute
Full EII computation utilities (on-the-fly).
Aggregation
Combined Ecosystem Integrity Index calculation.
calculate_eii(aoi, method=DEFAULT_AGGREGATION_METHOD, year_range=None, include_seasonality=True)
Calculate the full Ecosystem Integrity Index for an area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
Geometry
|
Earth Engine geometry defining the area of interest. |
required |
method
|
Literal['minimum', 'product', 'min_fuzzy_logic', 'geometric_mean']
|
Method to combine components. Options: - "minimum": Simple minimum of components (most conservative) - "product": Product of components - "min_fuzzy_logic": Minimum with fuzzy compensation (default) - "geometric_mean": Geometric mean of components |
DEFAULT_AGGREGATION_METHOD
|
year_range
|
list[str] | None
|
Date range for actual NPP [start_date, end_date]. Defaults to OBSERVED_NPP_YEAR_RANGE. |
None
|
include_seasonality
|
bool
|
Include seasonality in functional integrity. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Image]
|
Dictionary containing functional_integrity, structural_integrity, |
dict[str, Image]
|
compositional_integrity, and combined eii images. |
Source code in src/eii/compute/integrity.py
combine_components(functional, structural, compositional, method=DEFAULT_AGGREGATION_METHOD)
Combine integrity components into a single EII score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
functional
|
Image
|
Functional integrity image (0-1). |
required |
structural
|
Image
|
Structural integrity image (0-1). |
required |
compositional
|
Image
|
Compositional integrity image (0-1). |
required |
method
|
Literal['minimum', 'product', 'min_fuzzy_logic', 'geometric_mean']
|
Aggregation method. |
DEFAULT_AGGREGATION_METHOD
|
Returns:
| Type | Description |
|---|---|
Image
|
Combined EII image (0-1). |
Source code in src/eii/compute/integrity.py
Functional integrity (NPP)
NPP-based functional integrity calculation.
This module handles: - Predictor stack setup for the NPP model - NPP model inference - Functional integrity score calculation
calculate_functional_integrity(aoi=None, year_range=OBSERVED_NPP_YEAR_RANGE, include_seasonality=True, use_precomputed=True, model_asset_path=DEFAULT_NPP_MODEL_PATH, natural_npp_asset_path=NATURAL_NPP_ASSET_PATH, observed_npp_asset_path=OBSERVED_NPP_ASSET_PATH, natural_npp_use_tiled_collection=False, absolute_diff_percentile='p95')
Calculate NPP-based functional integrity with magnitude and seasonality dimensions.
Magnitude integrity: symmetric deviation score + absolute diff score (weight: 2/3) Seasonality integrity: comparison of observed vs natural intra-annual std (weight: 1/3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
Geometry | None
|
Area of interest. If None, returns unclipped global image. |
None
|
year_range
|
list[str]
|
Date range for observed NPP (3-year rolling window). |
OBSERVED_NPP_YEAR_RANGE
|
include_seasonality
|
bool
|
Include seasonality dimension in scoring. |
True
|
use_precomputed
|
bool
|
Use pre-computed natural NPP tiles (recommended). |
True
|
model_asset_path
|
str
|
Path to NPP model (only used if use_precomputed=False). |
DEFAULT_NPP_MODEL_PATH
|
natural_npp_asset_path
|
str
|
Asset path for pre-computed natural NPP. |
NATURAL_NPP_ASSET_PATH
|
observed_npp_asset_path
|
str
|
Asset path for observed NPP annual tiles. |
OBSERVED_NPP_ASSET_PATH
|
natural_npp_use_tiled_collection
|
bool
|
Use tiled collection for natural NPP. |
False
|
absolute_diff_percentile
|
str
|
Percentile key for absolute NPP penalty (e.g. "p80"). |
'p95'
|
Returns:
| Type | Description |
|---|---|
dict[str, Image]
|
Dictionary with intermediate layers and final functional_integrity score. |
Source code in src/eii/compute/npp.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 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 | |
load_natural_npp(aoi=None, asset_path=NATURAL_NPP_ASSET_PATH, use_tiled_collection=False)
Load pre-computed natural NPP mean/std from an image or tiled collection.
Source code in src/eii/compute/npp.py
load_natural_npp_tiles(aoi=None, asset_path=NATURAL_NPP_ASSET_PATH, use_tiled_collection=False)
Backward-compatible alias for loading natural NPP.
Source code in src/eii/compute/npp.py
load_npp_diff_percentiles(asset_path=NPP_DIFF_PERCENTILES_ASSET_PATH)
Load NPP difference percentiles from GEE asset.
The asset is a FeatureCollection with a single feature containing percentile breaks as properties (p05, p10, ..., p95).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_path
|
str
|
Path to the percentiles asset. |
NPP_DIFF_PERCENTILES_ASSET_PATH
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with percentile values. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the percentiles asset is not available. Run compute_npp_decile_breaks.ipynb to create it. |
Source code in src/eii/compute/npp.py
setup_predictor_stack(resolution=SPATIAL_RESOLUTION, include_lat_lon=None, include_regional_tpi=True)
Set up the predictor stack for NPP model inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int
|
Output resolution in meters. |
SPATIAL_RESOLUTION
|
include_lat_lon
|
bool | None
|
Whether to include lat/lon as predictors. If None, uses INCLUDE_LAT_LON_PREDICTORS from settings. |
None
|
include_regional_tpi
|
bool
|
Whether to calculate and include a regional TPI (Topographic Position Index) based on a coarser DEM. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Image
|
Multi-band image containing all predictor variables. |
Source code in src/eii/compute/npp.py
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 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 | |
setup_response(product='clms', year_range=NPP_YEAR_RANGE, include_std=False)
Set up the response variable(s) (observed NPP).
We model the "Average Annual NPP Sum". This is calculated by averaging the 'yearly NPP sum' assets over the provided range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
product
|
str
|
NPP data source ("clms" or "modis"). |
'clms'
|
year_range
|
list[str]
|
Date range [start, end]. Defaults to ["2014-01-01", "2025-01-01"]. |
NPP_YEAR_RANGE
|
include_std
|
bool
|
If True, also compute inter-annual standard deviation. |
False
|
Returns:
| Type | Description |
|---|---|
Image
|
Image with "longterm_avg_npp_sum" band (representing the multi-year average of annual sums), |
Image
|
and optionally "longterm_avg_npp_sd" band. |
Source code in src/eii/compute/npp.py
Structural integrity
Structural integrity calculation using quality-weighted core area metrics.
Structural integrity measures landscape fragmentation AND habitat quality by: 1. Identifying core habitat (interior areas unaffected by edge effects) 2. Weighting core pixels by habitat quality class based on HMI
Quality Classes
HMI < 0.1: Pristine (weight 4) HMI 0.1-0.2: Low-impact (weight 3) HMI 0.2-0.3: Moderate (weight 2) HMI 0.3-0.4: Semi-natural (weight 1) HMI >= 0.4: Modified (weight 0)
Score interpretation
1.0 = All pristine core habitat 0.25 = All semi-natural core habitat 0.0 = No core habitat (fragmented or modified)
calculate_structural_integrity(aoi=None, edge_depth_m=DEFAULT_EDGE_DEPTH_M, neighborhood_m=DEFAULT_NEIGHBORHOOD_M, scale_m=DEFAULT_SCALE_M)
Calculate structural integrity using quality-weighted core area.
Core area is habitat that survives erosion by the edge depth. Each core pixel is weighted by its habitat quality class (pristine=4, semi-natural=1). The final score reflects both fragmentation AND habitat quality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
Geometry | None
|
Area of interest geometry. If None, returns global unclipped image suitable for tiled export pipelines. |
None
|
edge_depth_m
|
int
|
Edge effect penetration depth in meters. Areas within this distance of habitat boundaries are considered edge-affected. Default 300m based on literature (typical range 100-500m). |
DEFAULT_EDGE_DEPTH_M
|
neighborhood_m
|
int
|
Landscape analysis radius in meters. Default 5km balances local actionability with landscape-scale processes. |
DEFAULT_NEIGHBORHOOD_M
|
scale_m
|
int
|
Output scale in meters for reprojection. Default 300m matches the native HMI resolution. |
DEFAULT_SCALE_M
|
Returns:
| Type | Description |
|---|---|
Image
|
Structural integrity score (0-1) where: |
Image
|
|
Image
|
|
Image
|
|
Source code in src/eii/compute/structural.py
Compositional integrity
Compositional Integrity Module
This module handles functionality related to calculating compositional integrity based on biodiversity metrics like the Biodiversity Intactness Index (BII).
calculate_compositional_integrity(aoi=None, year=2020, asset_path=DEFAULT_BII_ASSET_PATH)
Calculate compositional ecosystem integrity based on Biodiversity Intactness Index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
Geometry | None
|
Area of interest (optional). If None, returns unclipped global image. |
None
|
year
|
int
|
Year to use for BII data. |
2020
|
asset_path
|
str
|
Earth Engine ImageCollection path for BII data. |
DEFAULT_BII_ASSET_PATH
|
Returns:
| Type | Description |
|---|---|
Image
|
Compositional integrity score (0-1 scale). |