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
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Everything, but what the images are built from.
*
!pyproject.toml
!uv.lock
!README.md
!LICENSE
!src
!app
app/static/vendor
!benchmarks
!notebooks
**/__pycache__
**/*.pyc
**/.ipynb_checkpoints
.env
44 changes: 44 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copy this file to .env and fill in what you need. .env is never committed.
#
# cp .env.example .env
#
# Nothing here is needed to use the library, the command line, the MCP server
# or the page: INGV's data is open, with no account and no key. The Makefile
# and Docker Compose read .env by themselves.

# --- Where the data lives (optional) --------------------------------------
# The root shared with Limen and the other libraries of agent-engineering-studio:
# the ShakeMaps downloaded go to $DATA_ROOT/ingv-shakemap, one folder per
# event and per version. Unset: ~/.cache/ingv-shakemap, and
# ./data/ingv-shakemap for Docker Compose.
# DATA_ROOT=

# --- The containers (optional: every one has a default) --------------------
# The prefix of every container, image and network (default ingv-shakemap).
INGV_SHAKEMAP_NAME=
# The port of the page for a municipality (default 3010).
INGV_SHAKEMAP_UI_PORT=
# The port of Jupyter with the notebooks (default 8890), and its token (default shakemap).
INGV_SHAKEMAP_JUPYTER_PORT=
INGV_SHAKEMAP_JUPYTER_TOKEN=
# The port of the MCP server over HTTP (default 8774).
INGV_SHAKEMAP_MCP_PORT=

# --- The page of a municipality (optional) ---------------------------------
# The name in the header.
INGV_SHAKEMAP_ENTE="Comune di Amatrice"
# The ISTAT code of the municipality the page opens on (default 057002, Amatrice).
INGV_SHAKEMAP_COMUNE=057002
# Which earthquakes the page lists: epicentre within these km (default 100),
# from this magnitude (default 5.0), since this date (default 1985-01-01),
# at most this many (default 6: each is a map of 5 to 18 MB the first time).
INGV_SHAKEMAP_WITHIN_KM=
INGV_SHAKEMAP_MIN_MAGNITUDE=
INGV_SHAKEMAP_SINCE=
INGV_SHAKEMAP_LIMIT=
# The radius the recording stations are counted in, in km (default 20).
INGV_SHAKEMAP_RADIUS_KM=
# The tiles of the background map, and their credit (default: OpenStreetMap,
# which then sees the address of every visitor).
INGV_SHAKEMAP_TILES=
INGV_SHAKEMAP_TILES_CREDIT=
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,46 @@ jobs:
- run: uv run mypy
- run: uv run pytest --cov --cov-report=term-missing
- run: uv build

publiccode:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: italia/publiccode-parser-action@v1
with:
publiccode: publiccode.yml
no-network: true

benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.13"
enable-cache: true
- run: uv sync --locked
- run: uv run python -m benchmarks.run --check
- run: uv run python -m benchmarks.faithful --check

notebooks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.13"
enable-cache: true
- run: uv sync --locked --group examples
- name: Every offline notebook runs (04 needs the network)
working-directory: notebooks
run: uv run --group examples jupyter nbconvert --to notebook --execute --output-dir /tmp/run 01_*.ipynb 02_*.ipynb 03_*.ipynb

docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: The three images build
run: docker compose --profile app --profile notebooks --profile tools build
7 changes: 5 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# The documentation site (Zensical, from zensical.toml): built on every pull request (a broken page fails
# The documentation site (Zensical, from zensical.toml), with llms.txt, llms-full.txt and
# the agent skill: built on every pull request (a broken page fails
# the check), published to GitHub Pages from main. Pages must use "GitHub
# Actions" as its source (Settings > Pages), once.
name: docs
Expand All @@ -25,8 +26,10 @@ jobs:
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- run: uv sync --locked --only-group docs
# The package too: llms-full.txt renders the API from the modules.
- run: uv sync --locked --group docs
- run: uv run --no-sync zensical build --strict
- run: uv run --no-sync python tools/build_llms.py
- if: github.event_name != 'pull_request'
uses: actions/upload-pages-artifact@v5
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ site/
# Dati di prova scaricati a mano (inventari CEDIT): non si versionano.
data-test/
.DS_Store
/app/static/vendor/
/data/
.env
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,54 @@ All notable changes to this project are documented here. The format follows

## [Unreleased]

## [0.4.0] - 2026-11-28

### Added

