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.
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
docs/make_images.py with this package: 542 × 362 points, peak 0.33 g.
- What is it, in 30 seconds
- Who is it for
- Quick start
- How it works
- Recipes
- How far to trust a value
- The same place across earthquakes
- When a map is revised
- Facts, the check and the MCP server
- The command line
- The page for a municipality
- Docker and the Makefile
- Benchmark and notebooks
- The traps we already fell into
- API at a glance
- 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, 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
pip install ingv-shakemap
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())
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
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:
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.
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.
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:
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:
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:
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".
STDPGAis the standard deviation of the logarithm of the PGA, so the range is a factor (pga / e^sigmatopga * 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.
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)]
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.
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.
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:
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,
and the documentation site publishes llms.txt and llms-full.txt. No model
is called anywhere in this repository.
The command line
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
A page in Italian for the technical office of a public body
(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.
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:
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 thatcheck_textfinds exactly the faults put in them, and none in the faithful ones: 21 of 21.
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.
Four numbered notebooks in
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
-
PGA is in percent of g, not in g. The
grid.xmlwritesunits="%g":0.11is 0.0011 g, barely felt.pga_gconverts;value_at("PGA", ...)andcolumn("PGA")return the file's own unit. -
The row order is a convention, not a statement. Rows go from the north edge southwards, longitude fastest.
parse_gridchecks this on the first rows and refuses a file in another order, because a wrong guess would move every value without raising. -
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_stepandlat_step. -
An empty week is a 204, an outage is not. The FDSN service answers
204 No Contentto a window without earthquakes. A 5xx, even with no body, is a failure:eventsraisesIngvErrorfor it and returns[]only for the 204, so an unreachable catalogue never looks like a quiet week. -
No ShakeMap is a 404, and it is normal. Small or very recent events have none:
shakemapreturnsNone. Any other error raises. -
automaticcan last, and the map keeps changing. The maps of the 23 October 2026 sequence still saidmap_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: compareinfo(event_id).versioninstead. -
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/. -
No top-level id in the GeoJSON. INGV puts the event id in
properties.eventId, as an integer.parse_eventreads it from there. -
Times are UTC without an offset, both ways. The package sends
2026-10-23T10:19:15and gives back aware UTC datetimes. -
In
stationlist.jsona missing value is the string"null". 263 of the 469 stations of the Mw 5.5 have"pga": "null", as text.parse_stationsreads it asNone; a plainfloat()would raise, and a check for JSONnullwould let it through. -
The uncertainty is in
ln(g), not in g.STDPGAis the standard deviation of the natural logarithm of the PGA. The range is a factor:pga / e^sigmatopga * e^sigma. Subtracting 0.55 from 0.486 g gives a negative acceleration.trust_atcomputes the range. -
INGV serves only the current version. When version 5 is published, version 4 is gone. Store
grid.xmlunder a key without the version and you lose what you showed yesterday:version_keyandShakeMapStorekeep each one. -
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.
-
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.
Development
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 are under CC BY 4.0: credit INGV.
- ShakeMap: computed and published by INGV at 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.xmlformat 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, under CC BY 4.0, built bytools/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.
Metadata
Release files for ingv-shakemap 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ingv_shakemap-0.4.0.tar.gz | 209.5 kB | With provenance | Details for ingv_shakemap-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ingv_shakemap-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for ingv_shakemap-0.4.0-py3-none-any.whl |
Total release size: 412.6 kB
Release files / ingv_shakemap-0.4.0.tar.gz
| Download URL | ingv_shakemap-0.4.0.tar.gz |
|---|---|
| Size | 209.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a8d7bc930f9eb615da7922dea45c3250e368931edbcbe85ebfe3a067e59cfb1
|
|
BLAKE2b-256 checksum How to use checksums |
917f9e44b38fad6ead7a95d29ffde3ddb8645f47eec39907d4bb154014b9d97a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / ingv_shakemap-0.4.0-py3-none-any.whl
| Download URL | ingv_shakemap-0.4.0-py3-none-any.whl |
|---|---|
| Size | 203.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64375ae110e0436e449828edeedd21af7bcf3a1bf9fa3d257ed56bdfb970bdfb
|
|
BLAKE2b-256 checksum How to use checksums |
5405ae588e15ffcacc5e8016b2903b302001c7626af073befea8270afa39d3ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logSecurity for ingv-shakemap 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for ingv_shakemap-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.