limen-core 0.4.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_core-0.4.1/LICENSE +202 -0
- limen_core-0.4.1/PKG-INFO +195 -0
- limen_core-0.4.1/README.md +169 -0
- limen_core-0.4.1/pyproject.toml +135 -0
- limen_core-0.4.1/pyproject.toml.orig +108 -0
- limen_core-0.4.1/src/limen_core/__init__.py +20 -0
- limen_core-0.4.1/src/limen_core/agreement.py +142 -0
- limen_core-0.4.1/src/limen_core/calibration.py +78 -0
- limen_core-0.4.1/src/limen_core/cascades/__init__.py +16 -0
- limen_core-0.4.1/src/limen_core/cascades/attention.py +76 -0
- limen_core-0.4.1/src/limen_core/cascades/config.py +140 -0
- limen_core-0.4.1/src/limen_core/cascades/rules.py +124 -0
- limen_core-0.4.1/src/limen_core/cases.py +137 -0
- limen_core-0.4.1/src/limen_core/flood.py +178 -0
- limen_core-0.4.1/src/limen_core/landslide.py +118 -0
- limen_core-0.4.1/src/limen_core/models/__init__.py +40 -0
- limen_core-0.4.1/src/limen_core/models/context.py +182 -0
- limen_core-0.4.1/src/limen_core/models/hazard.py +30 -0
- limen_core-0.4.1/src/limen_core/models/risk.py +703 -0
- limen_core-0.4.1/src/limen_core/models/sensor.py +64 -0
- limen_core-0.4.1/src/limen_core/post_fire.py +135 -0
- limen_core-0.4.1/src/limen_core/py.typed +0 -0
- limen_core-0.4.1/src/limen_core/scoring/__init__.py +34 -0
- limen_core-0.4.1/src/limen_core/scoring/api.py +69 -0
- limen_core-0.4.1/src/limen_core/scoring/base.py +80 -0
- limen_core-0.4.1/src/limen_core/scoring/caine.py +163 -0
- limen_core-0.4.1/src/limen_core/scoring/engine.py +469 -0
- limen_core-0.4.1/src/limen_core/scoring/exposure.py +136 -0
- limen_core-0.4.1/src/limen_core/scoring/flood/__init__.py +6 -0
- limen_core-0.4.1/src/limen_core/scoring/flood/climatologia.py +85 -0
- limen_core-0.4.1/src/limen_core/scoring/flood/engine.py +175 -0
- limen_core-0.4.1/src/limen_core/scoring/flood/trigger.py +122 -0
- limen_core-0.4.1/src/limen_core/scoring/flood_forecast.py +59 -0
- limen_core-0.4.1/src/limen_core/scoring/kinematic.py +101 -0
- limen_core-0.4.1/src/limen_core/scoring/post_fire.py +85 -0
- limen_core-0.4.1/src/limen_core/scoring/regional_thresholds.py +1339 -0
- limen_core-0.4.1/src/limen_core/scoring/seismic_decay.py +101 -0
- limen_core-0.4.1/src/limen_core/scoring/soglie_regionali.py +129 -0
- limen_core-0.4.1/src/limen_core/scoring/wildfire/__init__.py +5 -0
- limen_core-0.4.1/src/limen_core/scoring/wildfire/climatology.py +54 -0
- limen_core-0.4.1/src/limen_core/scoring/wildfire/confronto.py +80 -0
- limen_core-0.4.1/src/limen_core/scoring/wildfire/engine.py +95 -0
- limen_core-0.4.1/src/limen_core/seismic.py +176 -0
- limen_core-0.4.1/src/limen_core/wildfire.py +272 -0
limen_core-0.4.1/LICENSE
ADDED
|
@@ -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,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: limen-core
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: The joins of Limen: what rain, landslides, fires, floods and earthquakes mean together, as pure functions over the open-data libraries
|
|
5
|
+
Author: Giuseppe Zileni
|
|
6
|
+
Author-email: Giuseppe Zileni <giuseppe.zileni@gmail.com>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Dist: pydantic>=2.9
|
|
17
|
+
Requires-Dist: pyyaml>=6.0
|
|
18
|
+
Requires-Dist: rainfall-thresholds~=0.5.0
|
|
19
|
+
Requires-Dist: fwi-chain~=1.3
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Project-URL: Homepage, https://github.com/agent-engineering-studio/limen-core
|
|
22
|
+
Project-URL: Issues, https://github.com/agent-engineering-studio/limen-core/issues
|
|
23
|
+
Project-URL: Documentation, https://agentengineering.it/limen-core/
|
|
24
|
+
Project-URL: Changelog, https://github.com/agent-engineering-studio/limen-core/blob/main/CHANGELOG.md
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# limen-core
|
|
28
|
+
|
|
29
|
+
[Documentation](https://agentengineering.it/limen-core/) · [Changelog](CHANGELOG.md)
|
|
30
|
+
|
|
31
|
+
**limen-core** holds the joins of [Limen](https://github.com/agent-engineering-studio/limen),
|
|
32
|
+
an open early-warning system for landslides, floods and wildfires in Italy.
|
|
33
|
+
|
|
34
|
+
Each open-data library of the project reads one source and stops there:
|
|
35
|
+
`dpc-radar` the rain radar, `ispra-idrogeo` the landslide inventory,
|
|
36
|
+
`firms-client` the fires seen from satellite, and so on. None of them imports
|
|
37
|
+
another. What two sources say *together* is a join, and it lives here: a burn
|
|
38
|
+
seen by satellite inside a mapped perimeter, an earthquake and the rain that
|
|
39
|
+
follows it, an index we compute next to the official one.
|
|
40
|
+
|
|
41
|
+
```mermaid
|
|
42
|
+
flowchart LR
|
|
43
|
+
L1["dpc-radar · rainfall-thresholds<br/>ispra-idrogeo · egms-client"] --> C
|
|
44
|
+
L2["firms-client · effis-client<br/>fwi-chain"] --> C
|
|
45
|
+
L3["glofas-ewds · copernicus-ems<br/>ingv-shakemap"] --> C
|
|
46
|
+
C["limen-core<br/>the joins, pure functions"] --> A["Limen<br/>database · jobs · API · map"]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
It is **alpha**. Two things are in it: the scoring engines of Limen, moved
|
|
50
|
+
as they are with the tests they had, and three joins rewritten as plain
|
|
51
|
+
functions and checked number by number against the code they come from.
|
|
52
|
+
|
|
53
|
+
## What is in it
|
|
54
|
+
|
|
55
|
+
| Module | What it answers | It joins |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| `limen_core.seismic` | how long a slope stays shaken, and how much less rain it takes after an earthquake | the shaking of `ingv-shakemap` with the thresholds of `rainfall-thresholds` |
|
|
58
|
+
| `limen_core.post_fire` | for how long, and how much, a burnt slope is more ready to fail | the fire power of `firms-client` with the perimeters of `effis-client` |
|
|
59
|
+
| `limen_core.landslide` | the rain before an instant at a place, against the threshold of the place, lowered after an earthquake | a `RainSource` (`dpc-radar`), the thresholds of `rainfall-thresholds`, `seismic` |
|
|
60
|
+
| `limen_core.wildfire` | what the satellite saw inside a burnt perimeter around its day: power, and power per hectare | the detections of `firms-client` with the perimeters of `effis-client`; the density feeds `post_fire` |
|
|
61
|
+
| `limen_core.flood` | a forecast river peak with how far to trust it, when the fluvial branch should not speak alone, and whether a place was seen flooded, dry or not seen | the credibility and trust of `glofas-ewds`, the water over a place of `copernicus-ems` |
|
|
62
|
+
| `limen_core.agreement` | how far two measures of the same thing are from each other | the index of `fwi-chain` with the official ones of `effis-client` and `glofas-ewds` |
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from datetime import UTC, datetime
|
|
66
|
+
|
|
67
|
+
from limen_core.post_fire import PostFireParams, frp_density, frp_severity, post_fire_factor
|
|
68
|
+
from limen_core.seismic import SeismicParams, Shaking, ThresholdMemory, rain_threshold_reduction
|
|
69
|
+
|
|
70
|
+
# An earthquake a month ago: the ground is still, the slope is not as it was.
|
|
71
|
+
params = SeismicParams(
|
|
72
|
+
tau_days=2,
|
|
73
|
+
min_magnitude=4,
|
|
74
|
+
lookback_days=7,
|
|
75
|
+
pga_threshold_g=0.1,
|
|
76
|
+
pga_scale_g=0.03,
|
|
77
|
+
pga_min_g=0.02,
|
|
78
|
+
)
|
|
79
|
+
memory = ThresholdMemory(max_reduction=0.3, memory_days=90, lookback_days=365)
|
|
80
|
+
quake = Shaking(datetime(2026, 10, 29, 12, tzinfo=UTC), magnitude=5.5, pga_g=0.2)
|
|
81
|
+
lower = rain_threshold_reduction(
|
|
82
|
+
[quake], as_of=datetime(2026, 11, 28, 12, tzinfo=UTC), params=params, memory=memory
|
|
83
|
+
)
|
|
84
|
+
# 0.21: the rain threshold of this place is 21 % lower today.
|
|
85
|
+
|
|
86
|
+
# A burn of 100 hectares where the satellite read 150 MW, six months ago.
|
|
87
|
+
fire = PostFireParams(
|
|
88
|
+
peak_months=6,
|
|
89
|
+
curve_denominator=72,
|
|
90
|
+
window_months_max=24,
|
|
91
|
+
severity_floor=0.4,
|
|
92
|
+
frp_floor_mw_per_ha=0.2,
|
|
93
|
+
frp_saturation_mw_per_ha=2.2,
|
|
94
|
+
)
|
|
95
|
+
severity = frp_severity(frp_density(150.0, 100.0), params=fire) # 0.65
|
|
96
|
+
post_fire_factor(6.0, params=fire, severity=severity) # 0.79
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The numbers in the examples are made up to show the calls: they are not a
|
|
100
|
+
calibration.
|
|
101
|
+
|
|
102
|
+
## The rules
|
|
103
|
+
|
|
104
|
+
- **Pure functions.** No database, no network, no clock: the time is always an
|
|
105
|
+
argument. Whatever needs I/O stays in Limen. The one file read is the
|
|
106
|
+
calibration, from the folder the application names.
|
|
107
|
+
- **Calibration is not shipped.** No threshold, weight or time constant has a
|
|
108
|
+
default here unless it switches something off. The values belong to whoever
|
|
109
|
+
measured them, and Limen keeps them in its configuration.
|
|
110
|
+
- **Not measured is not zero.** `None` stays `None`: a burnt perimeter with no
|
|
111
|
+
detection inside is not a weak fire.
|
|
112
|
+
- **One direction.** limen-core may use the libraries; no library imports
|
|
113
|
+
limen-core, and limen-core never imports Limen. A test checks the last one.
|
|
114
|
+
- **Checked against the code it replaces.** Every function that comes from
|
|
115
|
+
Limen has a test that compares it, on hundreds of seeded inputs, with Limen's
|
|
116
|
+
own code frozen in `tests/limen_reference.py`.
|
|
117
|
+
- **Nothing here is an alert.** These are factors and measures. The official
|
|
118
|
+
warning is the criticality bulletin of the Civil Protection Department.
|
|
119
|
+
|
|
120
|
+
## Conventions shared with the libraries
|
|
121
|
+
|
|
122
|
+
- **The instant of a dated landslide.** With a time: that time, read as
|
|
123
|
+
Europe/Rome. With no time: the next local midnight in Europe/Rome after its
|
|
124
|
+
day; an interval gives the end of its last day. `ispra-idrogeo` computes it
|
|
125
|
+
(`dated.instant_utc`).
|
|
126
|
+
- **Records.** Landslides and assessments travel between packages as
|
|
127
|
+
`opendata-record/v2`, the schema `egms-client` publishes.
|
|
128
|
+
|
|
129
|
+
## The scoring engines
|
|
130
|
+
|
|
131
|
+
Limen's engines live here since 0.2.0, as they were in Limen: the same code
|
|
132
|
+
and the same tests, so the same numbers.
|
|
133
|
+
|
|
134
|
+
| Package | What it holds |
|
|
135
|
+
|---|---|
|
|
136
|
+
| `limen_core.models` | what an engine reads and gives back: the features of a cell, the score with its breakdown, the hazards |
|
|
137
|
+
| `limen_core.scoring` | the landslide, flood and wildfire engines, their factors, and the schema of their calibration |
|
|
138
|
+
| `limen_core.cascades` | what one hazard does to another: a fire and the flood after it, three hazards on one municipality |
|
|
139
|
+
|
|
140
|
+
**The calibration stays with the application.** The engines read thresholds,
|
|
141
|
+
weights and class cut-offs from YAML files, and this package ships none: the
|
|
142
|
+
numbers belong to whoever measured them. Name the folder once:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from limen_core import calibration
|
|
146
|
+
from limen_core.scoring import score
|
|
147
|
+
|
|
148
|
+
calibration.use(
|
|
149
|
+
"/path/to/config"
|
|
150
|
+
) # hazards/landslide.yaml, flood.yaml, wildfire.yaml, cascades.yaml
|
|
151
|
+
result = score(bundle) # a CellFeatureBundle in, a RiskScore out
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
or set `LIMEN_CALIBRATION_DIR`. A loader given an explicit path looks nowhere
|
|
155
|
+
else.
|
|
156
|
+
|
|
157
|
+
What did **not** come: the choice of the engine from Limen's settings, and the
|
|
158
|
+
machine-learning engine with its model registry. They are wiring, and they
|
|
159
|
+
stay in Limen.
|
|
160
|
+
|
|
161
|
+
The moved code keeps Limen's names, some of them Italian, and uses pydantic.
|
|
162
|
+
It will be cleaned up a piece at a time; until then the two styles sit side
|
|
163
|
+
by side, and where a moved module and a rewritten one say the same thing
|
|
164
|
+
(`scoring.seismic_decay` and `seismic`, `scoring.wildfire.confronto` and
|
|
165
|
+
`agreement`) a test checks that they give the same numbers.
|
|
166
|
+
|
|
167
|
+
## Where it stands
|
|
168
|
+
|
|
169
|
+
Done: the engines (`models`, `scoring`, `cascades`), the joins `landslide`,
|
|
170
|
+
`wildfire`, `flood`, `seismic`, `post_fire`, `agreement`, and `cases` with
|
|
171
|
+
the measure of ground motion before a landslide.
|
|
172
|
+
|
|
173
|
+
Next:
|
|
174
|
+
|
|
175
|
+
1. Limen calls the joins instead of its own code: the FRP of the burnt
|
|
176
|
+
perimeters (its SQL), the instant and the rain of a landslide, the fluvial
|
|
177
|
+
decision with `hold_back`, the flood truth set with `observed`;
|
|
178
|
+
2. the scoring engines take the joins as inputs where they now read Limen's
|
|
179
|
+
own numbers, and their Italian names are cleaned up a piece at a time.
|
|
180
|
+
|
|
181
|
+
It depends on pydantic, PyYAML, `rainfall-thresholds` 0.5 and `fwi-chain` 1.3.
|
|
182
|
+
The other libraries are not imported: the joins take anything shaped like
|
|
183
|
+
their types (a rain source, a hotspot, a perimeter, a credibility, the water
|
|
184
|
+
over a place), so a library can be released without a release here.
|
|
185
|
+
|
|
186
|
+
## Develop
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
make help # the targets
|
|
190
|
+
make check # ruff, mypy --strict, pytest: the gate CI runs
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Licence
|
|
194
|
+
|
|
195
|
+
Code: Apache-2.0.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# limen-core
|
|
2
|
+
|
|
3
|
+
[Documentation](https://agentengineering.it/limen-core/) · [Changelog](CHANGELOG.md)
|
|
4
|
+
|
|
5
|
+
**limen-core** holds the joins of [Limen](https://github.com/agent-engineering-studio/limen),
|
|
6
|
+
an open early-warning system for landslides, floods and wildfires in Italy.
|
|
7
|
+
|
|
8
|
+
Each open-data library of the project reads one source and stops there:
|
|
9
|
+
`dpc-radar` the rain radar, `ispra-idrogeo` the landslide inventory,
|
|
10
|
+
`firms-client` the fires seen from satellite, and so on. None of them imports
|
|
11
|
+
another. What two sources say *together* is a join, and it lives here: a burn
|
|
12
|
+
seen by satellite inside a mapped perimeter, an earthquake and the rain that
|
|
13
|
+
follows it, an index we compute next to the official one.
|
|
14
|
+
|
|
15
|
+
```mermaid
|
|
16
|
+
flowchart LR
|
|
17
|
+
L1["dpc-radar · rainfall-thresholds<br/>ispra-idrogeo · egms-client"] --> C
|
|
18
|
+
L2["firms-client · effis-client<br/>fwi-chain"] --> C
|
|
19
|
+
L3["glofas-ewds · copernicus-ems<br/>ingv-shakemap"] --> C
|
|
20
|
+
C["limen-core<br/>the joins, pure functions"] --> A["Limen<br/>database · jobs · API · map"]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
It is **alpha**. Two things are in it: the scoring engines of Limen, moved
|
|
24
|
+
as they are with the tests they had, and three joins rewritten as plain
|
|
25
|
+
functions and checked number by number against the code they come from.
|
|
26
|
+
|
|
27
|
+
## What is in it
|
|
28
|
+
|
|
29
|
+
| Module | What it answers | It joins |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| `limen_core.seismic` | how long a slope stays shaken, and how much less rain it takes after an earthquake | the shaking of `ingv-shakemap` with the thresholds of `rainfall-thresholds` |
|
|
32
|
+
| `limen_core.post_fire` | for how long, and how much, a burnt slope is more ready to fail | the fire power of `firms-client` with the perimeters of `effis-client` |
|
|
33
|
+
| `limen_core.landslide` | the rain before an instant at a place, against the threshold of the place, lowered after an earthquake | a `RainSource` (`dpc-radar`), the thresholds of `rainfall-thresholds`, `seismic` |
|
|
34
|
+
| `limen_core.wildfire` | what the satellite saw inside a burnt perimeter around its day: power, and power per hectare | the detections of `firms-client` with the perimeters of `effis-client`; the density feeds `post_fire` |
|
|
35
|
+
| `limen_core.flood` | a forecast river peak with how far to trust it, when the fluvial branch should not speak alone, and whether a place was seen flooded, dry or not seen | the credibility and trust of `glofas-ewds`, the water over a place of `copernicus-ems` |
|
|
36
|
+
| `limen_core.agreement` | how far two measures of the same thing are from each other | the index of `fwi-chain` with the official ones of `effis-client` and `glofas-ewds` |
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from datetime import UTC, datetime
|
|
40
|
+
|
|
41
|
+
from limen_core.post_fire import PostFireParams, frp_density, frp_severity, post_fire_factor
|
|
42
|
+
from limen_core.seismic import SeismicParams, Shaking, ThresholdMemory, rain_threshold_reduction
|
|
43
|
+
|
|
44
|
+
# An earthquake a month ago: the ground is still, the slope is not as it was.
|
|
45
|
+
params = SeismicParams(
|
|
46
|
+
tau_days=2,
|
|
47
|
+
min_magnitude=4,
|
|
48
|
+
lookback_days=7,
|
|
49
|
+
pga_threshold_g=0.1,
|
|
50
|
+
pga_scale_g=0.03,
|
|
51
|
+
pga_min_g=0.02,
|
|
52
|
+
)
|
|
53
|
+
memory = ThresholdMemory(max_reduction=0.3, memory_days=90, lookback_days=365)
|
|
54
|
+
quake = Shaking(datetime(2026, 10, 29, 12, tzinfo=UTC), magnitude=5.5, pga_g=0.2)
|
|
55
|
+
lower = rain_threshold_reduction(
|
|
56
|
+
[quake], as_of=datetime(2026, 11, 28, 12, tzinfo=UTC), params=params, memory=memory
|
|
57
|
+
)
|
|
58
|
+
# 0.21: the rain threshold of this place is 21 % lower today.
|
|
59
|
+
|
|
60
|
+
# A burn of 100 hectares where the satellite read 150 MW, six months ago.
|
|
61
|
+
fire = PostFireParams(
|
|
62
|
+
peak_months=6,
|
|
63
|
+
curve_denominator=72,
|
|
64
|
+
window_months_max=24,
|
|
65
|
+
severity_floor=0.4,
|
|
66
|
+
frp_floor_mw_per_ha=0.2,
|
|
67
|
+
frp_saturation_mw_per_ha=2.2,
|
|
68
|
+
)
|
|
69
|
+
severity = frp_severity(frp_density(150.0, 100.0), params=fire) # 0.65
|
|
70
|
+
post_fire_factor(6.0, params=fire, severity=severity) # 0.79
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The numbers in the examples are made up to show the calls: they are not a
|
|
74
|
+
calibration.
|
|
75
|
+
|
|
76
|
+
## The rules
|
|
77
|
+
|
|
78
|
+
- **Pure functions.** No database, no network, no clock: the time is always an
|
|
79
|
+
argument. Whatever needs I/O stays in Limen. The one file read is the
|
|
80
|
+
calibration, from the folder the application names.
|
|
81
|
+
- **Calibration is not shipped.** No threshold, weight or time constant has a
|
|
82
|
+
default here unless it switches something off. The values belong to whoever
|
|
83
|
+
measured them, and Limen keeps them in its configuration.
|
|
84
|
+
- **Not measured is not zero.** `None` stays `None`: a burnt perimeter with no
|
|
85
|
+
detection inside is not a weak fire.
|
|
86
|
+
- **One direction.** limen-core may use the libraries; no library imports
|
|
87
|
+
limen-core, and limen-core never imports Limen. A test checks the last one.
|
|
88
|
+
- **Checked against the code it replaces.** Every function that comes from
|
|
89
|
+
Limen has a test that compares it, on hundreds of seeded inputs, with Limen's
|
|
90
|
+
own code frozen in `tests/limen_reference.py`.
|
|
91
|
+
- **Nothing here is an alert.** These are factors and measures. The official
|
|
92
|
+
warning is the criticality bulletin of the Civil Protection Department.
|
|
93
|
+
|
|
94
|
+
## Conventions shared with the libraries
|
|
95
|
+
|
|
96
|
+
- **The instant of a dated landslide.** With a time: that time, read as
|
|
97
|
+
Europe/Rome. With no time: the next local midnight in Europe/Rome after its
|
|
98
|
+
day; an interval gives the end of its last day. `ispra-idrogeo` computes it
|
|
99
|
+
(`dated.instant_utc`).
|
|
100
|
+
- **Records.** Landslides and assessments travel between packages as
|
|
101
|
+
`opendata-record/v2`, the schema `egms-client` publishes.
|
|
102
|
+
|
|
103
|
+
## The scoring engines
|
|
104
|
+
|
|
105
|
+
Limen's engines live here since 0.2.0, as they were in Limen: the same code
|
|
106
|
+
and the same tests, so the same numbers.
|
|
107
|
+
|
|
108
|
+
| Package | What it holds |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `limen_core.models` | what an engine reads and gives back: the features of a cell, the score with its breakdown, the hazards |
|
|
111
|
+
| `limen_core.scoring` | the landslide, flood and wildfire engines, their factors, and the schema of their calibration |
|
|
112
|
+
| `limen_core.cascades` | what one hazard does to another: a fire and the flood after it, three hazards on one municipality |
|
|
113
|
+
|
|
114
|
+
**The calibration stays with the application.** The engines read thresholds,
|
|
115
|
+
weights and class cut-offs from YAML files, and this package ships none: the
|
|
116
|
+
numbers belong to whoever measured them. Name the folder once:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from limen_core import calibration
|
|
120
|
+
from limen_core.scoring import score
|
|
121
|
+
|
|
122
|
+
calibration.use(
|
|
123
|
+
"/path/to/config"
|
|
124
|
+
) # hazards/landslide.yaml, flood.yaml, wildfire.yaml, cascades.yaml
|
|
125
|
+
result = score(bundle) # a CellFeatureBundle in, a RiskScore out
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
or set `LIMEN_CALIBRATION_DIR`. A loader given an explicit path looks nowhere
|
|
129
|
+
else.
|
|
130
|
+
|
|
131
|
+
What did **not** come: the choice of the engine from Limen's settings, and the
|
|
132
|
+
machine-learning engine with its model registry. They are wiring, and they
|
|
133
|
+
stay in Limen.
|
|
134
|
+
|
|
135
|
+
The moved code keeps Limen's names, some of them Italian, and uses pydantic.
|
|
136
|
+
It will be cleaned up a piece at a time; until then the two styles sit side
|
|
137
|
+
by side, and where a moved module and a rewritten one say the same thing
|
|
138
|
+
(`scoring.seismic_decay` and `seismic`, `scoring.wildfire.confronto` and
|
|
139
|
+
`agreement`) a test checks that they give the same numbers.
|
|
140
|
+
|
|
141
|
+
## Where it stands
|
|
142
|
+
|
|
143
|
+
Done: the engines (`models`, `scoring`, `cascades`), the joins `landslide`,
|
|
144
|
+
`wildfire`, `flood`, `seismic`, `post_fire`, `agreement`, and `cases` with
|
|
145
|
+
the measure of ground motion before a landslide.
|
|
146
|
+
|
|
147
|
+
Next:
|
|
148
|
+
|
|
149
|
+
1. Limen calls the joins instead of its own code: the FRP of the burnt
|
|
150
|
+
perimeters (its SQL), the instant and the rain of a landslide, the fluvial
|
|
151
|
+
decision with `hold_back`, the flood truth set with `observed`;
|
|
152
|
+
2. the scoring engines take the joins as inputs where they now read Limen's
|
|
153
|
+
own numbers, and their Italian names are cleaned up a piece at a time.
|
|
154
|
+
|
|
155
|
+
It depends on pydantic, PyYAML, `rainfall-thresholds` 0.5 and `fwi-chain` 1.3.
|
|
156
|
+
The other libraries are not imported: the joins take anything shaped like
|
|
157
|
+
their types (a rain source, a hotspot, a perimeter, a credibility, the water
|
|
158
|
+
over a place), so a library can be released without a release here.
|
|
159
|
+
|
|
160
|
+
## Develop
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
make help # the targets
|
|
164
|
+
make check # ruff, mypy --strict, pytest: the gate CI runs
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Licence
|
|
168
|
+
|
|
169
|
+
Code: Apache-2.0.
|