Skip to content

refactor(wildfire): the FRP of a perimeter from limen-core's seen_inside_all - #763

Merged
gzileni merged 1 commit into
mainfrom
feat/frp-limen-core
Nov 28, 2026
Merged

gzileni merged 1 commit into
mainfrom
feat/frp-limen-core

Conversation

@gzileni

@gzileni gzileni commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

fire_events_repo.refresh_perimeter_frp no longer computes the severity of a burnt perimeter in SQL. It reads the perimeters of v_fire_perimeters and the FIRMS detections that can count, one year at a time. limen_core.wildfire.seen_inside_all (limen-core 0.4.0, already pinned) applies the rule, and Limen writes the result.

The rule is the same as before: a vegetation detection (type 0) with a power, within 5 days of the fire's date, inside the perimeter or on its edge. The density is the sum over the area, and is NULL when the area is missing or zero.

The numbers do not change. This PR moves who computes them, not what they are. The severity anchors are measured again on the new layer in a separate PR, which moves numbers and is left to the user.

Parity on real rows

Both implementations ran on the same throwaway database:

  • Perimeters: 12,399 of ms:modis.ba.poly, fires from 2016-05-13 to 2026-11-24, loaded with Limen's own run_effis_sync on the 20 region boxes.
  • Detections: 198,235 FIRMS vegetation detections with a power, from 2015 to 2025, loaded with Limen's own fetch_archive_year (MODIS and VIIRS S-NPP, Italy).

Result:

  • the SQL measured 4,831 perimeters, seen_inside_all 4,831;
  • 0 perimeters differ in sum, count or density;
  • 0 perimeters with a power have a missing or zero area.

The 2026 perimeters have no detection here, because the FIRMS archive stops at 2025; in production they come from the NRT feed.

The edge cases, in a test

tests/integration/test_frp_parity.py runs the old SQL (kept as _REFRESH_FRP_SQL_LEGACY) and the new path on the same rows, and fixes the expected values too, so that a mistake shared by both is not taken for parity. The cases:

  • a point on an edge, on a vertex, in a hole and on the edge of the hole;
  • the first and last day of the window, and the first day out;
  • the second part of a MultiPolygon;
  • a perimeter with no area, one with zero area, one with no date;
  • a steelworks detection and one with no power.

Two behaviours that are not the same, on purpose

  • A perimeter that no longer has a detection that counts goes back to NULL. The SQL updated only the perimeters it matched, so an old value could stay after its detections were gone. A test covers it. On a fresh table the two agree, as the parity shows.
  • It writes only where a value changes. updated_at no longer moves on every nightly run, so the fingerprints that read it see a change only when there is one.

Epic

Part of #714 (wildfire)

Type of change

  • Scoring / thresholds (same numbers, computed elsewhere)

Verification

  • ruff, mypy clean.
  • New parity test, existing severity, EFFIS client and fire history integration tests: 25 passed.
  • The real-row parity above.

Risk/scoring impact

None on the values: 0 differences on 4,831 measured perimeters. Memory: one year of detections at a time, about 25,000 rows.

🤖 Generated with Claude Code

…een_inside_all (#714)

refresh_perimeter_frp reads the perimeters of v_fire_perimeters and the
hotspots that can count, one year at a time, lets
limen_core.wildfire.seen_inside_all apply the rule, and writes only where a
value changes. The SQL it replaces stays as _REFRESH_FRP_SQL_LEGACY for the
parity test.

Parity on real rows: 12,399 perimeters of ms:modis.ba.poly (2016-2026) and
198,235 FIRMS vegetation detections (2015-2025), 4,831 perimeters measured
by both, 0 differ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T17:53:20.128675Z 86f5f3d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@gzileni
gzileni merged commit 397bac0 into main Nov 28, 2026
7 checks passed
@gzileni
gzileni deleted the feat/frp-limen-core branch November 28, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant