Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# firms-client settings. Copy to .env (never committed) and fill in:
# cp .env.example .env
# The library and the `firms` command read FIRMS_DATA_DIR and FIRMS_MAP_KEY
# The library and the `firms` command read DATA_ROOT and FIRMS_MAP_KEY
# from the environment, else from the .env of the current directory.
# Values with spaces go between quotes.

# --- Data directory --------------------------------------------------------
# The one place every download goes, and is read from: yearly country
# archives, the static-source mask, the WorldCover copy (firms sync
# --worldcover) and sync.json. A relative path is relative to the directory
# you run from. Unset: ~/.cache/firms-client.
FIRMS_DATA_DIR=./data
# The data root shared by the agent-engineering-studio libraries: each one
# keeps its files in its own folder under it, this one in
# $DATA_ROOT/firms-client. Every download goes there and is read from there:
# yearly country archives, the static-source mask, WorldCover (firms init,
# firms sync) and sync.json. A relative path is relative to the directory
# you run from. Unset: ~/.cache/firms-client. (FIRMS_DATA_DIR, if set,
# still overrides it, for compatibility.)
DATA_ROOT=./data

# --- NASA FIRMS MAP_KEY ----------------------------------------------------
# Free, needed only for the near-real-time area API (`firms area`,
Expand All @@ -21,7 +24,7 @@ FIRMS_DATA_DIR=./data
FIRMS_MAP_KEY=

# --- MCP server (extra firms-client[mcp]) ----------------------------------
# Where `export_geojson` may write. Unset: <FIRMS_DATA_DIR>/exports.
# Where `export_geojson` may write. Unset: <data directory>/exports.
# FIRMS_EXPORT_DIR=./data/exports

# --- Bulletins with Claude (extra firms-client[claude]) ---------------------
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ All notable changes to this project are documented here. The format follows
under the fire-days separates the agricultural fires (0.58-0.86) from the
wildfires (0-0.004), where `classify_burning` called three of four
agricultural fires `mixed`. 34 of 41 checks pass in all.
- `init(directory=None, *, country, years, bbox=None, products=, client=None,
retry=None)` -> `InitReport`, and `firms init COUNTRY [--years] [--bbox]`:
download once what working offline needs, the yearly archives and the
whole WorldCover tiles over a box (Italy: 23 tiles, 1.3 GB), with no
rasterio. Idempotent and resumable: files there are skipped, downloads go
to `.part`, a failed file is recorded and the rest goes on. It takes the
caller's client and retries nothing unless asked. `worldcover_tiles`,
`download_worldcover_tile`.

### Changed

- The data directory is `$DATA_ROOT/firms-client`: `DATA_ROOT` is the data
root shared by the agent-engineering-studio libraries, read from the
environment or `.env` (`ENV_DATA_ROOT`). `FIRMS_DATA_DIR` still overrides
it, for compatibility, but is no longer in `.env.example`; with neither,
`~/.cache/firms-client` as before.

## [0.6.0] - 2026-11-25

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test-core: ## pytest on the core alone, without the extras, as CI does
bench: ## Score the known cases offline, as CI does: any change from results.json fails
uv run --all-extras python -m benchmarks.run --check

# The open country archives (~30 MB, once, into FIRMS_DATA_DIR), EFFIS perimeters
# The open country archives (~30 MB, once, into $DATA_ROOT/firms-client), EFFIS perimeters
# and WorldCover windows: no key needed.
bench-data: ## Download and crop the data of the known cases again, then score them
uv run --all-extras python -m benchmarks.fetch
Expand Down
56 changes: 42 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,18 @@ Everything the library downloads goes to **one data directory**, and is
read from there: the yearly archives, the static mask, the WorldCover copy,
`sync.json`. Pass `directory=` to a function to choose another; otherwise:

1. `FIRMS_DATA_DIR` from the environment;
2. else `FIRMS_DATA_DIR` from a `.env` file in the current directory;
3. else `~/.cache/firms-client` (or `$XDG_CACHE_HOME/firms-client`).
1. `$DATA_ROOT/firms-client`: `DATA_ROOT` is the data root the
agent-engineering-studio libraries share, each in its own folder
(`/data/firms-client`, `/data/egms-client`, …);
2. else `~/.cache/firms-client` (or `$XDG_CACHE_HOME/firms-client`).

