Facts¶
glofas_ewds.facts ¶
The numbers an assistant, or a page, may quote: each with its source and its age.
No network: everything is read from a :class:~glofas_ewds.store.Store.
Ask a language model "is the Lamone high?" and it answers 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 says which river cell it was read
from, where the data came from, when it was fetched and how many days old it
is, and how far GloFAS can be trusted on a river of that size. The model words
the answer; it does not compute it. This is what the command line and the
demo serve, and what an assistant or a tool server built on this package
should call::
facts = Facts(Store("data/glofas-ewds"))
facts.forecast("faenza")
- :meth:
Facts.places: the places of the store, and how old their data are. - :meth:
Facts.river: the river cell of a place, and how far to trust it. - :meth:
Facts.discharge: the last day of discharge against the place's own history. - :meth:
Facts.forecast: the forecast peak, its return period, and what stands behind it. - :meth:
Facts.summary: all three, for one place. - :meth:
Facts.check_text: the numbers of a text that are in none of the facts of a place.
:data:ANSWER_RULES is the same rules written for whoever words an answer
from these facts: give it to the model as its instructions.
The rules every answer follows:
Nonemeans not known, which is never "low" and never "no flood". A return period ofNoneis "below the 2-year flow" only whenbelow_two_year_flowis true; otherwise it could not be computed;- m³/s are rounded to 0.1 and shares to 0.01: the model does not know more;
- a forecast is labelled as a forecast, with its run;
- nothing here is an alert. The alert is the bulletin of the civil protection.
ANSWER_RULES
module-attribute
¶
ANSWER_RULES: Final[str] = 'River discharge from GloFAS 4, the global flood model of Copernicus, for the\nplaces someone stored on this machine. The data are read from disk, not from\nthe network: they are as old as their last download.\n\nRules for whoever answers with these facts (Facts.places, Facts.river,\nFacts.discharge, Facts.forecast, Facts.summary, Facts.check_text):\n\n- Every number you give must come from a result of these functions. Do not\n estimate, add up, convert or extrapolate numbers yourself. A share is\n written as in the result (0.61), not turned into a percentage.\n- Say how old the data are: each result has "age_days", "fetched" and\n "source". If the forecast run is more than a day old, say so first.\n- null means not known. It is never "low" and never "no flood".\n- The discharge is the mean of a day on a cell of about 5 km, from a model:\n it is not a gauge reading, and a flood of a few hours is not in it.\n- "trust" says how far GloFAS can be trusted on a river of that size, with\n the known floods it saw ("track_record"). Those counts are of the\n reanalysis, not of the forecasts issued at the time: quote them as such.\n If the level is "poor" or "none", say it before any number.\n- "forecast" is a forecast: present it as one, with its run. "ensemble" is\n how many of the members reach the 2-year flow; "persistence" is how many\n runs in a row forecast it, or null when no earlier run is stored. They\n are facts about the forecast, not a probability of flooding.\n- "return_period_years" is the longest official GloFAS threshold the value\n reaches (2, 5 or 20 years), in the model\'s own world. When it is null,\n read "below_two_year_flow": true is below the 2-year flow, null is not\n known.\n- Before answering, pass your text to Facts.check_text: every number it\n lists in "not_in_the_facts" is one you must remove or correct.\n- Nothing here is an alert. The official alert is the bulletin of the civil\n protection. For danger to people, point to it and to 112.\n\nData: GloFAS, Copernicus Emergency Management Service (CEMS), served by the\nEarly Warning Data Store or by Open-Meteo: each result names which.\n'
The rules for whoever words an answer from :class:Facts.
Meant for whoever builds an assistant, or a tool server, on the functions of
this package: pass it to the model as its instructions (the system prompt, or
the instructions of the server), and expose each method of :class:Facts as
a tool of the same name.
Facts ¶
Answers about the places of a store, as dictionaries of facts.
places ¶
places() -> dict[str, Any]
The places of the store: where, whether a river was found, how old the data are.
river ¶
river(place_id: str) -> dict[str, Any]
The river cell of a place, its official thresholds, and how far to trust it.
river_of ¶
river_of(place: Place) -> dict[str, Any]
:meth:river for a place that is not in the store (:func:glofas_ewds.local.locate).
discharge ¶
discharge(place_id: str) -> dict[str, Any]
The last day of discharge of a place's river, against its own history.
forecast ¶
forecast(place_id: str) -> dict[str, Any]
The forecast peak of a place's river, its return period and what stands behind it.
summary ¶
summary(place_id: str) -> dict[str, Any]
Everything about one place: its river, the last discharge, the forecast.
check_text ¶
check_text(place_id: str, text: str) -> dict[str, Any]
Check a text written about a place against all the facts of that place.
The numbers of text that are in none of the facts of
:meth:summary (see :func:glofas_ewds.text.check_text for how a
number is matched). faithful is true when every number is a fact::
{"place": "faenza", "not_in_the_facts": ["170"], "faithful": False}
Raises :class:~glofas_ewds.errors.GlofasEwdsError when the store has
no such place.