Metadata-Version: 2.4
Name: ingv-shakemap
Version: 0.4.0
Summary: Async Python client for INGV earthquakes and ShakeMap grids: FDSN events, grid.xml parsing, ground shaking (PGA, PGV, MMI) at any point
Author: Giuseppe Zileni
Author-email: Giuseppe Zileni <giuseppe.zileni@gmail.com>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Dist: httpx>=0.27
Requires-Dist: numpy>=2.0
Requires-Dist: mcp>=2.3 ; extra == 'mcp'
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/agent-engineering-studio/ingv-shakemap
Project-URL: Issues, https://github.com/agent-engineering-studio/ingv-shakemap/issues
Project-URL: Documentation, https://agentengineering.it/ingv-shakemap/
Project-URL: Changelog, https://github.com/agent-engineering-studio/ingv-shakemap/blob/main/CHANGELOG.md
Provides-Extra: mcp
Description-Content-Type: text/markdown

# ingv-shakemap

**How hard did the ground shake here, and how far can I trust that number?**
INGV's earthquakes and ShakeMap grids, read into numbers you can sample at any
point in Italy: with their range, the nearest station that recorded, and the
version of the map they come from.

[![ci](https://github.com/agent-engineering-studio/ingv-shakemap/actions/workflows/ci.yml/badge.svg)](https://github.com/agent-engineering-studio/ingv-shakemap/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/ingv-shakemap)](https://pypi.org/project/ingv-shakemap/)
[![docs](https://img.shields.io/badge/docs-agentengineering.it-blue)](https://agentengineering.it/ingv-shakemap/)
![python](https://img.shields.io/badge/python-3.12%20%7C%203.13-blue)
![mypy](https://img.shields.io/badge/mypy-strict-blue)
![coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)
[![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/agent-engineering-studio/ingv-shakemap/blob/main/LICENSE)

```python
grid = await IngvClient().shakemap(47606532)
grid.pga_g(15.55, 38.19)  # 0.0029 g in Messina, from the Mw 5.5 of 23 October 2026
```

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/agent-engineering-studio/ingv-shakemap/main/docs/images/pga-dark.png">
  <img alt="Map of the southern Tyrrhenian and Sicily coloured by peak ground acceleration on a log scale from 0.001 to 0.33 g, brightest around the epicentre of the Mw 5.5 of 23 October 2026; Palermo 0.002 g, Messina 0.003 g, Cosenza 0.001 g" src="https://raw.githubusercontent.com/agent-engineering-studio/ingv-shakemap/main/docs/images/pga-light.png">
</picture>
<sub>The ShakeMap of the Mw 5.5 in the southern Tyrrhenian, 23 October 2026, drawn by
<a href="https://github.com/agent-engineering-studio/ingv-shakemap/blob/main/docs/make_images.py"><code>docs/make_images.py</code></a> with this package: 542 × 362 points, peak 0.33 g.</sub>

- [What is it, in 30 seconds](#what-is-it-in-30-seconds)
- [Who is it for](#who-is-it-for)
- [Quick start](#quick-start)
- [How it works](#how-it-works)
- [Recipes](#recipes)
- [How far to trust a value](#how-far-to-trust-a-value)
- [The same place across earthquakes](#the-same-place-across-earthquakes)
- [When a map is revised](#when-a-map-is-revised)
- [Facts, the check and the MCP server](#facts-the-check-and-the-mcp-server)
- [The command line](#the-command-line)
- [The page for a municipality](#the-page-for-a-municipality)
- [Docker and the Makefile](#docker-and-the-makefile)
- [Benchmark and notebooks](#benchmark-and-notebooks)
- [The traps we already fell into](#the-traps-we-already-fell-into)
- [API at a glance](#api-at-a-glance)
- [Data licence and credits](#data-licence-and-credits)

## What is it, in 30 seconds

After every significant earthquake INGV publishes a **ShakeMap**: its estimate
of how strongly the ground shook at every point around the epicentre, built from
the stations that recorded it and from ground-motion models where there are
none. The map is a `grid.xml` of up to 12 MB of text. This package turns it into
arrays and answers questions about a point.

| | What you get |
|---|---|
| 🌍 | **Earthquakes** from the INGV FDSN catalogue: id, time (UTC), magnitude and its type, epicentre, depth, place |
| 📈 | **The ShakeMap grid** of an event: PGA, PGV, MMI, spectral accelerations, Vs30, as `numpy` arrays |
| 📍 | **The value at a point**: `pga_g(lon, lat)` in g, `pgv_cm_s`, `mmi`, or any column with `value_at` |
| 🧾 | **The map's own metadata**: version, `map_status` (`automatic` until reviewed), processing time |
| 🔌 | **Your HTTP layer**: inject an `httpx.AsyncClient`, or route every call through your own `send` |
| 🧪 | **Pure parsers**: `parse_grid` and `parse_events` do no I/O, so you can test them on a file |
| 🎯 | **How far to trust it**: the 68 % range, the nearest station that recorded, the version and status of the map |
| 🏘️ | **Municipalities by name**: the 7,896 Italian municipalities, and the same town across earthquakes |
| 🗂️ | **Every version kept**: INGV serves only the current map; the store keeps each one, and says what changed |
| 🤖 | **For assistants**: facts with units, an MCP server, and a check that a text quotes the numbers right |
| 🏛️ | **A page for a public body**, a command line, Docker, and a benchmark of five known earthquakes in CI |

## Who is it for

- Anyone who needs **shaking at a site**, not just a magnitude: a building, a
  dam, a road, the cells of a hazard model. Magnitude says how big the
  earthquake was; PGA says how hard it hit *here*.
- Landslide and multi-hazard models: earthquake-triggered landslides scale with
  ground acceleration, which this gives per point.
- Researchers and journalists who want INGV's own estimate rather than a
  distance-based guess.

It was extracted from [Limen](https://github.com/agent-engineering-studio/limen),
the landslide, flood and wildfire monitor for Italy, where it reads the
ShakeMap of every earthquake above magnitude 3.5 onto a 1 km grid. On three
real grids its PGA matches Limen's own parser value for value.

## Quick start

```bash
pip install ingv-shakemap
```

```python
import asyncio
from datetime import UTC, datetime

from ingv_shakemap import IngvClient


async def main() -> None:
    async with IngvClient() as ingv:
        quakes = await ingv.events(
            datetime(2026, 10, 23, tzinfo=UTC),
            datetime(2026, 10, 24, tzinfo=UTC),
            min_magnitude=4.5,
        )
        for q in quakes:
            print(q.id, q.time, q.magnitude, q.magnitude_type, q.place)

        grid = await ingv.shakemap(quakes[1].id)  # None if INGV published no map
        if grid is not None:
            print(grid.map_status, grid.pga_g(15.55, 38.19), grid.mmi(15.55, 38.19))


asyncio.run(main())
```

```text
47611152 2026-10-23 13:55:34.920000+00:00 5.0 Mw Tirreno Meridionale [Mare]
47606532 2026-10-23 10:19:15.470000+00:00 5.5 Mw Tirreno Meridionale [Mare]
47605832 2026-10-23 09:51:38.850000+00:00 4.8 Mw Tirreno Meridionale [Mare]
automatic 0.002939 3.4
```

## How it works

```mermaid
flowchart LR
    F["INGV FDSN<br/>webservices.ingv.it"] -->|GeoJSON| E["parse_events<br/>Event"]
    E -->|event id| S["shakemap.ingv.it<br/>/data/{id}/current/products/grid.xml"]
    S -->|up to 12 MB of XML| G["parse_grid<br/>ShakeGrid"]
    G --> P["pga_g · pgv_cm_s · mmi<br/>value_at · column"]
```

The FDSN event id is the ShakeMap id: the same integer joins the two services.

## Recipes

**The shaking on many points at once.** `sample` and `sample_g` take arrays
of positions and answer in one NumPy call: on 100,000 points of a real grid,
10 ms against 280 ms for a loop over `pga_g`, with the same values. Outside the
grid you get `NaN`:

```python
pga = grid.sample_g("PGA", lons, lats)  # nearest point, in g
pga = grid.sample_g("PGA", lons, lats, method="bilinear")  # interpolated
pgv = grid.sample("PGV", lons, lats)  # native unit, cm/s
```

`column` still gives the whole grid as an `(nlat, nlon)` array, north row first.

**Has the map changed?** `info` reads `info.json`, a few kB, instead of the
12 MB grid: compare its `version` with the one you stored and download the grid
only when it grew.

```python
info = await ingv.info(event_id)
if info is not None and info.version != stored_version:
    grid = await ingv.shakemap(event_id)
```

**How much of the map is measured.** `uncertainty` is the map's standard
deviation per point (`STDPGA` in ln g): low near the stations, high where the
map is the ground-motion model alone. `stations` gives the stations themselves,
what each recorded and what the model predicted there.

```python
unc = await ingv.uncertainty(event_id)
sigma = unc.sample("STDPGA", lons, lats)
stations = await ingv.stations(event_id)
residuals = [s.pga_g / s.predicted_pga_g for s in stations if s.pga_g and s.predicted_pga_g]
```

**Only what changed.** `events(..., updated_after=last_run)` asks the catalogue
for the events created or revised since then (FDSN `updatedafter`).

**Parse in a thread.** A big grid takes about a quarter of a second to parse.
`IngvClient.shakemap` already runs it in `asyncio.to_thread`; when you parse
yourself, do the same:

```python
xml = await ingv.shakemap_xml(event_id)
grid = await asyncio.to_thread(parse_grid, xml)
```

**Your own HTTP layer.** Pass `send`, and the client uses it for every request
and does no retrying of its own:

```python
async def send(method: str, url: str, **kwargs):
    return await my_shared_policy(method, url, **kwargs)


ingv = IngvClient(send=send)
```

**No network at all.** `parse_grid(Path("grid.xml").read_bytes())` and
`parse_events(json.loads(text))` work on files.

## How far to trust a value

A ShakeMap is exact where a station recorded and a model between the
stations. INGV says how uncertain each point is (`uncertainty.xml`) and which
stations it used (`stationlist.json`). `trust_at` puts them together:

```python
from ingv_shakemap import IngvClient, find_place, trust_at

amatrice = find_place("Amatrice")[0]  # the town of the municipality, ISTAT 057002
async with IngvClient() as ingv:
    grid = await ingv.shakemap(7073641)  # 24 August 2016, Mw 6.0
    sigma = await ingv.uncertainty(7073641)
    stations = await ingv.stations(7073641)

t = trust_at(
    grid, amatrice.longitude, amatrice.latitude, uncertainty=sigma, stations=stations, radius_km=20
)
t.pga_g, t.pga_low_g, t.pga_high_g  # 0.486 g, between 0.281 and 0.840 g
t.nearest_station.id, t.nearest_station_km, t.nearest_station.pga_g  # IT.AMT, 1.0 km, 0.868 g
t.stations_within  # 7 stations recorded within 20 km
t.map_version, t.map_status  # "1", "automatic"
```

Three things this shows on real data:

- **The range is wide.** 0.486 g is "between 0.28 and 0.84 g, 68 times out of
  100". `STDPGA` is the standard deviation of the *logarithm* of the PGA, so
  the range is a factor (`pga / e^sigma` to `pga * e^sigma`), not a
  difference.
- **A station next door can read almost twice the map.** AMT, one kilometre
  from the town, recorded 0.868 g. Both are right: an instrument at one
  place, and a smooth surface on a 900 m grid.
- **Far from a station the range widens.** In the Emilia earthquake of
  20 May 2012, Mirandola has a record 1.0 km away and a range of 0.155 to
  0.396 g; Finale Emilia has none within 19 km and 0.143 to 0.529 g.

There is no label ("reliable", "poor") and `radius_km` has no default: a
label needs a threshold, and a threshold needs a use. The numbers are INGV's;
what to make of them is yours.

## The same place across earthquakes

`shaking_facts` is what a point felt in one earthquake, as plain data;
`history_facts` ranks the same point across several.

```python
from ingv_shakemap import history_facts, shaking_facts

h = history_facts(
    shaking_facts(grid, lon, lat, uncertainty=sigma, stations=stations)
    for grid, sigma, stations in maps  # L'Aquila 2009, 24 Aug 2016, 30 Oct 2016
)
[(e["event"]["time"][:10], e["pga_g"], e["rank"]) for e in h["events"]]
# [('2016-10-30', 0.4517, 2), ('2016-08-24', 0.4858, 1), ('2009-04-06', 0.0475, 3)]
```

<img alt="Amatrice in three earthquakes, each with its estimate and 68 % range: L'Aquila 2009 0.048 g, 24 August 2016 0.486 g between 0.281 and 0.840, 30 October 2016 0.452 g between 0.310 and 0.658; the two ranges of 2016 overlap almost entirely" src="https://raw.githubusercontent.com/agent-engineering-studio/ingv-shakemap/main/docs/images/amatrice-en.png">

At Amatrice the two earthquakes of 2016 are ranked 1 and 2, but their ranges
(0.281 to 0.840 g and 0.310 to 0.658 g) overlap almost entirely: these maps do
not settle which shook the town more. `Facts(client).history(...)` does the
same from INGV, picking the strongest events around a point.

## When a map is revised

INGV serves only the **current** version of a map. The Mw 5.5 of 23 October
2026 is at version 5, the last run 26 days after the earthquake; Norcia 2016
got its version 3 on 17 November 2026, ten years later. A store that
overwrites `grid.xml` cannot say what changed.

```python
from ingv_shakemap import ShakeMapStore, fetch, is_newer, revision_facts, version_key

store = ShakeMapStore()  # $DATA_ROOT/ingv-shakemap, or ~/.cache/ingv-shakemap
version = await fetch(ingv, store, 47606532)  # downloads once; later only info.json (a few kB)
store.versions(47606532)  # [5]
version_key(47606532, 5, "grid.xml")  # "47606532/v005/grid.xml", for your own object store
is_newer(await ingv.info(47606532), 5)  # False: the map you hold is the published one

r = revision_facts(store.grid(47606532, 4), store.grid(47606532, 5), points, min_pga_g=0.004)
r["entered"], r["left"], r["largest_changes"]
```

`revision_facts` says, for your points and your threshold, which entered,
which left and where the largest changes are. **It is tested on pairs of
grids built by code**: no real pair of versions was at hand, because INGV
had already replaced them. Keep the versions and the next revision gives one.

## Facts, the check and the MCP server

Every answer of `shaking_facts`, `history_facts` and `revision_facts` is a
plain `dict` whose numbers carry their unit in the key (`pga_g`, `pgv_cm_s`,
`epicentre_km`), the map they come from and the rule that goes with every
answer: *a ShakeMap estimates the shaking; it is not a measure of damage, and
not an alert*. A model may word these facts; it never computes them.

```python
from ingv_shakemap import check_text, describe

describe(facts, language="it")  # a sentence written by code, no model
check_text("Amatrice felt 48.6 g, 3 km from a station.", facts)
# [Misquote('48.6 g', 'g', 'unit', 'pga_g = 0.4858 g'), Misquote('3 km', 'km', 'invented')]
```

`check_text` finds a number that is in no fact (**invented**), a fact of
another unit (**unit**: percent of g written as g is the classic one) and a
number near a fact but not its rounding (**rounded**). It knows that a number
is a fact of the right unit, not that it is said of the right place.

The MCP server gives the same to an assistant:

```sh
pip install "ingv-shakemap[mcp]"
ingv-shakemap-mcp                                # on standard input and output
ingv-shakemap-mcp --transport streamable-http    # http://127.0.0.1:8774/mcp
```

Six tools: `find_place`, `events`, `shaking`, `history`, `revision`, `check`.
The agent skill is in
[`skills/ingv-shakemap/SKILL.md`](https://github.com/agent-engineering-studio/ingv-shakemap/blob/main/skills/ingv-shakemap/SKILL.md),
and the documentation site publishes `llms.txt` and `llms-full.txt`. No model
is called anywhere in this repository.

## The command line

```sh
ingv-shakemap places Amatrice
ingv-shakemap events --days 30 --min-magnitude 4
ingv-shakemap shaking 7073641 --place Amatrice --radius-km 20
ingv-shakemap shaking 7073641 --place Amatrice --text it
ingv-shakemap history --place Amatrice --since 2009-01-01 --min-magnitude 5.5 --within-km 60
ingv-shakemap fetch 7073641 8863681      # keep the maps, one folder per version
ingv-shakemap revision 47606532 --place Ustica --place Palermo --min-pga-g 0.004
ingv-shakemap check answer.txt --facts facts.json
```

Every command prints JSON. `check` exits 2 when the text has a fault.

## The page for a municipality

<img alt="The page for Amatrice: a map with the town, the epicentre of the Norcia earthquake of 30 October 2016 and the stations that recorded; on the right 0.452 g, between 0.310 and 0.658 g, intensity 8.9, the nearest station MZ30 at 0.4 km which recorded 0.484 g, 30 stations within 20 km, INGV map version 3, automatic" src="https://raw.githubusercontent.com/agent-engineering-studio/ingv-shakemap/main/docs/images/page-amatrice.jpg">

A page in Italian for the technical office of a public body
([`app/`](https://github.com/agent-engineering-studio/ingv-shakemap/tree/main/app)):
one municipality, one earthquake, what the town felt, how far to trust it,
and the same town in the strongest earthquakes around. It is deliberately
narrow: no damage, no landslides, no risk, no alert. No text on it is written
by a model.

```sh
make app        # here, on http://127.0.0.1:3010
make app-up     # in a container
```

## Docker and the Makefile

`make help` lists every command. With Docker alone:

```sh
make start      # build and start everything
make stop
```

| Container | What | Address |
|---|---|---|
| `ingv-shakemap-ui` | the page for a municipality | <http://localhost:3010> |
| `ingv-shakemap-notebooks` | Jupyter with the example notebooks | <http://localhost:8890> (token `shakemap`) |
| `ingv-shakemap-mcp` | the MCP server over HTTP | <http://localhost:8774/mcp> |

The names are fixed and prefixed, and the ports are this library's own, so it
runs beside the other libraries of agent-engineering-studio. The maps
downloaded go to `$DATA_ROOT/ingv-shakemap` (`./data/ingv-shakemap` by
default), the root shared with Limen. `make cli ARGS="places Amatrice"` runs
the command in a container; `make data` downloads five known earthquakes.

## Benchmark and notebooks

Five known earthquakes (L'Aquila 2009, Emilia 2012, Amatrice and Norcia 2016,
Tyrrhenian Sea 2026), as windows of the maps INGV published, run in CI on
every change (`make benchmark`):

- read by the library, the map is within a factor of 2 of the record at all
  119 stations that recorded; read with the unit wrong it is 98 to 139 times
  off, and with the rows from the south it fails on four earthquakes of five;
- the typical distance between the map and a record at the record's own place
  is ×1.05 to ×1.39, and the largest gaps are at the strongest records (AMT:
  0.868 g recorded, 0.514 g on the map);
- a set of 21 texts (13 answers written by hand, 8 sentences written by
  `describe`) checks that `check_text` finds exactly the faults put in them,
  and none in the faithful ones: 21 of 21.

<img alt="Scatter plot on log axes of the PGA read on INGV's ShakeMap at each of 119 stations against the PGA the station recorded, for five earthquakes: every point lies between half and twice the record; the station AMT at Amatrice recorded 0.868 g where the map says 0.514 g" src="https://raw.githubusercontent.com/agent-engineering-studio/ingv-shakemap/main/docs/images/records-en.png">

The stations are the data the map was built on: this checks the reading, not
INGV's map between the stations. The whole account is in
[`benchmarks/README.md`](https://github.com/agent-engineering-studio/ingv-shakemap/blob/main/benchmarks/README.md).

Four numbered notebooks in
[`notebooks/`](https://github.com/agent-engineering-studio/ingv-shakemap/tree/main/notebooks)
walk through it: what a town felt, how far to trust it, the same town in
three earthquakes, and live from INGV.

## The traps we already fell into

1. **PGA is in percent of g, not in g.** The `grid.xml` writes `units="%g"`:
   `0.11` is 0.0011 g, barely felt. `pga_g` converts; `value_at("PGA", ...)`
   and `column("PGA")` return the file's own unit.
2. **The row order is a convention, not a statement.** Rows go from the north
   edge southwards, longitude fastest. `parse_grid` checks this on the first
   rows and refuses a file in another order, because a wrong guess would move
   every value without raising.
3. **The grid step changes from event to event**: about 90 m at Campi Flegrei,
   0.0083° (about 900 m) for the 23 October 2026 sequence. Never hard-code it;
   read `lon_step` and `lat_step`.
4. **An empty week is a 204, an outage is not.** The FDSN service answers
   `204 No Content` to a window without earthquakes. A 5xx, even with no body,
   is a failure: `events` raises `IngvError` for it and returns `[]` only for
   the 204, so an unreachable catalogue never looks like a quiet week.
5. **No ShakeMap is a 404, and it is normal.** Small or very recent events
   have none: `shakemap` returns `None`. Any other error raises.
6. **`automatic` can last, and the map keeps changing.** The maps of the
   23 October 2026 sequence still said `map_status="automatic"` twelve days
   later, and the Mw 5.5's went through four versions, the last one forty hours
   after the earthquake. A rule like "stable after 24 hours" misses it: compare
   `info(event_id).version` instead.
7. **The old URL is dead.** The `/shake4/` prefix answered 404 for every event
   on 19 October 2026; the grid lives under `/data/{id}/current/products/`.
8. **No top-level id in the GeoJSON.** INGV puts the event id in
   `properties.eventId`, as an integer. `parse_event` reads it from there.
9. **Times are UTC without an offset**, both ways. The package sends
   `2026-10-23T10:19:15` and gives back aware UTC datetimes.
10. **In `stationlist.json` a missing value is the string `"null"`.** 263 of the
    469 stations of the Mw 5.5 have `"pga": "null"`, as text. `parse_stations`
    reads it as `None`; a plain `float()` would raise, and a check for JSON
    `null` would let it through.

11. **The uncertainty is in `ln(g)`, not in g.** `STDPGA` is the standard
    deviation of the natural logarithm of the PGA. The range is a factor:
    `pga / e^sigma` to `pga * e^sigma`. Subtracting 0.55 from 0.486 g gives a
    negative acceleration. `trust_at` computes the range.
12. **INGV serves only the current version.** When version 5 is published,
    version 4 is gone. Store `grid.xml` under a key without the version and
    you lose what you showed yesterday: `version_key` and `ShakeMapStore` keep
    each one.
13. **Even at a station the map is not the record.** AMT recorded 0.868 g on
    24 August 2016; the map says 0.514 g at that grid point. Do not read a
    ShakeMap as a list of measurements.
14. **Old events have no map.** The Colfiorito earthquakes of 26 September
    1997 (Mw 5.8 and 5.6) are in the catalogue and answer 404 for the map.
    That is "not computed", never zero.

## API at a glance

| Name | What it does |
|---|---|
| `IngvClient(client=None, *, send=None, retries=3, backoff_s=2.0, timeout_s=60.0)` | async client; retries transport errors, 429 and 5xx |
| `IngvClient.events(start, end, *, bbox=ITALY, min_magnitude=None, max_depth_km=None, limit=None, updated_after=None)` | earthquakes, newest first |
| `IngvClient.shakemap(event_id)` / `.shakemap_xml(event_id)` | the parsed grid, or the raw bytes; `None` if there is no map |
| `IngvClient.uncertainty(event_id)` | the map's standard deviation, as a `ShakeGrid` |
| `IngvClient.info(event_id)` → `ShakeMapInfo` | version, status, history of runs, GMPE, stations, peaks |
| `IngvClient.stations(event_id)` → `list[Station]` | what each station recorded, and what the model predicted |
| `IngvClient.product(event_id, name)` | any file of the map's products, raw |
| `parse_grid(xml)` → `ShakeGrid` | pure parser; raises only `GridError` |
| `ShakeGrid.pga_g` / `.pgv_cm_s` / `.mmi` / `.value_at` | values at a point |
| `ShakeGrid.sample` / `.sample_g` | values at many points, nearest or bilinear |
| `shaken_points(grid, points, min_pga_g)` | `(key, PGA in g)` of your points shaken at least a threshold you choose |
| `ShakeGrid.require_g(name="PGA")` | `GridError` unless the column reads in g |
| `ShakeGrid.points()` / `.index_of(lons, lats)` | the coordinates of every grid point; the nearest grid point of your positions |
| `ShakeGrid.column` / `.bbox` | the whole grid as arrays |
| `parse_info(json)`, `parse_stations(json)` | pure parsers of `info.json` and `stationlist.json` |
| `ShakeGrid.event`, `.map_status`, `.version`, `.process_time`, `.fields` | the map's metadata |
| `parse_events(geojson)` / `parse_event(feature)` → `Event` | pure parsers of the FDSN answer |
| `event_query(...)`, `shakemap_grid_url(id)`, `shakemap_product_url(id, name)` | the requests, without sending them |
| `trust_at(grid, lon, lat, *, uncertainty, stations, radius_km)` → `Trust` | the value, its 68 % range, the nearest recording station, the map's version |
| `distance_km`, `nearest_stations(stations, lon, lat)` | great-circle distance; the recording stations, nearest first |
| `find_place(name)` / `places()` → `Place` | the 7,896 Italian municipalities, as the point of their town |
| `shaking_facts(grid, lon, lat, ...)` | what a point felt, as data with units in the keys |
| `history_facts(shakings)` | one point across earthquakes, ranked by PGA |
| `revision_facts(old, new, points, min_pga_g)` | what changed at your points between two versions |
| `Facts(client, store=...)` | `.events`, `.shaking`, `.history`, `.stations_near`, `.revision`, fetching from INGV |
| `describe(facts, language="en")` | the facts as a sentence, written by code |
| `check_text(text, facts)` → `list[Misquote]` | numbers invented, in the wrong unit, wrongly rounded |
| `ShakeMapStore(root)`, `fetch(client, store, id)` | every version of a map, kept on disk |
| `version_key(id, version, name)`, `is_newer(info, stored_version)` | a key that carries the version; is the published map newer than yours |
| `IngvError`, `GridError` | the only exceptions; `GridError` is also a `ValueError` |

The full reference is on the [documentation site](https://agentengineering.it/ingv-shakemap/).

## Development

```bash
uv sync
make help    # every command
make check   # ruff, mypy --strict, pytest with coverage, the benchmark
make docs    # the documentation site, llms.txt and llms-full.txt
```

## Data licence and credits

- **Earthquake catalogue:** © Istituto Nazionale di Geofisica e Vulcanologia
  (INGV). The data and results published on
  [terremoti.ingv.it](https://terremoti.ingv.it/en) are under
  [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/): credit INGV.
- **ShakeMap:** computed and published by INGV at
  [shakemap.ingv.it](https://shakemap.ingv.it/). That site states no licence of
  its own (checked on 4 November 2026); credit INGV as for the catalogue.
- ShakeMap is software by the USGS; the `grid.xml` format is ShakeMap 4's.
- **Municipalities:** the bundled list (`ingv_shakemap/data/comuni.csv.gz`,
  7,896 municipalities with their ISTAT code and the position of their town)
  comes from [GeoNames](https://www.geonames.org/), under
  [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), built by
  `tools/build_places.py`.
- **The maps of the benchmark** (`benchmarks/maps`) are windows of INGV's
  ShakeMaps of five earthquakes, downloaded on 28 November 2026.

This package is not affiliated with INGV or the USGS. Code under
[Apache-2.0](https://github.com/agent-engineering-studio/ingv-shakemap/blob/main/LICENSE).
