Skip to content

What the sources say about a cell

The readings an agent quotes next to a risk score: the radar rain of the last day, the landslides mapped nearby, the earthquakes of the last month, the official fire danger, the fires seen from space, the river discharge of GloFAS, the flood activations of Copernicus EMS, the ground motion of EGMS. Each one calls a library's Python function; the libraries have no servers.

pip install "limen-core[evidence]"
from datetime import UTC, datetime

from limen_core.evidence import Cell, gather, plan, render

asks = plan("landslide", [Cell("c1", 16.05, 38.91)], at=datetime.now(UTC))
evidence = await gather(asks, timeout_s=20, budget_s=60)
print(render(evidence))

Some readings need set-up on the machine that runs them; without it they are left out, as a source that is down (and, called one by one, they raise SourceNotConfiguredError with a message saying what to fetch):

Reading Library Needs
river_discharge glofas-ewds a GloFAS store on disk ($DATA_ROOT/glofas-ewds, else ~/.cache/glofas-ewds), filled with the glofas-ewds command line; Open-Meteo needs no key
ground_motion egms-client a CLMS service key in EGMS_SERVICE_KEY (its JSON) or EGMS_SERVICE_KEY_FILE (its path); the first read of a point downloads its L3 tile, about 60 MB, once
ground_motion_before egms-client the L3 CSV of the point's tile with its time series on disk (about 250 MB a tile) in EGMS_DATA_DIR, else $DATA_ROOT/egms-client, else ~/.cache/egms-client, fetched once with egms init --tile E46N19 --component U --keep tiff --keep csv (that needs the CLMS key; reading does not)
flood_activations, flood_activation_summary, flood_water_over_place copernicus-ems nothing: Rapid Mapping is public

Readings asked one by one

Three readings answer a question an agent asks by name, not a step of a plan. Each returns one Evidence (source, reading, arguments, answer, attribution) and raises its failure instead of leaving it out:

from limen_core.evidence import (
    flood_activation_summary,
    flood_water_around,
    flood_water_over_place,
    ground_motion_before,
)

# What the EGMS series of the 1 km cell said before a day: nothing after it is read.
motion = await ground_motion_before(16.05, 38.91, "2025-03-01")

# One Copernicus EMS activation: per product and per AOI.
summary = await flood_activation_summary("EMSR871")

# The water it observed over a place (GeoJSON), or within 3 km of a point.
water = await flood_water_around("EMSR871", 16.49, 40.47, 3.0)

