limen-common 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- limen_common-0.1.1/LICENSE +202 -0
- limen_common-0.1.1/PKG-INFO +134 -0
- limen_common-0.1.1/README.md +106 -0
- limen_common-0.1.1/pyproject.toml +108 -0
- limen_common-0.1.1/pyproject.toml.orig +82 -0
- limen_common-0.1.1/src/limen_common/__init__.py +64 -0
- limen_common-0.1.1/src/limen_common/check.py +603 -0
- limen_common-0.1.1/src/limen_common/danger.py +51 -0
- limen_common-0.1.1/src/limen_common/facts.py +93 -0
- limen_common-0.1.1/src/limen_common/geo.py +108 -0
- limen_common-0.1.1/src/limen_common/http.py +125 -0
- limen_common-0.1.1/src/limen_common/llms.py +285 -0
- limen_common-0.1.1/src/limen_common/paths.py +70 -0
- limen_common-0.1.1/src/limen_common/py.typed +0 -0
- limen_common-0.1.1/src/limen_common/record.py +767 -0
- limen_common-0.1.1/src/limen_common/reliability.py +108 -0
- limen_common-0.1.1/src/limen_common/schema/opendata-record-v2.json +647 -0
- limen_common-0.1.1/src/limen_common/stats.py +78 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: limen-common
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Shared building blocks for the Limen libraries: one retry policy, one data folder, one point and box, one way to take a quantile, one fire danger table, one reliability type, one open-data record and one answer checker
|
|
5
|
+
Keywords: limen,open data,retry,geo,reliability,fire weather index,json schema,llms.txt
|
|
6
|
+
Author: Giuseppe Zileni
|
|
7
|
+
Author-email: Giuseppe Zileni <giuseppe.zileni@gmail.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Dist: httpx>=0.27 ; extra == 'http'
|
|
18
|
+
Requires-Dist: griffe>=1.5 ; extra == 'llms'
|
|
19
|
+
Requires-Dist: jsonschema>=4.23 ; extra == 'record'
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Project-URL: Homepage, https://github.com/agent-engineering-studio/limen-common
|
|
22
|
+
Project-URL: Issues, https://github.com/agent-engineering-studio/limen-common/issues
|
|
23
|
+
Project-URL: Changelog, https://github.com/agent-engineering-studio/limen-common/blob/main/CHANGELOG.md
|
|
24
|
+
Provides-Extra: http
|
|
25
|
+
Provides-Extra: llms
|
|
26
|
+
Provides-Extra: record
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# limen-common
|
|
30
|
+
|
|
31
|
+
Shared building blocks for the Limen libraries.
|
|
32
|
+
|
|
33
|
+
Every library of the Limen family wrote its own retry loop, data folder,
|
|
34
|
+
bounding box, quantile and reliability score, each a little different: six
|
|
35
|
+
retry loops that disagree on whether a 500 is worth another try, six bounding
|
|
36
|
+
boxes, three ways to take a percentile, four scales for "how far to trust
|
|
37
|
+
this". `limen-common` holds one of each, so the libraries agree.
|
|
38
|
+
|
|
39
|
+
| Module | What | Replaces |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `limen_common.http` (extra `[http]`) | `RetryPolicy`, `send` (async), `send_sync`: 429/5xx and transport errors retried with exponential backoff, `Retry-After` honoured, everything else returned as it is | the retry loops of dpc-radar, egms-client, ingv-shakemap, copernicus-ems, firms-client, imageserver-export; none in effis-client |
|
|
42
|
+
| `limen_common.paths` | `data_dir(lib)`: the argument, then `<LIB>_DATA_DIR`, then `$DATA_ROOT/<lib>`, then `./data/<lib>`; `atomic_write` through `.part` and a rename | each library's own folder rule and `.part` writes |
|
|
43
|
+
| `limen_common.geo` | `Point` and `BBox`, longitude first and range-checked; `ITALY`; `haversine_m`; `BBox.around` | six `BBox` types, `(lon, lat)` tuples and `Node`s, three haversines |
|
|
44
|
+
| `limen_common.stats` | `quantile`, `quantiles`, `rank`: linear interpolation (numpy/R type 7) by default, nearest rank by name; `None` and `NaN` left out | nearest rank (effis-client), linear (fwi-chain), the ad hoc ones |
|
|
45
|
+
| `limen_common.danger` | the EFFIS FWI classes and `effis_class` | the copies in fwi-chain and effis-client ("very high" vs "Very High") |
|
|
46
|
+
| `limen_common.reliability` | `Reliability(measured, score, reasons)`, its `level` (none, poor, fair, good) and `weakest(*parts)` | dpc-radar's score, glofas-ewds' word, rainfall-thresholds' interval, egms-client's thresholds |
|
|
47
|
+
| `limen_common.record` (extra `[record]` to check) | the open-data record `opendata-record/v2`: typed `Observation`, `Fact`, `Event`, `Layer`, the JSON Schema, `problems`, `validate`, `read`, `from_csv` | the schema kept in egms-client; the record built by hand in rainfall-thresholds |
|
|
48
|
+
| `limen_common.check` | one answer checker: `check_text(text, facts, *, lang, question, rules) -> list[Misquote]`, `check_signs`, `check_claims`, `fill`; units and direction words as data in `Rules` | the checkers of rainfall-thresholds, egms-client, fwi-chain, effis-client, ingv-shakemap, firms-client, with diverging signatures |
|
|
49
|
+
| `limen_common.facts` | `stamp`, `rounded`, the shared `ANSWER_RULES` and `answer_rules(about, *rules)` | each library's `stamp`, `_round` and the rules repeated in every `ANSWER_RULES` |
|
|
50
|
+
| `limen_common.llms` (extra `[llms]` for API pages) | `Site` and `main`: `llms.txt`, `llms-full.txt` and the agent skill from `zensical.toml` and the docstrings | the nine copies of `tools/build_llms.py` |
|
|
51
|
+
|
|
52
|
+
## The convention
|
|
53
|
+
|
|
54
|
+
**`None` means "not measured".** It is never zero, never `NaN`, never a
|
|
55
|
+
neutral 0.5. A radar outage, a cell with no InSAR pixel, a region with no
|
|
56
|
+
dated landslide are not dry weather, still ground or a safe slope: a function
|
|
57
|
+
that cannot answer says so, and `Reliability.not_measured(...)` says why.
|
|
58
|
+
|
|
59
|
+
**Nothing reads the clock.** A function that needs "today" takes it.
|
|
60
|
+
|
|
61
|
+
**Longitude first**, as GeoJSON: `Point(lon, lat)`, `BBox(west, south, east, north)`.
|
|
62
|
+
`Point.from_lat_lon` and `BBox.lat_lon()` are there for the services that put
|
|
63
|
+
latitude first.
|
|
64
|
+
|
|
65
|
+
## Install
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
uv add "limen-common[http]" # with the retry policy (httpx)
|
|
69
|
+
uv add "limen-common[record]" # checking records (jsonschema)
|
|
70
|
+
uv add "limen-common[llms]" # API pages in llms-full.txt (griffe)
|
|
71
|
+
uv add limen-common # the rest has no dependency
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Examples
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import httpx
|
|
78
|
+
from limen_common import Point, Reliability, data_dir, quantile, weakest
|
|
79
|
+
from limen_common.http import RetryPolicy, send
|
|
80
|
+
|
|
81
|
+
folder = data_dir("dpc-radar") # $DATA_ROOT/dpc-radar
|
|
82
|
+
sarno = Point.of(14.62, 40.81)
|
|
83
|
+
|
|
84
|
+
async with httpx.AsyncClient() as client:
|
|
85
|
+
response = await send(client, "GET", url, policy=RetryPolicy(retries=4))
|
|
86
|
+
|
|
87
|
+
p95 = quantile([12.0, None, 30.5, 8.1], 0.95) # None is left out
|
|
88
|
+
|
|
89
|
+
answer = weakest(
|
|
90
|
+
Reliability.of(0.8, "radar visible from two sites"),
|
|
91
|
+
Reliability.not_measured("no rain gauge within 20 km"),
|
|
92
|
+
)
|
|
93
|
+
answer.measured # False: one part was not measured
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
A record, checked, and a text checked against its facts:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from datetime import UTC, datetime
|
|
100
|
+
from limen_common import Point, Reliability
|
|
101
|
+
from limen_common.check import check_text
|
|
102
|
+
from limen_common.record import MadeBy, Observation, Source, Time, Trust
|
|
103
|
+
|
|
104
|
+
record = Observation(
|
|
105
|
+
source=Source(name="DPC radar", licence="CC BY-SA 4.0"),
|
|
106
|
+
made_by=MadeBy("dpc-radar", "1.2.0"),
|
|
107
|
+
time=Time.at(datetime(2026, 10, 10, 12, tzinfo=UTC)),
|
|
108
|
+
where=Point(11.25, 43.77),
|
|
109
|
+
reliability=Trust.of(Reliability.of(0.8, "two radars see it"), "radar visibility"),
|
|
110
|
+
property="rainfall",
|
|
111
|
+
value=12.5,
|
|
112
|
+
unit="mm",
|
|
113
|
+
).check() # a dict valid against opendata-record/v2, or RecordError with every problem
|
|
114
|
+
|
|
115
|
+
facts = {"total_mm": 165.7, "needed_mm": 30.9}
|
|
116
|
+
check_text("165.7 mm fell; the threshold asks 30.9 mm/h", facts)
|
|
117
|
+
# [Misquote(said='30.9 mm/h', fault='unit', unit='mm/h', key='needed_mm', fact=30.9)]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The checker's faults are `invented`, `unit`, `rounded`, `sign` and `swapped`.
|
|
121
|
+
What is a library's own (a unit like `decades`, a word like *sinks*) goes in
|
|
122
|
+
`Rules`: `RULES.with_units({"decades": "decades"}, keys=[("_decades", "decades")])`,
|
|
123
|
+
`RULES.with_directions(down={"en": ["sinks?"]})`.
|
|
124
|
+
|
|
125
|
+
## Moving a library onto it
|
|
126
|
+
|
|
127
|
+
One library at a time, behaviour first: replace its own helper with the one
|
|
128
|
+
here, keep its public names as thin aliases for one minor release, and note any
|
|
129
|
+
change of behaviour (a status now retried, a quantile method) in its CHANGELOG.
|
|
130
|
+
The issues "Adopt limen-common" in each repository track it.
|
|
131
|
+
|
|
132
|
+
## Licence
|
|
133
|
+
|
|
134
|
+
Apache-2.0.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# limen-common
|
|
2
|
+
|
|
3
|
+
Shared building blocks for the Limen libraries.
|
|
4
|
+
|
|
5
|
+
Every library of the Limen family wrote its own retry loop, data folder,
|
|
6
|
+
bounding box, quantile and reliability score, each a little different: six
|
|
7
|
+
retry loops that disagree on whether a 500 is worth another try, six bounding
|
|
8
|
+
boxes, three ways to take a percentile, four scales for "how far to trust
|
|
9
|
+
this". `limen-common` holds one of each, so the libraries agree.
|
|
10
|
+
|
|
11
|
+
| Module | What | Replaces |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| `limen_common.http` (extra `[http]`) | `RetryPolicy`, `send` (async), `send_sync`: 429/5xx and transport errors retried with exponential backoff, `Retry-After` honoured, everything else returned as it is | the retry loops of dpc-radar, egms-client, ingv-shakemap, copernicus-ems, firms-client, imageserver-export; none in effis-client |
|
|
14
|
+
| `limen_common.paths` | `data_dir(lib)`: the argument, then `<LIB>_DATA_DIR`, then `$DATA_ROOT/<lib>`, then `./data/<lib>`; `atomic_write` through `.part` and a rename | each library's own folder rule and `.part` writes |
|
|
15
|
+
| `limen_common.geo` | `Point` and `BBox`, longitude first and range-checked; `ITALY`; `haversine_m`; `BBox.around` | six `BBox` types, `(lon, lat)` tuples and `Node`s, three haversines |
|
|
16
|
+
| `limen_common.stats` | `quantile`, `quantiles`, `rank`: linear interpolation (numpy/R type 7) by default, nearest rank by name; `None` and `NaN` left out | nearest rank (effis-client), linear (fwi-chain), the ad hoc ones |
|
|
17
|
+
| `limen_common.danger` | the EFFIS FWI classes and `effis_class` | the copies in fwi-chain and effis-client ("very high" vs "Very High") |
|
|
18
|
+
| `limen_common.reliability` | `Reliability(measured, score, reasons)`, its `level` (none, poor, fair, good) and `weakest(*parts)` | dpc-radar's score, glofas-ewds' word, rainfall-thresholds' interval, egms-client's thresholds |
|
|
19
|
+
| `limen_common.record` (extra `[record]` to check) | the open-data record `opendata-record/v2`: typed `Observation`, `Fact`, `Event`, `Layer`, the JSON Schema, `problems`, `validate`, `read`, `from_csv` | the schema kept in egms-client; the record built by hand in rainfall-thresholds |
|
|
20
|
+
| `limen_common.check` | one answer checker: `check_text(text, facts, *, lang, question, rules) -> list[Misquote]`, `check_signs`, `check_claims`, `fill`; units and direction words as data in `Rules` | the checkers of rainfall-thresholds, egms-client, fwi-chain, effis-client, ingv-shakemap, firms-client, with diverging signatures |
|
|
21
|
+
| `limen_common.facts` | `stamp`, `rounded`, the shared `ANSWER_RULES` and `answer_rules(about, *rules)` | each library's `stamp`, `_round` and the rules repeated in every `ANSWER_RULES` |
|
|
22
|
+
| `limen_common.llms` (extra `[llms]` for API pages) | `Site` and `main`: `llms.txt`, `llms-full.txt` and the agent skill from `zensical.toml` and the docstrings | the nine copies of `tools/build_llms.py` |
|
|
23
|
+
|
|
24
|
+
## The convention
|
|
25
|
+
|
|
26
|
+
**`None` means "not measured".** It is never zero, never `NaN`, never a
|
|
27
|
+
neutral 0.5. A radar outage, a cell with no InSAR pixel, a region with no
|
|
28
|
+
dated landslide are not dry weather, still ground or a safe slope: a function
|
|
29
|
+
that cannot answer says so, and `Reliability.not_measured(...)` says why.
|
|
30
|
+
|
|
31
|
+
**Nothing reads the clock.** A function that needs "today" takes it.
|
|
32
|
+
|
|
33
|
+
**Longitude first**, as GeoJSON: `Point(lon, lat)`, `BBox(west, south, east, north)`.
|
|
34
|
+
`Point.from_lat_lon` and `BBox.lat_lon()` are there for the services that put
|
|
35
|
+
latitude first.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
uv add "limen-common[http]" # with the retry policy (httpx)
|
|
41
|
+
uv add "limen-common[record]" # checking records (jsonschema)
|
|
42
|
+
uv add "limen-common[llms]" # API pages in llms-full.txt (griffe)
|
|
43
|
+
uv add limen-common # the rest has no dependency
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import httpx
|
|
50
|
+
from limen_common import Point, Reliability, data_dir, quantile, weakest
|
|
51
|
+
from limen_common.http import RetryPolicy, send
|
|
52
|
+
|
|
53
|
+
folder = data_dir("dpc-radar") # $DATA_ROOT/dpc-radar
|
|
54
|
+
sarno = Point.of(14.62, 40.81)
|
|
55
|
+
|
|
56
|
+
async with httpx.AsyncClient() as client:
|
|
57
|
+
response = await send(client, "GET", url, policy=RetryPolicy(retries=4))
|
|
58
|
+
|
|
59
|
+
p95 = quantile([12.0, None, 30.5, 8.1], 0.95) # None is left out
|
|
60
|
+
|
|
61
|
+
answer = weakest(
|
|
62
|
+
Reliability.of(0.8, "radar visible from two sites"),
|
|
63
|
+
Reliability.not_measured("no rain gauge within 20 km"),
|
|
64
|
+
)
|
|
65
|
+
answer.measured # False: one part was not measured
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A record, checked, and a text checked against its facts:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from datetime import UTC, datetime
|
|
72
|
+
from limen_common import Point, Reliability
|
|
73
|
+
from limen_common.check import check_text
|
|
74
|
+
from limen_common.record import MadeBy, Observation, Source, Time, Trust
|
|
75
|
+
|
|
76
|
+
record = Observation(
|
|
77
|
+
source=Source(name="DPC radar", licence="CC BY-SA 4.0"),
|
|
78
|
+
made_by=MadeBy("dpc-radar", "1.2.0"),
|
|
79
|
+
time=Time.at(datetime(2026, 10, 10, 12, tzinfo=UTC)),
|
|
80
|
+
where=Point(11.25, 43.77),
|
|
81
|
+
reliability=Trust.of(Reliability.of(0.8, "two radars see it"), "radar visibility"),
|
|
82
|
+
property="rainfall",
|
|
83
|
+
value=12.5,
|
|
84
|
+
unit="mm",
|
|
85
|
+
).check() # a dict valid against opendata-record/v2, or RecordError with every problem
|
|
86
|
+
|
|
87
|
+
facts = {"total_mm": 165.7, "needed_mm": 30.9}
|
|
88
|
+
check_text("165.7 mm fell; the threshold asks 30.9 mm/h", facts)
|
|
89
|
+
# [Misquote(said='30.9 mm/h', fault='unit', unit='mm/h', key='needed_mm', fact=30.9)]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The checker's faults are `invented`, `unit`, `rounded`, `sign` and `swapped`.
|
|
93
|
+
What is a library's own (a unit like `decades`, a word like *sinks*) goes in
|
|
94
|
+
`Rules`: `RULES.with_units({"decades": "decades"}, keys=[("_decades", "decades")])`,
|
|
95
|
+
`RULES.with_directions(down={"en": ["sinks?"]})`.
|
|
96
|
+
|
|
97
|
+
## Moving a library onto it
|
|
98
|
+
|
|
99
|
+
One library at a time, behaviour first: replace its own helper with the one
|
|
100
|
+
here, keep its public names as thin aliases for one minor release, and note any
|
|
101
|
+
change of behaviour (a status now retried, a quantile method) in its CHANGELOG.
|
|
102
|
+
The issues "Adopt limen-common" in each repository track it.
|
|
103
|
+
|
|
104
|
+
## Licence
|
|
105
|
+
|
|
106
|
+
Apache-2.0.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "limen-common"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "Shared building blocks for the Limen libraries: one retry policy, one data folder, one point and box, one way to take a quantile, one fire danger table, one reliability type, one open-data record and one answer checker"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
keywords = [
|
|
7
|
+
"limen",
|
|
8
|
+
"open data",
|
|
9
|
+
"retry",
|
|
10
|
+
"geo",
|
|
11
|
+
"reliability",
|
|
12
|
+
"fire weather index",
|
|
13
|
+
"json schema",
|
|
14
|
+
"llms.txt",
|
|
15
|
+
]
|
|
16
|
+
requires-python = ">=3.12"
|
|
17
|
+
license = "Apache-2.0"
|
|
18
|
+
license-files = ["LICENSE"]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 3 - Alpha",
|
|
21
|
+
"Intended Audience :: Science/Research",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
dependencies = []
|
|
29
|
+
|
|
30
|
+
[[project.authors]]
|
|
31
|
+
name = "Giuseppe Zileni"
|
|
32
|
+
email = "giuseppe.zileni@gmail.com"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
http = ["httpx>=0.27"]
|
|
36
|
+
record = ["jsonschema>=4.23"]
|
|
37
|
+
llms = ["griffe>=1.5"]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/agent-engineering-studio/limen-common"
|
|
41
|
+
Issues = "https://github.com/agent-engineering-studio/limen-common/issues"
|
|
42
|
+
Changelog = "https://github.com/agent-engineering-studio/limen-common/blob/main/CHANGELOG.md"
|
|
43
|
+
|
|
44
|
+
[build-system]
|
|
45
|
+
requires = ["uv_build>=0.13.6,<0.14"]
|
|
46
|
+
build-backend = "uv_build"
|
|
47
|
+
|
|
48
|
+
[dependency-groups]
|
|
49
|
+
dev = [
|
|
50
|
+
"griffe>=1.5",
|
|
51
|
+
"httpx>=0.27",
|
|
52
|
+
"jsonschema>=4.23",
|
|
53
|
+
"mypy>=1.13",
|
|
54
|
+
"pytest>=8.3",
|
|
55
|
+
"pytest-cov>=6.0",
|
|
56
|
+
"ruff>=0.8",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
[tool.ruff]
|
|
60
|
+
line-length = 100
|
|
61
|
+
target-version = "py312"
|
|
62
|
+
|
|
63
|
+
[tool.ruff.lint]
|
|
64
|
+
select = [
|
|
65
|
+
"E",
|
|
66
|
+
"F",
|
|
67
|
+
"W",
|
|
68
|
+
"I",
|
|
69
|
+
"N",
|
|
70
|
+
"UP",
|
|
71
|
+
"B",
|
|
72
|
+
"C4",
|
|
73
|
+
"SIM",
|
|
74
|
+
"ARG",
|
|
75
|
+
"PTH",
|
|
76
|
+
"RUF",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[tool.ruff.lint.per-file-ignores]
|
|
80
|
+
"tests/**" = [
|
|
81
|
+
"ARG",
|
|
82
|
+
"B018",
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[tool.mypy]
|
|
86
|
+
strict = true
|
|
87
|
+
python_version = "3.12"
|
|
88
|
+
files = [
|
|
89
|
+
"src",
|
|
90
|
+
"tests",
|
|
91
|
+
]
|
|
92
|
+
warn_unused_ignores = true
|
|
93
|
+
warn_redundant_casts = true
|
|
94
|
+
|
|
95
|
+
[[tool.mypy.overrides]]
|
|
96
|
+
module = ["jsonschema.*"]
|
|
97
|
+
ignore_missing_imports = true
|
|
98
|
+
|
|
99
|
+
[tool.pytest.ini_options]
|
|
100
|
+
testpaths = ["tests"]
|
|
101
|
+
addopts = "--strict-markers"
|
|
102
|
+
|
|
103
|
+
[tool.coverage.run]
|
|
104
|
+
source = ["limen_common"]
|
|
105
|
+
|
|
106
|
+
[tool.coverage.report]
|
|
107
|
+
fail_under = 95
|
|
108
|
+
show_missing = true
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "limen-common"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "Shared building blocks for the Limen libraries: one retry policy, one data folder, one point and box, one way to take a quantile, one fire danger table, one reliability type, one open-data record and one answer checker"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
keywords = ["limen", "open data", "retry", "geo", "reliability", "fire weather index", "json schema", "llms.txt"]
|
|
7
|
+
requires-python = ">=3.12"
|
|
8
|
+
license = "Apache-2.0"
|
|
9
|
+
license-files = ["LICENSE"]
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Giuseppe Zileni", email = "giuseppe.zileni@gmail.com" },
|
|
12
|
+
]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Science/Research",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
dependencies = []
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
# limen_common.http: the retry policy around an httpx client.
|
|
26
|
+
http = ["httpx>=0.27"]
|
|
27
|
+
# limen_common.record: checking a record against the JSON Schema.
|
|
28
|
+
record = ["jsonschema>=4.23"]
|
|
29
|
+
# limen_common.llms: the API reference of llms-full.txt, from the docstrings.
|
|
30
|
+
llms = ["griffe>=1.5"]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/agent-engineering-studio/limen-common"
|
|
34
|
+
Issues = "https://github.com/agent-engineering-studio/limen-common/issues"
|
|
35
|
+
Changelog = "https://github.com/agent-engineering-studio/limen-common/blob/main/CHANGELOG.md"
|
|
36
|
+
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["uv_build>=0.13.6,<0.14"]
|
|
39
|
+
build-backend = "uv_build"
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"griffe>=1.5",
|
|
44
|
+
"httpx>=0.27",
|
|
45
|
+
"jsonschema>=4.23",
|
|
46
|
+
"mypy>=1.13",
|
|
47
|
+
"pytest>=8.3",
|
|
48
|
+
"pytest-cov>=6.0",
|
|
49
|
+
"ruff>=0.8",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
line-length = 100
|
|
54
|
+
target-version = "py312"
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint]
|
|
57
|
+
select = ["E", "F", "W", "I", "N", "UP", "B", "C4", "SIM", "ARG", "PTH", "RUF"]
|
|
58
|
+
|
|
59
|
+
[tool.ruff.lint.per-file-ignores]
|
|
60
|
+
"tests/**" = ["ARG", "B018"]
|
|
61
|
+
|
|
62
|
+
[tool.mypy]
|
|
63
|
+
strict = true
|
|
64
|
+
python_version = "3.12"
|
|
65
|
+
files = ["src", "tests"]
|
|
66
|
+
warn_unused_ignores = true
|
|
67
|
+
warn_redundant_casts = true
|
|
68
|
+
|
|
69
|
+
[[tool.mypy.overrides]]
|
|
70
|
+
module = ["jsonschema.*"]
|
|
71
|
+
ignore_missing_imports = true
|
|
72
|
+
|
|
73
|
+
[tool.pytest.ini_options]
|
|
74
|
+
testpaths = ["tests"]
|
|
75
|
+
addopts = "--strict-markers"
|
|
76
|
+
|
|
77
|
+
[tool.coverage.run]
|
|
78
|
+
source = ["limen_common"]
|
|
79
|
+
|
|
80
|
+
[tool.coverage.report]
|
|
81
|
+
fail_under = 95
|
|
82
|
+
show_missing = true
|