Criterion B Details

# Default ecosystem code for template development.
# This line is replaced by build_ecosystem_pages.py for each ecosystem.
ecosystem_code = 'Bosque Fragmentado con Vegetacion Secundaria'

Import Python modules.

import os
import yaml
from pathlib import Path
from lonboard import Map
from rle.core import Ecosystems, criterion_b_status, rle_category
from rle.core.eoo import make_eoo
from rle.core.aoo import make_aoo_grid

Load the country config file.

project_root = os.environ.get('PIXI_PROJECT_ROOT', str(Path('..').resolve()))
config_path = Path(project_root) / 'config' / 'country_config.yaml'
with open(config_path) as f:
    config = yaml.safe_load(f)

# Ecosystem index (the COG pixel value for this ecosystem), looked up by code
# from the canonical index table. Absent if the index has not been built yet.
import csv
ecosystem_index = None
index_csv = Path(project_root) / 'config' / 'ecosystems' / 'index.csv'
if index_csv.exists():
    with open(index_csv) as f:
        for row in csv.DictReader(f):
            if row['code'] == ecosystem_code:
                ecosystem_index = int(row['index'])
                break

Load & Filter Ecosystem Data

Load data for all the ecosystems.

import sys
# Shared config helpers live in scripts/; make them importable from here.
sys.path.insert(0, str(Path(project_root) / 'scripts'))
from _config import ensure_vector_source

source = config['ecosystem_source']
# ecosystem_code_column is optional: fall back to the name column.
ecosystem_column = source.get('ecosystem_code_column') or source.get('ecosystem_name_column')
# Prefer the ecosystem-sorted `optimized_data` copy when configured, so that
# filtering to one ecosystem uses parquet predicate pushdown instead of loading
# the whole national map into memory. Falls back to `data`.
ecosystems = Ecosystems.from_file(
    ensure_vector_source(source.get('optimized_data') or source['data']),
    ecosystem_column=ecosystem_column,
    ecosystem_name_column=source.get('ecosystem_name_column'),
    functional_group_column=source.get('functional_group_column')
)

Filter by the Bosque Fragmentado con Vegetacion Secundaria and check the number of features.

ecosystem = ecosystems.filter(ecosystem_code)
has_data = ecosystem.size() > 0
print(f'{ecosystem.size() = }')
if not has_data:
    from IPython.display import Markdown, display
    display(Markdown(
        f'**No spatial data found for {ecosystem_code}.** '
        f'Criterion B calculations are skipped.'
    ))
ecosystem.size() = 11091

Extent of Occurrence (EOO) (subcriterion B1)

Extent of occurrence (EOO). The EOO of an ecosystem is the area (km2) of a minimum convex polygon – the smallest polygon in which no internal angle exceeds 180° that encompasses all known current spatial occurrences of the ecosystem type.

The minimum convex polygon (also known as a convex hull) must not exclude any areas, discontinuities or disjunctions, regardless of whether the ecosystem can occur in those areas or not. Regions such as oceans (for terrestrial ecosystems), land (for coastal or marine ecosystems), or areas outside the study area (such as in a different country) must remain included within the minimum convex polygon to ensure that this standardised method is comparable across ecosystem types. In addition, these features contribute to spreading risks across the distribution of the ecosystem by making different parts of its distribution more spatially independent.

Calculate EOO

Start by calculating the convex hull of the ecosystem’s distribution.

import geopandas as gpd

if has_data:
    ecosystem_geometry = ecosystem.geometry.union_all()
    gdf_ecosystem_polygons = gpd.GeoDataFrame(geometry=[ecosystem_geometry], crs=ecosystem.geometry.crs)
    hull = ecosystem_geometry.convex_hull
    gdf_hull = gpd.GeoDataFrame(geometry=[hull], crs=ecosystem.geometry.crs)

Display the ecosystem’s distribution and the convex hull.

from lonboard import Map, PolygonLayer
from rle.core.viz import smart_map

if has_data:
    eoo_hull = make_eoo(ecosystem).compute()
    display(smart_map([eoo_hull, ecosystem]))
/home/runner/work/rle-tyler-colombia/rle-tyler-colombia/.pixi/envs/default/lib/python3.11/site-packages/lonboard/_geoarrow/ops/reproject.py:116: UserWarning: Input being reprojected to EPSG:4326 CRS.
Lonboard is only able to render data in EPSG:4326 projection.
  warnings.warn(

if has_data:
    hull_ea = gdf_hull.to_crs("ESRI:54034")
    eoo = hull_ea.geometry.iloc[0].area / 1e6
    print(f'EOO is {eoo:.1f} km2')
EOO is 1543318.1 km2

Then calculate the area of the convex hull polygon.

Direct calculation of EOO

EOO can also be calculated directly using …

if has_data:
    ecosystem.eoo

Verify that the area returned by calling make_eoo(ecosystem).compute().area_km2 is the same as the area of the convex hull polygon.

if has_data:
    assert ecosystem.eoo == eoo

Area of Occupancy (AOO) (subcriterion B2)

The protocol for this adjustment includes the following steps:

  1. Intersect AOO grid with the ecosystem’s distribution map.
  2. Calculate extent of the ecosystem type in each grid cell (area) and sum these areas to obtain the total ecosystem area (total area).
  3. Arrange grid cells in ascending order based on their area (smaller first). Calculate accumulated sum of area per cell (cumulative area).
  4. Calculate cumulative proportion by dividing cumulative area by total area (cumulative proportion takes values between 0 and 1)
  5. Calculate AOO by counting the number of cells with a cumulative proportion greater than 0.01 (i.e. exclude cells that in combination account for up to 1% of the total mapped extent of the ecosystem type).

AOO Calculation Details

Intersect AOO grid and ecosystem map

  1. Intersect AOO grid with the ecosystem’s distribution map
from pathlib import Path
from rle.core.aoo import make_aoo_grid_cached

if has_data:
    # Prefer a prebuilt grid cache (e.g. a gs:// URI) so the national AOO grid
    # is not recomputed during CI renders — computing it from the full national
    # ecosystem map peaks at many GB of RAM. Fall back to a local cache when no
    # prebuilt cache is configured. Build one with `pixi run build-caches`.
    cache_path = (
        source.get('aoo_grid_cache_url')
        or (Path(project_root) / '.cache' / 'aoo_grid.parquet')
    )
    aoo_grid = make_aoo_grid_cached(ecosystems, cache_path=cache_path)
    aoo_grid_filtered = aoo_grid.filter_by_ecosystem(ecosystem_code)

Visualize variations in the AOO grid.

from matplotlib.colors import LinearSegmentedColormap
from lonboard.colormap import apply_continuous_cmap
from rle.core.aoo import slugify_ecosystem_name

ecosystem_column = slugify_ecosystem_name(ecosystem_code)
if has_data:
    cmap = LinearSegmentedColormap.from_list("white_red", ["white", "red"])
    values = aoo_grid_filtered.grid_cells[ecosystem_column].values
    normalized = (values - values.min()) / (values.max() - values.min())
    colors = apply_continuous_cmap(normalized, cmap)
    display(smart_map([(aoo_grid_filtered, {"get_fill_color": colors}), ecosystem]))

Calculate grid cell area and total area

  1. Calculate extent of the ecosystem type in each grid cell (area) and sum these areas to obtain the total ecosystem area (total area).
if has_data:
    keep = ['geometry', 'grid_col', 'grid_row', ecosystem_column]
    gdf = aoo_grid_filtered.grid_cells[keep]
    display(gdf)
geometry grid_col grid_row Bosque_Fragmentado_con_Vegetacion_Secundaria
0 POLYGON ((-78.96191 1.62808, -78.96191 1.71855... -880 18 0.013159
1 POLYGON ((-78.87208 1.62808, -78.87208 1.71855... -879 18 0.032135
2 POLYGON ((-78.78225 1.53761, -78.78225 1.62808... -878 17 0.002659
3 POLYGON ((-78.69242 1.53761, -78.69242 1.62808... -877 17 0.047470
4 POLYGON ((-78.60259 1.17576, -78.60259 1.26622... -876 13 0.009403
... ... ... ... ...
3838 POLYGON ((-66.92449 1.53761, -66.92449 1.62808... -746 17 0.010076
3839 POLYGON ((-66.92449 1.62808, -66.92449 1.71855... -746 18 0.007051
3840 POLYGON ((-66.83466 1.26622, -66.83466 1.35668... -745 14 0.018678
3841 POLYGON ((-66.83466 1.35668, -66.83466 1.44714... -745 15 0.005428
3842 POLYGON ((-66.83466 1.44714, -66.83466 1.53761... -745 16 0.002426

3843 rows × 4 columns

The column Bosque_Fragmentado_con_Vegetacion_Secundaria contains the (fractional) area of the ecosystem in each grid cell.

Sum up the areas of each grid cell to get the total area.

if has_data:
    total_area = gdf[ecosystem_column].sum()
    display(total_area)
np.float64(100.9777061013306)

Calculate cumulative area

  1. Arrange grid cells in ascending order based on their area (smaller first). Calculate accumulated sum of area per cell (cumulative area).
if has_data:
    gdf = gdf.sort_values(by=ecosystem_column)
    gdf["cumulative_area"] = gdf[ecosystem_column].cumsum()
    display(gdf)
geometry grid_col grid_row Bosque_Fragmentado_con_Vegetacion_Secundaria cumulative_area
549 POLYGON ((-76.71613 4.52643, -76.71613 4.61715... -855 50 1.223524e-09 1.223524e-09
324 POLYGON ((-77.16528 6.43418, -77.16528 6.52518... -860 71 4.068595e-08 4.190947e-08
2573 POLYGON ((-73.03303 5.1617, -73.03303 5.2525, ... -814 57 4.134816e-07 4.553910e-07
460 POLYGON ((-76.89579 2.98573, -76.89579 3.07629... -857 33 1.523100e-06 1.978491e-06
3634 POLYGON ((-69.7991 1.89951, -69.7991 1.99, -69... -778 21 1.704989e-06 3.683480e-06
... ... ... ... ... ...
1335 POLYGON ((-75.18899 4.98013, -75.18899 5.07091... -838 55 2.219789e-01 9.993306e+01
1110 POLYGON ((-75.63815 1.62808, -75.63815 1.71855... -843 18 2.255477e-01 1.001586e+02
2607 POLYGON ((-73.03303 11.1008, -73.03303 11.1929... -814 122 2.358833e-01 1.003945e+02
2717 POLYGON ((-72.85337 8.8061, -72.85337 8.89759,... -812 97 2.397482e-01 1.006342e+02
1040 POLYGON ((-75.81781 4.16367, -75.81781 4.25434... -845 46 3.434625e-01 1.009777e+02

3843 rows × 5 columns

Calculate cumulative proportion

  1. Calculate cumulative proportion by dividing cumulative area by total area (cumulative proportion takes values between 0 and 1)
if has_data:
    gdf["cumulative_proportion"] = gdf["cumulative_area"] / total_area
    display(gdf)
geometry grid_col grid_row Bosque_Fragmentado_con_Vegetacion_Secundaria cumulative_area cumulative_proportion
549 POLYGON ((-76.71613 4.52643, -76.71613 4.61715... -855 50 1.223524e-09 1.223524e-09 1.211678e-11
324 POLYGON ((-77.16528 6.43418, -77.16528 6.52518... -860 71 4.068595e-08 4.190947e-08 4.150369e-10
2573 POLYGON ((-73.03303 5.1617, -73.03303 5.2525, ... -814 57 4.134816e-07 4.553910e-07 4.509818e-09
460 POLYGON ((-76.89579 2.98573, -76.89579 3.07629... -857 33 1.523100e-06 1.978491e-06 1.959334e-08
3634 POLYGON ((-69.7991 1.89951, -69.7991 1.99, -69... -778 21 1.704989e-06 3.683480e-06 3.647816e-08
... ... ... ... ... ... ...
1335 POLYGON ((-75.18899 4.98013, -75.18899 5.07091... -838 55 2.219789e-01 9.993306e+01 9.896547e-01
1110 POLYGON ((-75.63815 1.62808, -75.63815 1.71855... -843 18 2.255477e-01 1.001586e+02 9.918884e-01
2607 POLYGON ((-73.03303 11.1008, -73.03303 11.1929... -814 122 2.358833e-01 1.003945e+02 9.942244e-01
2717 POLYGON ((-72.85337 8.8061, -72.85337 8.89759,... -812 97 2.397482e-01 1.006342e+02 9.965986e-01
1040 POLYGON ((-75.81781 4.16367, -75.81781 4.25434... -845 46 3.434625e-01 1.009777e+02 1.000000e+00

3843 rows × 6 columns

Count AOO cells

  1. Calculate AOO by counting the number of cells with a cumulative proportion greater than 0.01 (i.e. exclude cells that in combination account for up to 1% of the total mapped extent of the ecosystem type).
if has_data:
    aoo = len(gdf[gdf["cumulative_proportion"] > 0.01])
    print(f'AOO is {aoo} cells')
AOO is 3294 cells

AOO Calculation (direct call)

if has_data:
    aoo_count = ecosystem.aoo
    print(f'AOO: {aoo_count} grid cells')
AOO: 3294 grid cells

Criterion B Summary

Criterion B status (spatial)
Least Concern (LC) — Bosque Fragmentado con Vegetacion Secundaria (Bosque Fragmentado con Vegetacion Secundaria), index 31

Status reflects the spatial thresholds for EOO (B1) and AOO (B2) only. A final listing under B1/B2 additionally requires at least one of: (a) an observed or inferred continuing decline; (b) threatening processes likely to cause continuing decline within 20 years; or (c) few threat-defined locations — none of which are derived from the spatial metrics.

Sub-criterion Metric Value Category
B1 EOO 1543318 km² Least Concern (LC)
B2 AOO 3294 cells Least Concern (LC)
Overall B — — Least Concern (LC)