Skip to content

Wildfires: the fire inside its perimeter

limen_core.wildfire

The fire seen by satellite inside its burnt perimeter: how hard it burnt.

The wildfire join. effis-client gives the burnt perimeters, with the day the fire started and the area EFFIS states; firms-client gives the fires the satellites saw, each with its fire radiative power (FRP, in MW). Neither knows the other. Here a perimeter takes the detections that fell inside it around its day, and their power over its area is how hard it burnt: the severity :mod:limen_core.post_fire turns into a factor.

The rule is Limen's (fire_events_repo, the SQL it replaces): a detection counts when it is a vegetation fire (type 0), carries a power, falls within window_days days of the fire's date, and lies inside the perimeter or on its edge.

Three things are kept, on purpose:

  • Not measured stays not measured. A perimeter with no detection that counts has no power and no density: None, never 0 (a burn the satellite missed is not a weak burn). A perimeter with no date, or no area, has no density either.
  • One layer at a time. EFFIS serves two lists of burnt areas that do not count the same fires (nrt.ba.poly lists heat that is not burnt vegetation, lava included; ms:modis.ba.poly misses only small fires). A perimeter carries the name of its layer, and :func:seen_inside_all refuses to mix two.
  • No geometry library. The perimeter is a GeoJSON Polygon or MultiPolygon in longitude and latitude, holes included; a point is inside by the even-odd rule, and on an edge counts as inside.

The second question is per cell of a grid: when did it last burn, and how hard? :func:latest_fire answers it from what touched the cell, the perimeters and the confirmed days of FIRMS detections, with the rule of Limen's fire_check (the decision after its query; the spatial join stays in SQL, where the index is).

Pure functions, no I/O.

Detection dataclass

One fire the satellite saw: where, which day (UTC), its power and its type.

Perimeter dataclass

One burnt perimeter: its GeoJSON geometry, its day, its area and its layer.

FireSeen dataclass

What the satellite saw inside one perimeter around its day.

detection_of

detection_of(hotspot: _HotspotLike) -> Detection

A :class:Detection from anything shaped like firms_client.Hotspot.

perimeter_of

perimeter_of(feature: Mapping[str, Any], attributes: _AttributesLike, *, layer: str) -> Perimeter | None

A :class:Perimeter from an EFFIS GeoJSON feature and what it says about itself.

attributes is anything shaped like effis_client.PerimeterAttributes (effis_client.perimeter_attributes(feature)). None when the feature has no id or no (Multi)Polygon geometry.

contains

contains(geometry: Mapping[str, Any], lon: float, lat: float) -> bool

Whether (lon, lat) is inside a GeoJSON (Multi)Polygon or on its edge.

seen_inside

seen_inside(perimeter: Perimeter, detections: Iterable[Detection], *, window_days: int) -> FireSeen | None

What the satellite saw inside one perimeter; None when it has no date.

seen_inside_all

seen_inside_all(perimeters: Iterable[Perimeter], detections: Iterable[Detection], *, window_days: int) -> list[FireSeen]

:func:seen_inside for many perimeters, in their order; the undated are left out.

The detections are indexed by day once, so the cost grows with the perimeters and the detections of their days, not with their product. Raises ValueError when the perimeters come from more than one layer.

latest_fire

latest_fire(perimeters_by_cell: Mapping[K, Iterable[tuple[date, float | None]]], detection_days_by_cell: Mapping[K, Iterable[date]], detections_per_day: Mapping[date, int], *, min_hotspots: int, as_of: date, window_months_max: float, severity: Callable[[float], float | None]) -> dict[K, tuple[float, float | None]]

When each cell last burnt, and how hard: {cell: (months_since_fire, severity)}.

Two sources, the newest wins:

  • perimeters_by_cell: for each cell, the burnt perimeters that touch it, as (fire_date, frp_density_mw_per_ha); the density is None when not measured;
  • detection_days_by_cell: for each cell, the days FIRMS detections of vegetation fires (type 0) fell in it. A day counts only when it is confirmed: detections_per_day has at least min_hotspots detections of type 0 for it over the whole area (the region, not the cell), because a single point can be a glint.

Dates after as_of are not read. The months are the days since the fire over 30, never negative; a cell whose newest fire is more than window_months_max months old is left out, as is a cell nothing touched.

The severity exists only when a perimeter is the newest fire of the cell (a detection on the same day as the perimeter does not take it away): a FIRMS fire with no perimeter has no area to divide by. It is severity(density), or None when the density is not measured. Of two perimeters of the same newest day the denser one is read: Limen's SQL took either, which made the answer depend on the order of the rows.