- `trust_at` → `Trust`: the shaking at a point with how far to trust it. The
68 % range from the uncertainty grid (`STDPGA` is in ln g, so the range is
`pga / e^sigma` to `pga * e^sigma`), the nearest station that recorded and
its distance, the recording stations within a radius the caller passes, the
version and status of the map. No label and no default radius.
`distance_km` and `nearest_stations` with it.
- `shaking_facts`, `history_facts`, `revision_facts` and the async `Facts`
(`events`, `shaking`, `history`, `stations_near`, `revision`): the answers
as plain data with the unit in each key, the map they come from and the
rule that a ShakeMap is not a measure of damage and not an alert.
`describe` writes them as a sentence, in English or Italian, with no model.
`revision_facts` is tested on pairs of grids built by code: INGV serves
only the current version of a map, so no real pair was at hand.
- `check_text` → `Misquote`: the numbers of a text that are in no fact, are a
fact of another unit (percent of g written as g, and the reverse) or are
wrongly rounded.
- `ShakeMapStore`, `fetch`, `version_key`, `is_newer`: every version of a map
kept on disk under `<event>/v005/<file>`, in `$DATA_ROOT/ingv-shakemap` or
`~/.cache/ingv-shakemap`; whether the published map is newer than the one
held, from `info.json` alone.
- `find_place`, `places` → `Place`: the 7,896 Italian municipalities with
their ISTAT code, as the point of their town (GeoNames, CC BY 4.0, 147 kB
bundled, read on the first call).
- The command line `ingv-shakemap` (`places`, `events`, `shaking`, `history`,
`fetch`, `versions`, `revision`, `check`, `mcp`).
- The MCP server `ingv-shakemap-mcp` (extra `mcp`): `find_place`, `events`,
`shaking`, `history`, `revision`, `check`; on standard input and output or
over HTTP on port 8774, with `GET /health`.
- A page for a public body in `app/` (Italian, Bootstrap Italia): what the
town of a municipality felt in an earthquake, how far to trust it, and the
same town in the strongest earthquakes around. No damage, no risk, no alert.
- `Dockerfile` and `compose.yaml`: `ingv-shakemap-ui` on 3010,
`ingv-shakemap-notebooks` on 8890, `ingv-shakemap-mcp` on 8774. A Makefile
with `help` and targets for the containers, the data and the notebooks.
- A benchmark of five known earthquakes in CI (`benchmarks/`): the map
against the 119 stations that recorded, what the library reads at 17
town-and-earthquake pairs, and a faithfulness set of hand-written answers.
- Four numbered notebooks, `llms.txt` and `llms-full.txt` on the
documentation site, the agent skill, `publiccode.yml`.

### Changed

- `make check` also runs the benchmark.

## [0.3.0] - 2026-11-28

### Added
Expand Down
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

Issues and pull requests are welcome.

- Run `make check` before pushing: ruff, `mypy --strict` and pytest must be
clean, the same gate CI runs.
- Run `make check` before pushing: ruff, `mypy --strict`, pytest and the
benchmark must be clean, the same gate CI runs. `make help` lists the rest.
- A change in what the library reads on the benchmark's maps fails
`make benchmark`: if you meant it, `make benchmark-record` and say why.
- Commits follow [Conventional Commits](https://www.conventionalcommits.org/).
- Contributions are accepted under the project's license, Apache-2.0
(section 5 of the license: inbound = outbound). No separate CLA.
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ingv-shakemap in a container: the library, the `ingv-shakemap` command and
# the `ingv-shakemap-mcp` server (target "app"), Jupyter with the example
# notebooks (target "notebooks") and the page for a municipality (target
# "web"). Built from this folder, so it runs the code you see.
#
# make up the MCP server on http://localhost:8774/mcp
# make notebooks Jupyter on http://localhost:8890
# make app-up the page for a municipality on http://localhost:3010

FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS app

ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PROJECT_ENVIRONMENT=/opt/venv \
PATH=/opt/venv/bin:$PATH \
PYTHONUNBUFFERED=1 \
DATA_ROOT=/data

WORKDIR /app
COPY pyproject.toml uv.lock README.md LICENSE ./
COPY src ./src
RUN uv sync --locked --no-dev --no-editable --extra mcp

RUN useradd --create-home --uid 1000 shakemap \
&& mkdir -p /data/ingv-shakemap \
&& chown shakemap /data/ingv-shakemap
USER shakemap
WORKDIR /home/shakemap

EXPOSE 8774
CMD ["ingv-shakemap-mcp"]


FROM app AS notebooks

USER root
WORKDIR /app
RUN uv sync --locked --no-dev --no-editable --extra mcp --group examples
# The notebooks read the maps of the benchmark, at the same relative path.
COPY benchmarks /home/shakemap/benchmarks
COPY notebooks /home/shakemap/notebooks
RUN chown -R shakemap /home/shakemap
USER shakemap
WORKDIR /home/shakemap/notebooks

EXPOSE 8888
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser"]


FROM app AS web

USER root
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
RUN uv sync --locked --no-dev --no-editable --extra mcp --group app
COPY app ./app
RUN sh app/vendor.sh && chown -R shakemap /app/app
USER shakemap

EXPOSE 3010
CMD ["uvicorn", "--factory", "app.api:create_app", "--host", "0.0.0.0", "--port", "3010"]
Loading
Loading