Skip to content

Two measures side by side

limen_core.agreement

Two measures of the same thing, side by side: how far apart they are.

Made for the fire weather index: the one computed with fwi-chain next to the official ones (the EFFIS rasters read by effis-client, the Copernicus reanalysis read by glofas-ewds). Each library gives its own numbers; the pairing of the two, and what the difference means, is a join and lives here. It works for any two series of numbers.

:func:pair joins two sets by key (a place and a day, say); :func:compare gives, for each component, the mean difference, the absolute and the squared error, the correlation and, when a classify is given, how often the two fall in the same class and how often ours is above.

It measures agreement, not truth: an official value is a reference, and two models that agree can both be wrong. Pure functions, no I/O.

Agreement dataclass

How one component of ours stands against the reference.

pearson

pearson(xs: Sequence[float], ys: Sequence[float]) -> float | None

Pearson's correlation; None with fewer than three pairs or no variance.

bands

bands(lower_bounds: Sequence[float]) -> Callable[[float], int]

A classify for :func:compare: the rank of the band a value falls in.

lower_bounds are the lower edges of the bands above the lowest, in growing order: a value below the first is in band 0, one at or above the last is in the highest.

pair

pair(ours: Mapping[K, Mapping[str, float | None]], reference: Mapping[K, Mapping[str, float | None]]) -> dict[str, list[tuple[float, float]]]

The pairs (ours, reference) of each component, on the keys both have.

A key is whatever tells two values to be the same thing: a place and a day. A component missing or None on either side gives no pair: not measured is not zero. The pairs follow the order of ours.

compare

compare(pairs: Mapping[str, Sequence[tuple[float, float]]], *, classify: Callable[[float], int] | None = None, classified: Collection[str] = ('fwi',)) -> list[Agreement]

The agreement of each component, in the order of pairs; one with no pairs is left out.

classify turns a value into the rank of its class (0 the lowest): with it, the components named in classified also get same_class and above. The classes are the caller's: the danger classes of a service, or the bands of a score.