They are in READINGS (ground_motion_before reads as of the Ask's at, or its day parameter; the EMS ones take code, and place or a cell with radius_km), so a plan of one's own can name them, but not in DEFAULT_PLAN: the first needs a day inside the EGMS release (December 2020 to November 2025 for 2020-2025; today reads too_few_acquisitions) and a heavy table on disk, the others an activation code that a plan of cells does not have.

Ground motion before a day is a measure, not a verdict. egms-client leaves the minimums to the caller; limen-core sets conservative defaults, not calibrated, all parameters:

Parameter Default Why
window_days 180 "before" is the last six months: 15 to 30 Sentinel-1 acquisitions
min_points 5 the median of at least five 100 m points of the 1 km cell, not one or two noisy ones
min_acquisitions 10 two thirds of the window at a 12-day revisit
min_history_days 365 a year of series before the window, so the season is not read as a trend (egms-client's floor)
z 2.0 share_changed counts the points whose change is beyond two standard errors

Below a minimum the numbers are null and reasons says why (too_few_points, too_few_acquisitions, too_short_history, not_measured, no_tile). Every answer carries note: nobody has yet measured that a change before a day tells cells with a landslide from the others, and InSAR misses a slope that fails in hours.

limen_core.evidence

What the open-data libraries say about the cells an assessment ranks first.

An agent that explains a risk score is more useful when it can quote what the sources measured around the cells at the top: the rain of the last day from the radar, the landslides mapped nearby, the earthquakes of the last month, the official fire danger. This module asks the libraries directly, through their Python functions, and gives the answers back as :class:Evidence: data, with the source, the question and the attribution.

The libraries have no servers: this is the one place where Limen reaches them for its agents. Each library is an optional dependency (the evidence extra), imported only when one of its readings runs.

Readings. A reading is a named question to one library, such as radar_rain or landslides_near. :data:DEFAULT_PLAN says which readings each hazard asks, of how many cells, with which parameters. A caller can pass its own plan, or its own readings.

Degrading. A source that is down, slow or refuses a question does not stop the others. The reading is logged and left out. Every reading has a timeout, and the readings of one call share a total budget; they run concurrently. A source that needs what this machine does not have (a key, a filled store) raises :class:SourceNotConfiguredError, and is left out the same way.

What needs set-up.

  • river_discharge reads the GloFAS store of glofas-ewds on disk ($DATA_ROOT/glofas-ewds, else ~/.cache/glofas-ewds), filled beforehand with its command line (glofas-ewds; Open-Meteo needs no key). No network here.
  • ground_motion needs a CLMS service key in EGMS_SERVICE_KEY (its JSON) or EGMS_SERVICE_KEY_FILE (its path); the first read of a point downloads its L3 tile once, about 60 MB (kept in EGMS_DATA_DIR, else $DATA_ROOT/egms-client), which a short timeout may not allow.
  • ground_motion_before reads the EGMS L3 table of the point's tile with its time series from disk, offline: no key at read time. The CSV of a tile (about 250 MB) must be fetched beforehand into EGMS_DATA_DIR (else $DATA_ROOT/egms-client, else ~/.cache/egms-client), once: egms init --tile E46N19 --component U --keep tiff --keep csv (that one needs the CLMS key).
  • flood_activations, flood_activation_summary and flood_water_over_place need nothing: Rapid Mapping is public.

Readings for one question. Three readings answer a question an agent asks by name rather than a step of a plan: :func:ground_motion_before (a dated reading of the EGMS series), :func:flood_activation_summary and :func:flood_water_over_place / :func:flood_water_around (one Copernicus EMS activation, by its code). They are in :data:READINGS too, so a caller can put them in its own plan, but not in :data:DEFAULT_PLAN: the first needs a day inside the EGMS release and a heavy table on disk, the others an activation code that a plan of cells does not have.

SourceNotConfiguredError

Bases: RuntimeError

A source this machine cannot read yet: a key that is not set, a store not filled.

Cell dataclass

A cell of the assessment: its id and its centroid in degrees (WGS84).

Ask dataclass

One reading to run: on a cell, or on the whole area when cell is None.

Evidence dataclass

What a library answered to one reading.

Clients

The library clients the readings use, opened on first use and closed together.

Each factory builds an async context manager; the defaults are the libraries' own clients. Tests replace them.

Reading dataclass

A named question to one library.

run gets the clients and the :class:Ask and returns (arguments, answer): what was asked, and the library's answer.

circle

circle(lon: float, lat: float, radius_km: float, *, sides: int = 64) -> dict[str, Any]

A GeoJSON Polygon (lon/lat) of sides vertices about radius_km around a point.

Drawn on the local tangent plane: within a fraction of a percent of the true circle at the sizes allowed (0 < radius_km <= :data:MAX_RADIUS_KM).

plan

plan(hazard: str, cells: Sequence[Cell], *, at: datetime, bbox: BBox | None = None, steps: Sequence[tuple[str, int, Mapping[str, Any]]] | None = None) -> list[Ask]

The readings to run for hazard on cells (the first ones first).

An area reading without a box, or a reading of an unknown hazard, is left out.

gather async

gather(asks: Sequence[Ask], *, clients: Clients | None = None, readings: Mapping[str, Reading] | None = None, timeout_s: float = 20.0, budget_s: float = 60.0, clock: Callable[[], float] = time.monotonic) -> list[Evidence]

The answers to asks, in order, without the ones that failed.

They run concurrently; each has timeout_s and none starts once budget_s has gone by.

read_one async

read_one(name: str, ask: Ask, *, clients: Clients | None = None, readings: Mapping[str, Reading] | None = None) -> Evidence

One reading, as :class:Evidence; unlike :func:gather, its failure is raised.

A source that needs set-up raises :class:SourceNotConfiguredError, a bad argument :class:ValueError, a failing source its own error: a tool that wraps it shows the message to whoever asked.

ground_motion_before async

ground_motion_before(lon: float, lat: float, day: date | datetime | str, *, window_days: int = MOTION_WINDOW_DAYS, min_points: int = MOTION_MIN_POINTS, min_acquisitions: int = MOTION_MIN_ACQUISITIONS, min_history_days: int = MOTION_MIN_HISTORY_DAYS, z: float | None = MOTION_Z, component: Literal['U', 'E'] = 'U', release: str | None = None, include_day: bool = False, directory: Path | str | None = None, clients: Clients | None = None) -> Evidence

What the EGMS series of the 1 km cell around a point said before day.

The cell is the 1 km square of EPSG:3035 holding the point (Limen's grid); its 100 m L3 points are read from the tile's CSV on disk, and :class:egms_client.asof.Series gives velocity_before (the last window_days before the day), velocity_long (from the first acquisition to the start of the window), change, change_z, share_changed (beyond z standard errors) and the counts. Nothing on or after day is read, unless include_day. day is a date, an aware datetime (its UTC day) or ISO text.

The minimums have defaults here (:data:MOTION_MIN_POINTS and the others) because egms-client has none: they are conservative, not calibrated. Too few points or acquisitions give None numbers and reasons. Each answer carries :data:MOTION_NOTE: a measure of the series, not a verdict.

Offline: the tile's CSV must be on disk in directory (default EGMS_DATA_DIR, else $DATA_ROOT/egms-client, else the user cache); without it :class:SourceNotConfiguredError says how to fetch it. A tile the archive does not have (an absent marker) answers no_tile.

flood_activation_summary async

flood_activation_summary(code: str, *, hazard: Literal['flood', 'landslide', 'all'] = 'flood', clients: Clients | None = None) -> Evidence

What one Copernicus EMS activation observed, per product and per AOI.

The answer is copernicus-ems's ActivationSummary: code, name, category, event_time, hazard, products (one row each: product, product_type, aoi_number, aoi_name, observed_time, event_km2, observed_km2, ...), aois (the largest and latest delineation of each) and attribution. Products of one AOI are successive views of one place: never add them up.

flood_water_over_place async

flood_water_over_place(code: str, place: Mapping[str, Any], *, clients: Clients | None = None) -> Evidence

The water one Copernicus EMS activation observed over a place (a GeoJSON in lon/lat).

The answer is copernicus-ems's PlaceWaterRow: covered, place_km2, observed_km2, observed_share, water_km2, water_share_of_observed, observed_from / observed_to, the products used, note and attribution. covered false: no product looked at the place, nothing is known of it; it is not "no water". The part of the place not observed is unknown, not dry.

flood_water_around async

flood_water_around(code: str, lon: float, lat: float, radius_km: float, *, clients: Clients | None = None) -> Evidence

:func:flood_water_over_place over the :func:circle of radius_km around a point.

render

render(evidence: Sequence[Evidence]) -> str

The evidence as a fenced block for a model's message; empty without evidence.

The block says that its content is data, not instructions: a text inside an answer is not a request to the model.