Facts: the rain as data an assistant can quote¶
Facts answers the questions an assistant is asked about the rain over Italy
("how much has it rained on Messina in the last three hours?") with a plain
dictionary, ready for JSON, that names the product and the time of the frame
it was computed from. The model words the answer; it does not compute it.
dpc-radar is a data library: it has no server of its own. An assistant, or a
tool server such as an MCP server, calls these methods and gives the model
ANSWER_RULES with them.
pip install "dpc-radar[facts]" # scipy and shapely: storms, nowcast, alert zones
from dpc_radar import RadarClient
from dpc_radar.facts import ANSWER_RULES, Facts
async with RadarClient() as radar:
facts = Facts(radar)
print(await facts.rain_at(15.78, 37.92, hours=3))
print(await facts.area_summary(15.5, 37.85, 16.2, 38.3, hours=24))
No key: the data are open.
| Method | What it answers |
|---|---|
latest() |
the newest frame of every product, and how often a new one comes |
rain_at(lon, lat, hours=1) |
the rain of the last 1, 3, 6, 12 or 24 hours at a point: the median of 3×3 pixels, with the reliability of the radar there |
area_summary(west, south, east, north, hours=1) |
over a box: maximum and where, mean, median, 95th percentile, km² over 1, 5, 10, 20, 50 and 100 mm |
storm_now(west, south, east, north) |
the storms on the newest intensity frame (patches at 10 mm/h or more), with their motion; all of Italy without a box |
rain_ahead(lon, lat, minutes=60, mm=20) |
the nowcast at a point, labelled as a forecast, with the chance of at least mm |
official_alert(lon, lat, place) |
the level of the criticality bulletin: the zone of a point, the zones of a municipality or with a name, or every zone on alert |
rarity(lon, lat, hours, mm) |
the return period of an amount of radar rain at a place (not a coroutine) |
radar_status(lon, lat) |
which radars the DPC viewer reports as on: those in range of a point, or all of them. A hint from an undocumented file, null when not known |
This is the answer of rain_at(15.78, 37.92, hours=3):
{
"lon": 15.78, "lat": 37.92, "hours": 3,
"mm": 0.0, "measured": true,
"method": "median of the 3x3 pixels around the point",
"frame": {
"product": "CUM3", "time": "2026-11-17T10:30Z", "unit": "mm", "hours": 3,
"source": "radar and rain gauges («Merging»)"
},
"quality": {
"verdict": "consistent", "trusted_share": 1.0, "masked_pixels": 0,
"reasons": {"jump": 0, "beyond_record": 0, "outlier": 0, "gauge_only": 0},
"newest_frame_rejected": null
},
"reliability": {
"score": 0.9, "reliable": true, "beam_height_m": 1100.0,
"nearest_radar": "Catania Fontanarossa", "distance_km": 81.7
},
"note": "radar data, not an alert: the official alert is the DPC bulletin"
}
What keeps the numbers honest.
- Every answer carries its
frame: product and time. One hour is the radar alone (SRT1), three hours and more are the «Merging»; the answer says which. - Each frame goes through
qualityagainst the frame before it. If the newest frame is rejected, the answer is read from the one before and says so (newest_frame_rejected). Pixels that fail a rule are masked. - Not measured is
null, with a note, never zero. rain_aheadanswers"kind": "forecast", with its limits in words.- What the library refuses (a window that does not exist, half a box) is a
DpcRadarErroror aValueErrorwhose message a model can read:the DPC publishes the rain of [1, 3, 6, 12, 24] hours, not of 2. radar_statusexplains a hole in the data; it never says the data are good. A radar reported on may be missing from the mosaic.ANSWER_RULEStells the model not to add up or estimate numbers itself, and that nothing here is an alert.
A model can still word a number badly: the facts and the rules cannot read
its answer. For a text that must be right, see the event
reports, where every number of the text is checked
(dpc-radar check).
official_alert and regions. The bulletin names alert zones ("Versante
Jonico Meridionale") and their municipalities, not regions. place matches
a municipality (in Italian, the whole name) or part of a zone name; for a
region, ask by point or read the list of zones on alert.
dpc_radar.facts ¶
The numbers an assistant may quote, each with the frame it came from.
A language model that is asked "how much did it rain in Florence?" will answer
with a number, whether it has one or not. :class:Facts gives it the number:
every answer is a plain dictionary, ready for JSON, that names the product and
the time of the frame it was computed from, how the value was read and how far
the radar can be trusted there. The model words the answer; it does not compute
it. An assistant or a tool server built on these methods should give the model
:data:ANSWER_RULES with them. From Python::
async with RadarClient() as radar:
facts = Facts(radar)
await facts.rain_at(11.25, 43.77, hours=3)
- :meth:
Facts.latest: the newest frame of every product. - :meth:
Facts.rain_at: the rain of the last 1, 3, 6, 12 or 24 hours at a point. - :meth:
Facts.area_summary: the same over a box: maximum, mean, km² over thresholds. - :meth:
Facts.storm_now: the storms on the newest intensity frame, and where they go. - :meth:
Facts.rain_ahead: the nowcast at a point, always labelled as a forecast. - :meth:
Facts.official_alert: the level of the DPC criticality bulletin. - :meth:
Facts.rarity: how rare an amount of rain is at a place. - :meth:
Facts.radar_status: which radars the DPC reports on and off.
The rules every answer follows:
- a point is read as the median of the 3x3 pixels around it, never as one pixel;
- the newest frame goes through :meth:
dpc_radar.RainGrid.qualityagainst the one before it; if it is rejected the answer comes from the frame before, and says so; Nonemeans not measured, which is not the same as dry;- millimetres are rounded to 0.1: the radar does not know more than that.
Frames are kept in memory (cache_frames of them), so a conversation that
asks about ten places downloads each frame once.
Source ¶
Bases: Protocol
Where the frames come from: a :class:dpc_radar.RadarClient, or anything like it.
Facts ¶
Answers about the rain over Italy, as dictionaries that name their frames.
latest
async
¶
latest() -> dict[str, Any]
The newest frame of every product: its time, and how often a new one comes.
rain_at
async
¶
rain_at(lon: float, lat: float, hours: int = 1) -> dict[str, Any]
The rain of the last hours (1, 3, 6, 12 or 24) at a point, in mm.
area_summary
async
¶
area_summary(west: float, south: float, east: float, north: float, hours: int = 1) -> dict[str, Any]
The rain of the last hours over a box in degrees: maximum, mean, km².
storm_now
async
¶
storm_now(west: float | None = None, south: float | None = None, east: float | None = None, north: float | None = None) -> dict[str, Any]
The storms on the newest SRI frame (patches at 10 mm/h or more), heaviest first.
With a box, only those that touch it. moving is the motion of the
rain around the storm over the last half hour: km/h, and the degrees
from north of where it goes (90: east).
rain_ahead
async
¶
rain_ahead(lon: float, lat: float, minutes: int = 60, mm: float = 20.0) -> dict[str, Any]
A forecast: the rain of the next minutes (5 to 120) at a point.
The newest SRI frame moved along the motion of the last half hour
(:mod:dpc_radar.nowcast), and the chance of at least mm.
official_alert
async
¶
official_alert(lon: float | None = None, lat: float | None = None, place: str | None = None) -> dict[str, Any]
The level of the newest DPC criticality bulletin, for today and tomorrow.
With lon and lat: the zone of that point. With place: the
zones whose name contains it, or that hold a municipality of that
name. With neither: every zone on alert (yellow or more).
rarity ¶
rarity(lon: float, lat: float, hours: int, mm: float) -> dict[str, Any]
How rare mm of rain in hours (1, 3, 6 or 24) are at a point.
radar_status
async
¶
radar_status(lon: float | None = None, lat: float | None = None) -> dict[str, Any]
Which radars the DPC reports on and off now (:mod:dpc_radar.status).
With lon and lat: the radars whose range holds the point, the
nearest first. Without: every radar of the status file. known
false means there is no status to read, which is not "all on".
lonlat ¶
lonlat(grid: RainGrid, row: int, col: int) -> tuple[float, float]
The centre of a pixel, in degrees.
describe ¶
describe(part: RainGrid, thresholds: tuple[int, ...] = THRESHOLDS) -> dict[str, Any]
The rain of a frame, or of a piece of one, as numbers.
The mean, the median and the 95th percentile are of the pixels with data,
each weighted by its area. measured_share is the share of the area that
has data: a mean over half a box is the mean of that half.
trust ¶
trust(lon: float, lat: float) -> dict[str, Any]
How far the radar can be trusted at a point (:func:dpc_radar.reliability).
rarity_of ¶
rarity_of(lon: float, lat: float, hours: int, mm: float) -> dict[str, Any]
How rare mm in hours are at a point (:func:dpc_radar.rarity).