Skip to content

Scoring

limen_core.scoring

Deterministic V1 scoring engine.

Exposes a stable interface so the V2 ML model (later prompt) can be a drop-in replacement: :func:score takes a fully-assembled :class:CellFeatureBundle and returns a :class:RiskScore — no I/O, no LLM, no network. Assembling the bundle from DB/cache is a separate concern (Phase 4).

MultiFactorScoringEngine

Bases: ScoringEngine[ComponentBreakdown]

Stateless engine bound to a :class:RegionalThresholds.

is_rescued_by_floor

is_rescued_by_floor(bundle: CellFeatureBundle) -> bool

Issue #20 — pure predicate: does this cell cross the permissive rain floor (T2) with enough antecedent wetness to warrant scoring?

True ⇒ the national tiering step MUST evaluate this cell even if its susceptibility tier is low, so an exceptional rain event on a cell with an incomplete IFFI inventory is never missed in silence. False when no rain_floor block is configured (backward-compatible: no rescue).

Conditioned on the soil-moisture sigmoid: identical rain rescues a saturated cell but not a dry one. No DB, no network — safe to call for every candidate cell before the meteo budget is spent.

score

score(bundle: CellFeatureBundle) -> RiskScore[ComponentBreakdown]

Score one cell at one moment. Pure, deterministic.

V1.5: when the bundle carries a :class:SensorFeatures and a YAML kinematic block is configured, K is computed and the top-level weights are renormalised so w_K + (scaled S/M/E/F/H) = 1. With no sensor features (or no YAML block), the score is byte-for-byte identical to V1.

RegionalThresholds

Bases: HazardThresholds

Landslide configuration — strict validation, immutable.

macroregion_for

macroregion_for(aoi_id: str) -> str

La curva da usare per questa AOI.

score

score(bundle: CellFeatureBundle, *, thresholds: RegionalThresholds | None = None) -> RiskScore[ComponentBreakdown]

Functional convenience wrapper around :class:MultiFactorScoringEngine.

load_regional_thresholds

load_regional_thresholds(path: Path | str | None = None) -> RegionalThresholds

Landslide thresholds, typed for the landslide engine.

limen_core.scoring.engine

MultiFactorScoringEngine — the V1 deterministic risk engine.

Pure function from :class:CellFeatureBundle to :class:RiskScore. No I/O. No LLM. No network. The bundle assembler — fed by the DB, the caches, and the integration clients — is a separate concern (Phase 4).

The aggregation is the §2.4 weighted linear combination:

S(c) = w_susc · norm(susc_ISPRA) + w_iffi · norm(iffi_density)
     + w_slope · norm(slope) + w_pai · norm(PAI) + w_litho · litho_weight
M(c,t) = w_caine · norm(caine_excess) + w_api · api_factor
       + w_soil · soil_factor
risk = w_S · S + w_M · M + w_E · E + w_F · F + w_H · H

with five-class classification using the cutoffs in :class:ClassCutoffs. H is the ISPRA Mosaicatura Idraulica flood class (Phase 12+); cells without a populated flood_hazard_norm keep the V1 baseline H = 0.

MultiFactorScoringEngine

Bases: ScoringEngine[ComponentBreakdown]

Stateless engine bound to a :class:RegionalThresholds.

is_rescued_by_floor

is_rescued_by_floor(bundle: CellFeatureBundle) -> bool

Issue #20 — pure predicate: does this cell cross the permissive rain floor (T2) with enough antecedent wetness to warrant scoring?

True ⇒ the national tiering step MUST evaluate this cell even if its susceptibility tier is low, so an exceptional rain event on a cell with an incomplete IFFI inventory is never missed in silence. False when no rain_floor block is configured (backward-compatible: no rescue).

Conditioned on the soil-moisture sigmoid: identical rain rescues a saturated cell but not a dry one. No DB, no network — safe to call for every candidate cell before the meteo budget is spent.

score

score(bundle: CellFeatureBundle) -> RiskScore[ComponentBreakdown]

Score one cell at one moment. Pure, deterministic.

V1.5: when the bundle carries a :class:SensorFeatures and a YAML kinematic block is configured, K is computed and the top-level weights are renormalised so w_K + (scaled S/M/E/F/H) = 1. With no sensor features (or no YAML block), the score is byte-for-byte identical to V1.

score

score(bundle: CellFeatureBundle, *, thresholds: RegionalThresholds | None = None) -> RiskScore[ComponentBreakdown]

Functional convenience wrapper around :class:MultiFactorScoringEngine.

limen_core.scoring.flood.engine

Deterministic flood engine (#63).

score = susceptibilità × max(pluviale, fluviale)

A maximum, not a sum. The two triggers are different ways for the same cell to end up under water; a cell is not more flooded because both could happen. Whichever is worse is what an operator has to plan for, and summing them would let two moderate signals invent a severe one.

Susceptibility multiplies rather than adds, unlike the wildfire engine's base term. There is no equivalent of "fire arrives from outside": water goes downhill, so a cell that the hydraulic mosaic puts on high ground does not flood however hard it rains next door. Below susceptibility.floor the engine short-circuits to zero.

La cascata incendio → alluvione (#58) entra qui e non dopo il motore: un suolo percorso dal fuoco è idrofobico, quindi la stessa pioggia scorre invece di infiltrarsi. È fisica del ramo pluviale, e applicarla come correzione a punteggio già calcolato lascerebbe score e breakdown a raccontare due cose diverse. Il moltiplicatore finisce nel breakdown, così un operatore vede di quanto e perché.

Amplifica il solo ramo pluviale: un incendio a valle non fa crescere un fiume a monte.

Pure: no DB, no network, no LLM. La suscettibilità viene dal mosaico idraulico ISPRA già normalizzato per cella, i due segnali dinamici li recupera il workflow, e i mesi dall'incendio arrivano da FireCheck — che gira in ogni workflow, quindi la cascata non ha bisogno di uno sweep in più.

FloodScoringEngine

Bases: ScoringEngine[FloodBreakdown]

ScoringEngine[FloodBreakdown] — the V1 baseline for flood.

limen_core.scoring.wildfire.engine

Deterministic wildfire engine (#61).

score = fwi_norm × (w_base + w_fuel · fuel + w_slope · slope)

The terrain modulates the weather rather than adding to it. Three independent things have to be true at once for a cell to be dangerous: the weather has to be right for fire, there has to be something to burn, and the slope has to let it run -- but the weather is the gate. A sum would give a conifer forest a weather-independent floor, so it would read "Moderate" under a January downpour, which is physically false.

w_base is why this is not a plain product: it is the share of the danger a cell carries because fire arrives from outside it, so bare rock in extreme fire weather still scores. The three weights sum to 1, which makes a maximally flammable, maximally steep cell score exactly its normalised FWI -- that is what keeps the class cutoffs readable as EFFIS danger bands.

Pure, like the landslide engine: no DB, no network, no LLM. The recursive FWI codes arrive already advanced in bundle.dynamic.fire_weather -- persisting and stepping them is the workflow's job, not the engine's.

WildfireScoringEngine

Bases: ScoringEngine[WildfireBreakdown]

ScoringEngine[WildfireBreakdown] — the V1 baseline for wildfire.