# FIRMS active-fire ingest The FIRMS plugin (`tracking.models.firms.FirmsPlugin`) pulls NASA FIRMS VIIRS 375 m active-fire detections for one FIRMS region. It records each detection inside the plugin's spatial feature group as an observation and, for qualifying detections, raises a `firms_rep` event. `tracking.tasks.schedule_firms_plugins` schedules the plugins (see [celery_schedule](../architecture/celery_schedule.md)). The `firms` management command runs every plugin by hand. Each run reads two NRT day files from the Earthdata archive (`nrt3.modaps.eosdis.nasa.gov`): yesterday's and today's (UTC). NASA keeps rewriting yesterday's file for hours after midnight. ## Satellite products | `firms_product` | Archive folder | File name pattern | Status | |-----------------|-----------------------|----------------------------------------------------------|--------------------------------------------| | `noaa-20` | `noaa-20-viirs-c2` | `J1_VIIRS_C2__VJ114IMGTDL_NRT_.txt` | **Default** | | `noaa-21` | `noaa-21-viirs-c2` | `J2_VIIRS_C2__VJ214IMGTDL_NRT_.txt` | Supported | | `suomi-npp` | `suomi-npp-viirs-c2` | `SUOMI_VIIRS_C2__VNP14IMGTDL_NRT_.txt` | End of life: no new data after 2026-11-02 | We verified these folders, prefixes and product tokens against the live archive on 2026-11-16. That check covered NASA's public directory listing and authenticated downloads of NOAA-20 and NOAA-21 files. All three products publish the same 13-column header: ``` latitude,longitude,bright_ti4,scan,track,acq_date,acq_time,satellite,confidence,version,bright_ti5,frp,daynight ``` The `satellite` column holds `N` (Suomi NPP), `N20` (NOAA-20) or `N21` (NOAA-21). **Suomi NPP is retired.** NASA stopped delivering new Suomi NPP science data at 15:40 UTC on 2026-11-02. The last Suomi NRT day file is `2026306`, and later days return 404. NOAA-20 and NOAA-21 carry the same VIIRS sensor in the same orbital plane, about 50 minutes apart. `suomi-npp` can still be selected, but each run against it logs a warning that names the end-of-life date. ## `additional` options All options live in the plugin's existing `additional` JSON, so none of them needs a migration. If a value is invalid, the run stops with a configuration error before any request is sent. | Key | Default | Meaning | |-----------------------------------|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `firms_product` | `"noaa-20"` | Satellite product to read: `noaa-20`, `noaa-21` or `suomi-npp`. The default applies only when the key is absent; any value present, including `""`, `null` or `false`, must name a product or the run stops with a configuration error. | | `accepted_processing_levels` | `["NRT"]` | Non-empty list of processing levels to ingest, matched case-insensitively against the suffix of the `version` column (`2.0NRT` → `NRT`). FIRMS publishes the same detection as URT (~60 s), RT (~60 min) and NRT (~3 h). | | `accept_unknown_processing_level` | `false` | Whether to ingest rows whose `version` has no recognisable level. Either way, those rows are counted, and each distinct value is logged once per run. | | `dedupe_location_precision` | `3` | Decimal places (0–7) that set the de-duplication cell: new events are stored at the reported position rounded to this many places, and a detection within one cell (10^-N degrees on each axis) of an existing incident at the same acquisition time is treated as that incident. 3 places is about 110 m: enough to absorb an intraday geolocation revision, while keeping adjacent 375 m pixels apart. | | `confidence_alert_levels` | `["nominal", "high"]` | List of confidence values that raise an event. It must be a JSON list of strings; a bare string is rejected. An empty list ingests observations without raising events. | | `alert_window` | 24 hours | Only detections newer than this raise an event (unchanged). | The plugin writes and manages one more key itself. Do not edit it by hand. - `firms_cursors`: `{product: {day_index: {etag, offset, prefix_sha256, columns}}}`. For each product and each day, it records how far the plugin has read. `offset` always points just past the last complete line. Only yesterday and today are kept. ## How a resume works - Each request for a day file carries the Earthdata token. It also carries `If-None-Match`, but only when the cursor for that file is complete: an etag, a positive offset, a `prefix_sha256` and the header columns. It never carries `Range` or `If-Range`. - `304` means the file is unchanged. Nothing is read, and the cursor is kept. - `200` carries the whole file. The plugin compares the first `offset` bytes (and the header columns) against the cursor's `prefix_sha256`: - If they match, the file was only appended to, and parsing resumes at the cursor, so earlier rows are not ingested twice. - If they don't match, the file was rewritten. It is re-read from the start, and the run counts a `resume_reset`. - An incomplete cursor (no usable offset, `prefix_sha256` or columns) sends no `If-None-Match`. So even an unchanged file is re-read in full, rather than skipped with a `304`, and the cursor is replaced by a complete one. - **Why no byte ranges.** The archive ignores `If-Range`, and its etag changes on every append, so a partial (`206`) body could never be validated against the cursor. It would always be discarded and followed by a full download. The cost of this protocol is one conditional request per unchanged file, and one full download per changed file. - A half-written trailing record is never parsed. It is read on a later cycle, once it is complete. - Fields are parsed by header name. A line with the wrong number of fields, or an unparseable value, is skipped with a warning and counted. A file whose header lacks `latitude`, `longitude`, `acq_date` or `acq_time` is skipped with an error. That file's cursor is left untouched, and the other file is still read. - The day being read comes from the plugin's own cursor keys, not from response headers. A `304` or `404` on one file leaves the other file's cursor alone. - An HTML response (Earthdata redirects an unauthenticated request to its login page) logs an error naming the `app_key`, and leaves the cursor unchanged. - `304` is the only "no new data" answer, and `404` is counted in `files_not_found`. Any other status, including a `206` or `416`, is logged with its code and URL, and its body is never parsed. The cursor is left unchanged. `401`/`403` are logged as errors pointing at the `app_key`; everything else as a warning. Each is counted in `fetch_errors`, as is the HTML login page. - `acq_time` must be `HH:MM` (the archive) or `HHMM` (the public CSVs), with a valid hour and minute. Any other shape makes the line malformed. ## De-duplication Before creating an event, the plugin looks for an existing FIRMS event in the tenant with the same event type, acquisition time and provenance, located within one cell of the reported position. The cell is 10^-`dedupe_location_precision` degrees on each axis, 0.001° by default. A hit means the detection is already an incident, and it is counted in `events_deduplicated`. That covers: - a revision whose coordinates NASA changes during the day, even when the change crosses a rounding boundary (for example `-18.90049` → `-18.90051`); - incidents recorded before this change, which were stored at full precision. The lookup is a bounding box on `Event.location`, a geometry in SRID 4326, so the cell is in degrees. A degree of longitude shrinks towards the poles, so at high latitude the box only gets narrower in metres. It can never merge detections that would stay apart at the equator. Adjacent 375 m VIIRS pixels are about 0.0034° apart at the equator, and further apart in longitude at higher latitudes, so neighbouring pixels at the same acquisition time remain separate incidents. A box straddling the antimeridian does not wrap. New events are stored at the reported position rounded to `dedupe_location_precision` places. The full-precision reported coordinates are kept on the observation, and in the event's `event_details` as `reported_latitude` / `reported_longitude`. ## Run summary Every run ends with a single INFO line, `Finished FIRMS Plugin. region-name=… product=…`, followed by these counters (also attached as structured `extra` fields): - `files_read`: day files fetched and parsed, including ones with no new rows - `records_read` - `skipped_processing_level` - `unknown_processing_level` - `malformed_lines` - `header_errors` - `resume_resets` - `files_not_found` - `fetch_errors`: day files that could not be fetched (HTTP errors, connection errors, the login page) - `unexpected_errors`: 1 if the run stopped on an unexpected error part-way - `outside_area` - `events_created` - `events_deduplicated` For a backfill run, `backfill=..` comes before the counters. ## Backfilling missed days The `firms` management command runs every FIRMS plugin in one tenant. `--backfill-days N` makes it re-read the day files from N days before today through today, oldest first. ```bash cd das python manage.py firms --tenant_domain --backfill-days N ``` Example: on 2026-11-16, recovering everything since Suomi NPP stopped on 2026-11-02 (day `2026306`): ```bash python manage.py firms --tenant_domain --backfill-days 14 ``` That reads 15 day files, `2026306` through `2026320`, for each plugin's product (NOAA-20 unless `firms_product` says otherwise). - **Limits.** N must be a whole number from 1 to 60. The archive keeps today's file plus the 60 before it (checked on 2026-11-16 across products and regions), and anything larger is rejected before any plugin runs. A day missing from the archive (404) is logged, counted in `files_not_found` and skipped. The rest of the backfill goes on. - **Same filters as a normal run.** Product selection, processing levels, the spatial feature group and `confidence_alert_levels` all apply unchanged. - **Events.** A normal run only raises events inside `alert_window` (24 h by default). A backfill widens that window back to 00:00 UTC on its first day, so sites get the incidents they missed. See the notification caveat below. - **Resume state.** Every backfilled day is read in full, without `If-None-Match`. Cursors are written only for yesterday and today. Each is written as if that file had just been read for the first time, so the next scheduled run resumes normally. If yesterday's or today's file is missing or unusable, its existing cursor is kept. No cursor is ever written for an older day. - **Re-running is safe.** Observations are keyed on Source and acquisition time, and events are matched within one de-duplication cell at the same acquisition time (see [De-duplication](#de-duplication)). A second backfill over the same days creates nothing new; its events show up as `events_deduplicated`. A `suomi-npp` backfill over days the old code already ingested matches those full-precision incidents in the same way, so it creates no duplicates either. - **Which plugins.** A backfill runs only the tenant's *enabled* FIRMS plugins (`status = enabled`, the same rule the scheduled task uses). Each disabled plugin is reported by region and left completely alone: no request, no Source, no cursor change, and no event-type upgrade on its account. If the tenant has no enabled FIRMS plugin, the command says so and does nothing. A plain `firms` run, without `--backfill-days`, still runs every plugin, disabled ones included. - **Output and exit status.** After each plugin runs, the command writes its run summary to stdout: `FIRMS plugin '': region-name=… product=… [backfill=…] `. Every plugin is attempted. The command then exits non-zero, naming each affected plugin, its region and the counts, if any plugin: - had a configuration error (reported on stderr, plugin not run); - raised an unexpected exception (reported on stderr with the plugin's name; the remaining plugins still run); - had a day file that failed to fetch (`fetch_errors`) or had an unusable header (`header_errors`), even if other days were ingested; - stopped on an unexpected error part-way through the run (`unexpected_errors`); - in a backfill, read no day file at all, for example because every day returned 404. A run is still a success, exiting 0, when every file answered `304` (normal run), when some backfill days are missing but others were read, or when no row fell inside the spatial feature group. The scheduled task does not use this exit status; it only logs the summary. - **Cancelling.** Ctrl-C (`KeyboardInterrupt`) or `SystemExit` during a plugin's run stops the whole command. - The remaining plugins are not started, and no summary is printed for the cancelled plugin. - The cancelled plugin's cursors are not saved. Observations and events already recorded stay, and the next run re-reads yesterday's and today's files idempotently. - **Concurrency.** The command does not take the scheduled task's run-once lock. If the scheduled task runs the same plugin at the same moment, whichever saves last wins `additional.firms_cursors`. Both write valid cursors, so the worst case is one extra re-read. ### Caveats - **Notifications.** Every backfilled event is created exactly like a live one, and nothing in the event pipeline looks at how old an event is: - **Alert rules.** `activity/signals.py` (`event_post_save`) queues `evaluate_alert_rules` for each new event. `evaluate_event` (`activity/alerting/service.py`) selects the active `firms_rep` alert rules whose schedule matches the *current* time, not the event's, and whose conditions match the event. In this release, alert rules have no per-rule trigger setting: every selected rule notifies when an event is created (`activity/tasks.py`, `evaluate_conditions_for_sending_alerts` → `evaluate_notifications`), and no rule can opt out. - **Alert rate limit.** Each recipient may receive `alert_rate_limit` alerts (20 by default) per 24 h (`activity/alerting/rate_limit.py`). A large backfill can exhaust that quota, which blocks that user's alerts for *any* event type until the window resets. - **Realtime.** Each new event is published as `das.event.new` and pushed to every connected client (`rt_api/tasks.py`). - **Webhooks.** Active event webhooks deliver the backfilled events, because `created_at`/`updated_at` are the time of the backfill run (`activity/webhooks/tasks.py`). EarthRanger has no built-in way to suppress notifications for a backfill. To avoid them, an administrator can deactivate the tenant's `firms_rep` alert rules before the backfill. Reactivate them only once the queued alert evaluations have drained, and remember that live fire alerts are suppressed for that period too. - **New Source.** NOAA detections land on the product-qualified Source (for example `Southern_Africa-noaa-20`), not the old Suomi NPP Source. See the migration notes below. - **Overlap on 2026-11-02.** Suomi NPP delivered data until 15:40 UTC that day, so its events cover part of it. The same fire can then appear once from Suomi NPP and once from NOAA-20. The two satellites pass about 50 minutes apart, so their detections have different acquisition times and never de-duplicate against each other. ## Migration notes (ERA-13999, deployed after 2026-11-16) - **The default product changes from Suomi NPP to NOAA-20.** Every existing plugin has had no new Suomi data since 2026-11-02. With no `additional` change, each one recovers on its first run after deploy. - **A new Source is created.** Each product gets its own Source. A `suomi-npp` Source keeps its bare region name as `manufacturer_id` (for example `Southern_Africa`), so existing Sources are untouched. NOAA Sources are qualified by product: `Southern_Africa-noaa-20`, model name `VIIRS NOAA-20`. So the first run after deploy creates a new Source and SourcePlugin for each plugin. Historic Suomi observations stay on the old Source. Re-point anything bound to the old Source at the new one, such as a subject assignment. - **First run backfills.** The first NOAA-20 run reads yesterday's and today's NOAA-20 files in full. Qualifying detections inside `alert_window` (24 h by default) raise events, so sites get their first fire events since Suomi NPP stopped. - **Legacy cursors are discarded.** The old cursor is `additional.stored_headers`: raw Suomi response headers whose `content-length` served as the offset. The first run removes it and never applies it as a byte offset, to any product. A plugin configured for `suomi-npp` re-reads its window from the start, which is safe because observation writes are idempotent. Since 2026-11-02 that window only returns 404s. - **RT and URT rows are now excluded** by default. Set `accepted_processing_levels` to include them. - **Event locations are rounded** to `dedupe_location_precision` places (3 by default). Use `reported_latitude` / `reported_longitude` in `event_details` for the exact position. - **Stricter `additional` validation.** `firms_product` must be a string naming a product. `confidence_alert_levels` must be a list of strings. A plugin whose `additional` holds, for example, `"confidence_alert_levels": "nominal"` ran before, matching by substring. Now it stops with a configuration error, logged by the scheduled task and reported by the `firms` command, until the value is a list such as `["nominal"]`. - **Event-type schema (V2 only).** The `firms_rep` V2 schema now declares `reported_latitude` and `reported_longitude`. A new tenant gets them when the type is created. An existing tenant's V2 `firms_rep` gains them the first time FIRMS runs for that tenant after deploy. That happens through `ensure_firms_event_type()`, which both the scheduled task and the `firms` command call before each plugin runs, so a backfill upgrades the type before it creates events. Tenants without a FIRMS plugin are not touched. - **Additive only.** Each field is added only if the schema doesn't already declare it or list it on the form. It goes right after `track` (or after `reported_latitude` for the longitude), in the section that holds that field, or else at the end of `section-1`. Everything a site has retitled, added or reordered is kept. Once both fields are present, nothing is written. A site that deletes one of the two fields gets it back on the next run. - **Recorded as an edit.** The write goes through `EventTypeSchemaService` and the event type's own save, inside the tenant's context. It records an event-type revision and bumps `updated_at`, so sync clients using `updated_since` and ETags see the change. - **V1 `firms_rep` types are left unchanged.** On those, the two values are in the event's API data but not on its form. - **Existing events are unaffected.** Events recorded before the upgrade lack the two fields. They still validate, because neither field is required, and they still render. The `event_details_view` reporting view only picks up the new columns when an administrator recreates it from the admin.