Constants API

The constants module provides lookup tables and mappings loaded from the official BNG metric data files.

Habitat Mappings

bngmetric.constants.HABITAT_TYPE_TO_ID: dict[str, int]

Maps habitat type names to unique integer IDs for JAX array indexing.

from bngmetric.constants import HABITAT_TYPE_TO_ID

habitat_id = HABITAT_TYPE_TO_ID['Grassland - Lowland meadows']
bngmetric.constants.HABITAT_DISTINCTIVENESS_MAP: dict[str, float]

Maps habitat type names to their distinctiveness scores.

bngmetric.constants.ID_TO_DISTINCTIVENESS_VALUE: jax.Array

JAX array of distinctiveness values indexed by habitat ID.

Condition Mappings

bngmetric.constants.CONDITION_CATEGORY_TO_ID: dict[str, int]

Maps condition category names to integer IDs.

from bngmetric.constants import CONDITION_CATEGORY_TO_ID

condition_id = CONDITION_CATEGORY_TO_ID['Good']  # Returns 0
bngmetric.constants.CONDITION_MULTIPLIERS_MATRIX: jax.Array

2D JAX array of condition multipliers. Shape: (n_habitats, n_conditions)

Usage:

multiplier = CONDITION_MULTIPLIERS_MATRIX[habitat_id, condition_id]

Creation Multipliers

bngmetric.constants.CREATION_MULTIPLIERS_MATRIX: jax.Array

2D JAX array of time-to-target years for habitat creation. Shape: (n_habitats, n_conditions) NaN values indicate disallowed combinations.

bngmetric.constants.CREATION_RISK: jax.Array

1D JAX array of difficulty multipliers for habitat creation. Indexed by habitat ID.

bngmetric.constants.TEMPORAL_MULTIPLIER_LOOKUP: jax.Array

1D JAX array converting years to temporal multipliers. Index by year to get the multiplier.

Enhancement Multipliers

bngmetric.constants.CONDITION_ENHANCEMENT_TEMPORAL: jax.Array

3D JAX array of years for condition enhancement. Shape: (n_habitats, n_conditions, n_conditions) Index: [habitat_id, start_condition_id, target_condition_id]

bngmetric.constants.DISTINCTIVENESS_ENHANCEMENT_TEMPORAL: jax.Array

2D JAX array of years for distinctiveness enhancement. Shape: (n_habitats, n_condition_transitions)

bngmetric.constants.ENHANCEMENT_RISK: jax.Array

1D JAX array of difficulty multipliers for enhancement. Indexed by habitat ID.

Spatial Risk Multipliers

bngmetric.constants.SPATIAL_RISK_CATEGORY_TO_ID: dict[str, int]

Maps spatial risk category names to integer IDs.

SPATIAL_RISK_CATEGORY_TO_ID = {
    'Inside LPA/NCA': 0,
    'Neighbouring LPA/NCA': 1,
    'Beyond neighbouring LPA/NCA': 2,
}
bngmetric.constants.SPATIAL_RISK_MULTIPLIERS: jax.Array

JAX array of spatial risk multipliers: [1.0, 0.75, 0.5]

Level 2 Habitat Labels

bngmetric.constants.HABITAT_TO_LEVEL2: dict[str, str]

Maps specific habitat types to their Level 2 broad habitat category.

bngmetric.constants.LEVEL2_TO_ID: dict[str, int]

Maps Level 2 habitat labels to integer IDs.

Usage Example

from bngmetric.constants import (
    HABITAT_TYPE_TO_ID,
    CONDITION_CATEGORY_TO_ID,
    CONDITION_MULTIPLIERS_MATRIX,
    ID_TO_DISTINCTIVENESS_VALUE
)

# Get IDs
habitat_id = HABITAT_TYPE_TO_ID['Grassland - Lowland meadows']
condition_id = CONDITION_CATEGORY_TO_ID['Good']

# Look up values
distinctiveness = ID_TO_DISTINCTIVENESS_VALUE[habitat_id]
condition_multiplier = CONDITION_MULTIPLIERS_MATRIX[habitat_id, condition_id]

print(f"Distinctiveness: {distinctiveness}")
print(f"Condition multiplier: {condition_multiplier}")