The MAP_KEY works the same way (`FIRMS_MAP_KEY`, environment or `.env`).
`.env.example` lists every setting:
`DATA_ROOT` is read from the environment, else from a `.env` file in the
current directory. `FIRMS_DATA_DIR`, if set, still overrides it, for
compatibility. The MAP_KEY works the same way (`FIRMS_MAP_KEY`, environment
or `.env`). `.env.example` lists every setting:

```bash
cp .env.example .env # then set FIRMS_DATA_DIR and FIRMS_MAP_KEY
cp .env.example .env # then set DATA_ROOT and FIRMS_MAP_KEY
```

```
Expand Down Expand Up @@ -297,16 +300,40 @@ In **Docker**, point it at a volume so the data survives the container:
services:
app:
environment:
FIRMS_DATA_DIR: /data/firms
DATA_ROOT: /data
volumes:
- firms-data:/data/firms
volumes:
firms-data:
- ${DATA_ROOT:-./data}:/data
```

It is the same convention as
[egms-client](https://github.com/agent-engineering-studio/egms-client)
(`EGMS_DATA_DIR`), so one volume can hold both under `/data`.
The other agent-engineering-studio libraries read the same `DATA_ROOT`, so
one volume holds all of them, each in its own folder.

### Download it all once: `firms init`

For a server or an installer: the yearly archives and the **whole**
WorldCover tiles over a box, in one idempotent, resumable step, with no
`rasterio` needed:

```bash
firms init Italy --bbox 6,35,19,48 # VIIRS 2012-last year + 23 tiles, 1.3 GB
firms init Italy --years 2016-2025 --product all # MODIS too, no tiles
```

A file already there is skipped; a download goes to `.part` and is renamed
when complete; a failed file is reported (exit code 1) and the rest goes
on, so running it again resumes. In Python, with your own client and your
own retry (the library retries nothing unless given `retry=RetryPolicy()`):

```python
report = await init(country="Italy", years=range(2012, 2026), bbox=(6, 35, 19, 48), client=client)
report.downloaded, report.skipped, report.missing, report.failed, report.ok
```

`missing` lists the years not published and the tiles of open sea (they do
not exist); they are not errors. `download_archive` and
`download_worldcover_tile` do one file each, for an application that
retries file by file. The static mask is built later from the archives,
offline.

### Fill it before you need it: `firms sync`

Expand Down Expand Up @@ -1024,7 +1051,8 @@ All checked against the live service on 3 November 2026.
| `confidence_level(raw)` | pure | MODIS % or VIIRS level → `"low"` / `"nominal"` / `"high"` |
| `is_hotspot_csv(text)` | pure | is this a hotspot CSV, or an error page? |
| `archive_url`, `archive_filename`, `area_url`, `area_windows`, `archive_years` | pure | URLs, file names, 5-day windows, year ranges |
| `default_directory()` | pure | `FIRMS_DATA_DIR`, else `~/.cache/firms-client` |
| `default_directory()` | pure | `$DATA_ROOT/firms-client` (`FIRMS_DATA_DIR` overrides it), else `~/.cache/firms-client` |
| `init(directory=None, *, country, years, bbox, products, client, retry)` → `InitReport` | async | archives and whole WorldCover tiles, once, resumable; `download_worldcover_tile`, `worldcover_tiles` |
| `MODIS`, `VIIRS_SNPP`, `ARCHIVE_PRODUCTS`, `NRT_SOURCES`, `SP_SOURCES`, `MAX_AREA_DAYS` | constants | products and sources |
| `VEGETATION_FIRE`, `ACTIVE_VOLCANO`, `STATIC_LAND_SOURCE`, `OFFSHORE` | constants | the `type` values |
| `Hotspot`, `FireEvent`, `ArchiveProduct`, `BBox`, `ConfidenceLevel` | types | |
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2>Small, typed, honest about the data</h2>
<p class="sub">Built for researchers, data engineers and civil-protection teams who want FIRMS data in a notebook or a pipeline, without the e-mail order form.</p>
<div class="grid">
<div class="card"><h3><span class="icon">📦</span>Open yearly archives</h3><p>MODIS from 2000 and VIIRS S-NPP from 2012, per country, with no Earthdata login and no key.</p></div>
<div class="card"><h3><span class="icon">💾</span>Never download twice</h3><p>Archives are saved in a persistent data directory (<code>FIRMS_DATA_DIR</code>) and read from disk next time.</p></div>
<div class="card"><h3><span class="icon">💾</span>Never download twice</h3><p>Archives are saved in a persistent data directory (<code>$DATA_ROOT/firms-client</code>) and read from disk next time.</p></div>
<div class="card"><h3><span class="icon">⚡</span>Near-real-time API</h3><p>The last 1-5 days over any bounding box, about 3 hours after the overpass, with a free MAP_KEY.</p></div>
<div class="card"><h3><span class="icon">🔥</span>Fire or factory?</h3><p>Every detection carries its FIRMS <code>type</code>: vegetation, volcano, industry, offshore.</p></div>
<div class="card"><h3><span class="icon">🎚️</span>One confidence scale</h3><p>MODIS percentages and VIIRS <code>l</code>/<code>n</code>/<code>h</code> judged by one rule.</p></div>
Expand Down Expand Up @@ -184,7 +184,7 @@ <h2>API at a glance</h2>
<tr><td><code>confidence_level(raw)</code></td><td>pure</td><td>MODIS % or VIIRS level → <code>"low"</code> / <code>"nominal"</code> / <code>"high"</code></td></tr>
<tr><td><code>is_hotspot_csv(text)</code></td><td>pure</td><td>is this a hotspot CSV, or an error page?</td></tr>
<tr><td><code>archive_url</code>, <code>archive_filename</code>, <code>area_url</code>, <code>archive_years</code></td><td>pure</td><td>URLs, file names, year ranges</td></tr>
<tr><td><code>default_directory()</code></td><td>pure</td><td><code>FIRMS_DATA_DIR</code>, else <code>~/.cache/firms-client</code></td></tr>
<tr><td><code>default_directory()</code></td><td>pure</td><td><code>$DATA_ROOT/firms-client</code>, else <code>~/.cache/firms-client</code></td></tr>
<tr><td><code>fetch_area_range(client, map_key, source, bbox, start, end)</code></td><td>async</td><td>any date range, in 5-day requests</td></tr>
<tr><td><code>cluster(hotspots, *, radius_m, gap_days)</code></td><td>pure</td><td>hotspots → <code>FireEvent</code>s, largest first</td></tr>
<tr><td><code>summarize(hotspots)</code></td><td>pure</td><td>a JSON digest of a few KB, for people and LLMs</td></tr>
Expand Down
5 changes: 3 additions & 2 deletions docs/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Key facts an assistant must get right:

- Per-country yearly archives are static open CSVs: no Earthdata login, no key. Products: `MODIS` (2000-), `VIIRS_SNPP` (2012-). VIIRS NOAA-20/21 have no country archive.
- `fetch_archive(client, product, year, country, directory=None)` -> `list[Hotspot] | None`. `None` means the year is not published (HTTP 404). Country is the English name as FIRMS writes it: `Italy`, `Greece`, `United_States`.
- Archives are cached in `directory`, else `FIRMS_DATA_DIR`, else `$XDG_CACHE_HOME/firms-client` or `~/.cache/firms-client`. Delete a file to refresh it.
- Archives are cached in `directory`, else `$DATA_ROOT/firms-client` (`FIRMS_DATA_DIR` still overrides it), else `$XDG_CACHE_HOME/firms-client` or `~/.cache/firms-client`. Delete a file to refresh it.
- `fetch_area(client, map_key, source, bbox, *, days=1, on_date=None)` -> `list[Hotspot]`. `bbox` is `(west, south, east, north)`. `days` is 1-5. Sources: `VIIRS_SNPP_NRT`, `VIIRS_NOAA20_NRT`, `VIIRS_NOAA21_NRT`, `MODIS_NRT`. Never cached. Empty result is `[]`.
- Every async function takes the caller's `httpx.AsyncClient`. Retries for 5xx/timeouts are the caller's job; httpx exceptions propagate.
- `FirmsError`: a bad MAP_KEY or source (HTTP 400 plain text `Invalid MAP_KEY.`), or an error page served with HTTP 200.
Expand Down Expand Up @@ -45,10 +45,11 @@ Key facts an assistant must get right:
- `sync(client, country, *, products=(VIIRS_SNPP,), first_year=None, last_year=None, worldcover=None, directory=None, retry=None)` -> `SyncReport`: download now what the library reads lazily (archives, the static mask, a local WorldCover copy over a box), and write `sync.json`; running it again costs nothing. For servers and offline use. CLI: `firms sync Italy --worldcover W,S,E,N`.
- `save_worldcover(bbox, directory=None)` -> files: a local copy of WorldCover over a box, under the tiles' names; `WorldCover.synced()` reads it, else the public bucket.
- CLI: `firms trust LAT LON [--country Italy] [--no-land] [--area-ha N] [--format json]`.
- `init(directory=None, *, country, years, bbox=None, products=(VIIRS_SNPP,), client=None, retry=None)` -> `InitReport` (`downloaded`, `skipped`, `missing`, `failed` {name: error}, `ok`, `as_dict()`): the yearly archives and the **whole** WorldCover tiles touching `bbox` (3° tiles, Italy 23 tiles / 1.3 GB, under `worldcover/` with the bucket's path, read by `WorldCover.synced()`), into the data directory. Idempotent and resumable (`.part` then rename, files there skipped, a failed file recorded and the rest goes on). Takes the caller's `httpx.AsyncClient`; no retry unless `retry=RetryPolicy()`. Sea tiles do not exist (404): in `missing`, not errors. No rasterio needed. `worldcover_tiles(bbox)` -> the tile URLs; `download_worldcover_tile(client, url, directory=None, *, retry=None)` -> `Path | None` one tile. CLI: `firms init Italy [--years 2012-2025] [--bbox W,S,E,N] [--product all]` (exit 1 if a file failed).

## What the service has, lacks, and the key

- One data directory: `FIRMS_DATA_DIR` from the environment, else from the `.env` of the current directory, else `~/.cache/firms-client`. Archives, the static mask, the WorldCover copy and `sync.json` all go there and are read from there (`default_directory()`). The MAP_KEY likewise: `FIRMS_MAP_KEY` from the environment or `.env` (`map_key_from_env()`, `ENV_MAP_KEY`); `env_file_value(name)` reads one `.env` value without changing the environment.
- One data directory: `$DATA_ROOT/firms-client` (`DATA_ROOT`, `ENV_DATA_ROOT`, is the data root shared by the agent-engineering-studio libraries), from the environment, else from the `.env` of the current directory; `FIRMS_DATA_DIR` (`ENV_DATA_DIR`) still overrides it, for compatibility; else `~/.cache/firms-client`. Archives, the static mask, the WorldCover copy and `sync.json` all go there and are read from there (`default_directory()`). The MAP_KEY likewise: `FIRMS_MAP_KEY` from the environment or `.env` (`map_key_from_env()`, `ENV_MAP_KEY`); `env_file_value(name)` reads one `.env` value without changing the environment.
- `missing_days(client)` -> `MissingDays` (`standard`, `near_real_time`: `{satellite: frozenset[date]}`; `.missing("VIIRS_SNPP", day, nrt=False)`): the days a satellite has **no data** in FIRMS, from the service's missing-data table (not a documented API: a changed page raises `FirmsError`). A fire on such a day is not measured, not absent. VIIRS S-NPP: no standard data 27 July-10 August 2022, stretches of 2024 and 2026.
- `latest_archive(client, product, country, *, until=None)` -> the last year with a published country archive, or `None`.
- `map_key_status(client, key)` (JSON as FIRMS writes it) and `data_availability(client, key, source="ALL")` (CSV rows as written): need a MAP_KEY. `is_map_key(key)`: 32 lowercase letters and digits.
Expand Down
12 changes: 12 additions & 0 deletions src/firms_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from firms_client.client import (
ENV_DATA_DIR,
ENV_DATA_ROOT,
ENV_MAP_KEY,
default_directory,
download_archive,
Expand All @@ -50,6 +51,12 @@
select,
within,
)
from firms_client.init import (
InitReport,
download_worldcover_tile,
init,
worldcover_tiles,
)
from firms_client.landcover import (
WORLDCOVER_CLASSES,
BurningRules,
Expand Down Expand Up @@ -104,6 +111,7 @@
"ATTRIBUTION",
"CSV_COLUMNS",
"ENV_DATA_DIR",
"ENV_DATA_ROOT",
"ENV_MAP_KEY",
"MAX_AREA_DAYS",
"MODIS",
Expand Down Expand Up @@ -132,6 +140,7 @@
"FirmsError",
"Grid",
"Hotspot",
"InitReport",
"LaeaGrid",
"MaskRules",
"MissingDays",
Expand Down Expand Up @@ -161,6 +170,7 @@
"default_directory",
"distance_m",
"download_archive",
"download_worldcover_tile",
"draft_bulletin",
"env_file_value",
"event_land_cover",
Expand All @@ -169,6 +179,7 @@
"fetch_area",
"fetch_area_range",
"fetch_static_mask",
"init",
"is_hotspot_csv",
"is_map_key",
"laea",
Expand All @@ -190,4 +201,5 @@
"to_geojson",
"trust",
"within",
"worldcover_tiles",
]
Loading