rainfall-thresholds 0.3.0__tar.gz → 0.4.0__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.
Files changed (21) hide show
  1. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/PKG-INFO +86 -10
  2. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/README.md +85 -9
  3. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/pyproject.toml +4 -1
  4. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/pyproject.toml.orig +6 -1
  5. rainfall_thresholds-0.4.0/src/rainfall_thresholds/__init__.py +72 -0
  6. rainfall_thresholds-0.4.0/src/rainfall_thresholds/antecedent.py +79 -0
  7. rainfall_thresholds-0.4.0/src/rainfall_thresholds/assess.py +176 -0
  8. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/italy.py +63 -3
  9. rainfall_thresholds-0.4.0/src/rainfall_thresholds/regional.py +115 -0
  10. rainfall_thresholds-0.4.0/src/rainfall_thresholds/regional_thresholds.toml +443 -0
  11. rainfall_thresholds-0.4.0/src/rainfall_thresholds/sources.py +41 -0
  12. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/threshold.py +10 -0
  13. rainfall_thresholds-0.3.0/src/rainfall_thresholds/__init__.py +0 -36
  14. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/LICENSE +0 -0
  15. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/check.py +0 -0
  16. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/events.py +0 -0
  17. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/facts.py +0 -0
  18. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/fit.py +0 -0
  19. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/mcp_server.py +0 -0
  20. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/measure.py +0 -0
  21. {rainfall_thresholds-0.3.0 → rainfall_thresholds-0.4.0}/src/rainfall_thresholds/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rainfall-thresholds
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Rainfall intensity-duration thresholds for shallow landslides (Caine power law, frequentist fitting)
5
5
  Keywords: landslide,rainfall threshold,intensity-duration,caine,hydrology,natural hazards,italy,italica
6
6
  Author: Giuseppe Zileni
@@ -45,6 +45,7 @@ mark the hours it could not measure as `None`.
45
45
 
46
46
  [![ci](https://github.com/agent-engineering-studio/rainfall-thresholds/actions/workflows/ci.yml/badge.svg)](https://github.com/agent-engineering-studio/rainfall-thresholds/actions/workflows/ci.yml)
47
47
  [![PyPI](https://img.shields.io/pypi/v/rainfall-thresholds)](https://pypi.org/project/rainfall-thresholds/)
48
+ [![docs](https://img.shields.io/badge/docs-agentengineering.it-blue)](https://agentengineering.it/rainfall-thresholds/)
48
49
  [![Python](https://img.shields.io/pypi/pyversions/rainfall-thresholds)](https://pypi.org/project/rainfall-thresholds/)
49
50
  [![Dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen)](https://github.com/agent-engineering-studio/rainfall-thresholds/blob/main/pyproject.toml)
50
51
  [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/agent-engineering-studio/rainfall-thresholds/blob/main/LICENSE)
@@ -59,6 +60,13 @@ catalogue). The blue line is the threshold this library fits: only 5 % of
59
60
  those storms fall below it. The red star is the storm from the
60
61
  [quick start](#quick-start).</sub>
61
62
 
63
+ **Read the story:** [Basta questa pioggia per far franare?](https://agentengineering.it/blog/soglie-pioggia-frane-rainfall-thresholds/)
64
+ ([English](https://agentengineering.it/en/blog/soglie-pioggia-frane-rainfall-thresholds/)),
65
+ the last episode of the Open Data series, after
66
+ [dpc-radar](https://agentengineering.it/blog/pioggia-radar-protezione-civile-dpc-radar/)
67
+ and [ispra-idrogeo](https://agentengineering.it/blog/frane-pericolo-idrogeologico-ispra-idrogeo/).
68
+ **Try it** in the browser: [the intensity-duration plane](https://agentengineering.it/rainfall-thresholds/explainer/).
69
+
62
70
  ---
63
71
 
64
72
  ## Contents
@@ -77,7 +85,9 @@ those storms fall below it. The red star is the storm from the
77
85
  - [API at a glance](#api-at-a-glance)
78
86
  - [Benchmark](#benchmark)
79
87
  - [Notebooks and Docker](#notebooks-and-docker)
88
+ - [A calibration bench for public bodies](#a-calibration-bench-for-public-bodies)
80
89
  - [For assistants and agents](#for-assistants-and-agents)
90
+ - [Roadmap: what is measured, what is open](#roadmap-what-is-measured-what-is-open)
81
91
  - [Good to know](#good-to-know)
82
92
  - [References](#references) · [Citing](#citing) · [Contributing](#contributing)
83
93
 
@@ -451,7 +461,7 @@ rainfall part of a simple monitoring loop: a number to watch, not an alert.
451
461
 
452
462
  | Name | Kind | What it is |
453
463
  |---|---|---|
454
- | `PowerLawThreshold(alpha, beta)` | frozen dataclass | `I = α·D^(-β)`, with `.intensity(D)`, `.cumulated(D)`, `.exceedance(I, D)` |
464
+ | `PowerLawThreshold(alpha, beta)` | frozen dataclass | `I = α·D^(-β)`, with `.intensity(D)`, `.cumulated(D)`, `.exceedance(I, D)`, `.scaled(factor)` |
455
465
  | `reconstruct_events(series, *, no_rain_break_hours, min_event_mm, source=None)` | function | hourly `(datetime, mm or None)` pairs → `list[RainfallEvent]`; `None` is not measured |
456
466
  | `strongest_event(events, threshold)` | function | the event furthest above the threshold, or `None` |
457
467
  | `latest_event(events)` | function | the event that ended last, or `None` |
@@ -469,7 +479,18 @@ rainfall part of a simple monitoring loop: a number to watch, not an alert.
469
479
  | `mcp_server.create_server()`, `rainfall-thresholds-mcp` | MCP (extra `mcp`) | tools `threshold`, `assess`, `fit`, `check` |
470
480
  | `ITALICA_T5` | read-only mapping | `"italy"`, `"northern"`, `"central"`, `"southern"` → `PowerLawThreshold` |
471
481
  | `MACROREGIONS` | read-only mapping | macroregion → set of region names (e-ITALICA spelling) |
472
- | `macroregion_of(region)` | function | region name → macroregion, or `None` |
482
+ | `macroregion_of(region)` | function | region name or ISTAT region code (`8`, `"08"`) → macroregion, or `None` |
483
+ | `ISTAT_REGIONS` | read-only mapping | ISTAT region code → region name |
484
+ | `threshold_for(macroregion, thresholds=ITALICA_T5, *, default="italy")` | function | the threshold of a macroregion, or the default one |
485
+ | `event_against_threshold(hours, threshold, *, no_rain_break_hours, min_event_mm, choice="latest", source=None, radar_gauge_factor=1.0)` | function | `{datetime: mm or None}` → `EventAssessment` or `None` |
486
+ | `EventAssessment` | frozen dataclass | `event`, `threshold`, `borders_unmeasured`; `.threshold_mm_h`, `.threshold_mm`, `.ratio`, `.excess_decades`, `.at_least` |
487
+ | `cumulate(hours, end, *, windows_hours)` | function | the totals of the last N hours → `{N: WindowTotal}`; no total when an hour is not measured |
488
+ | `caine_excess(event, threshold, *, radar_gauge_factor=1.0)` | function | decades above the line, zero on or below it |
489
+ | `api_kohler_linsley(daily_precip_mm, *, decay_k, initial=0.0)` | function | the Antecedent Precipitation Index, mm |
490
+ | `api_factor(api_mm, *, fallback_baseline_mm, fallback_sigma_mm, sigma_min_mm, baseline_mm=None, sigma_mm=None)` | function | an API as a wetness factor in 0..1; 0.5 when not known |
491
+ | `load_regional_catalogue()` | function | published regional thresholds with their sources → `RegionalCatalogue` of `RegionalThreshold` and `Source` |
492
+ | `RainSource` | `typing.Protocol` | `hourly(points, start, end) -> dict[datetime, list[float or None]]`: what can feed the package |
493
+ | `point_series(rain, index)` | function | the series of one point out of `RainSource.hourly` |
473
494
 
474
495
  Everything is fully typed (`py.typed`) and checked with `mypy --strict`.
475
496
 
@@ -490,10 +511,13 @@ uv run python -m benchmarks.run
490
511
 
491
512
  ## Notebooks and Docker
492
513
 
493
- Three [example notebooks](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/notebooks)
494
- need no network: the Italian thresholds over the e-ITALICA landslides, the
495
- storm of Melito on the DPC radar, and fitting your own threshold. Open them
496
- with uv, or with Docker alone:
514
+ Four [example notebooks](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/notebooks):
515
+ the Italian thresholds over the e-ITALICA landslides, the storm of Melito on
516
+ the DPC radar, and fitting your own threshold, with no network; and the join
517
+ with the sister libraries, landslides dated by
518
+ [ispra-idrogeo](https://agentengineering.it/ispra-idrogeo/) against radar rain
519
+ from [dpc-radar](https://agentengineering.it/dpc-radar/). Open them with uv, or
520
+ with Docker alone:
497
521
 
498
522
  ```bash
499
523
  uv run --group examples jupyter lab notebooks/
@@ -504,6 +528,21 @@ make docker-bench # the benchmark, in a container
504
528
  The compose file gives no fixed name to containers or images: Compose names
505
529
  them after the project, so two copies run side by side.
506
530
 
531
+ ## A calibration bench for public bodies
532
+
533
+ [`app/`](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/app)
534
+ is a page in Italian, with Bootstrap Italia, for a public body: it opens on
535
+ the e-ITALICA landslides of its region, fits a threshold on the ones that
536
+ matter, compares it with the national one, measures its cost in false alarms
537
+ on the body's own rain gauge, and exports it. It is not a warning system and
538
+ reads no live rain. `docker compose up taratura`, then http://localhost:3001.
539
+ [Riuso nella PA](https://agentengineering.it/rainfall-thresholds/riuso/)
540
+ says, in Italian, what it does and what stays with the body.
541
+
542
+ To explain what a threshold is, the docs site has
543
+ [Try it](https://agentengineering.it/rainfall-thresholds/explainer/): an
544
+ interactive intensity-duration plane that runs in the browser.
545
+
507
546
  ## For assistants and agents
508
547
 
509
548
  A language model may word the numbers; it should never compute them. The
@@ -533,6 +572,31 @@ library gives them as data, and checks the words.
533
572
  The base package still has no dependencies: the MCP SDK comes only with the
534
573
  `mcp` extra.
535
574
 
575
+ ## Roadmap: what is measured, what is open
576
+
577
+ The plan is in [#4](https://github.com/agent-engineering-studio/rainfall-thresholds/issues/4),
578
+ and the [roadmap page](https://agentengineering.it/rainfall-thresholds/roadmap/)
579
+ says what each phase measured.
580
+
581
+ - **Done:** the benchmark (#5), the strongest event and hours not measured
582
+ (#6), the functions to measure a threshold (#7), the AI layer (#9), the
583
+ calibration bench, Try it and `publiccode.yml` (#10), notebooks and Docker
584
+ (#14), the rule that the package depends on no sister library (#21).
585
+ - **A pilot on 2026** ([`benchmarks/measures/`](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/benchmarks/measures)):
586
+ on 9 dated landslides and Limen's archive of DPC frames, the «Merging»
587
+ caught 7 of 9 with 9.4 alerts per landslide caught; the radar alone 8 of 9
588
+ with 12.25. Nine landslides: a first look, not a validation.
589
+ - **The measure from 2018 to 2025** ([`benchmarks/measures/`](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/benchmarks/measures)):
590
+ on the radar history and 4,200 dated landslides, the rain is above T5 at
591
+ the gauge for 95.6 % of the same landslides and on the radar for 66.0 %.
592
+ The threshold still separates on radar rain (AUC 0.85 and 0.73), and a
593
+ threshold fitted on radar rain does not hold: none goes in.
594
+ - **Open, and measured in Limen, not here:** the numbers of
595
+ [limen#243](https://github.com/agent-engineering-studio/limen/issues/243)
596
+ recomputed with `measure` (#7); `strongest_event` against the
597
+ last event on the twelve backtest windows of Limen, before it is switched
598
+ on there.
599
+
536
600
  ## Good to know
537
601
 
538
602
  - **A threshold is not a forecast.** Rain above T5 means "conditions like
@@ -548,12 +612,24 @@ The base package still has no dependencies: the MCP SDK comes only with the
548
612
  thresholds to events from `reconstruct_events` mixes the two: fine for
549
613
  monitoring, worth knowing for a study.
550
614
  - **Units are fixed:** hours, millimetres, millimetres per hour.
615
+ - **No sister library inside.** The package imports neither dpc-radar nor
616
+ ispra-idrogeo, and a test keeps it so: [Limen](https://github.com/agent-engineering-studio/limen)
617
+ pins all three, and a library that imported another would tie their
618
+ releases together. The join lives in Limen, in notebook 04 and in `app/`.
551
619
 
552
620
  ## Where it's used
553
621
 
554
- Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
555
- which uses it for the rainfall component of its landslide score. Using it
556
- somewhere else? [Open an issue](https://github.com/agent-engineering-studio/rainfall-thresholds/issues)
622
+ - **[Limen](https://github.com/agent-engineering-studio/limen)**, an open
623
+ early-warning system for landslides, floods and wildfires in Italy, from
624
+ which the library was extracted. It pins `rainfall-thresholds~=0.3.0` for
625
+ the rainfall trigger of its landslide score; the choice of the strongest
626
+ event is in its `landslide.yaml`, off until its backtest measures it.
627
+ - **The Open Data series** of Agent Engineering Studio, with its sister
628
+ libraries [dpc-radar](https://agentengineering.it/dpc-radar/) and
629
+ [ispra-idrogeo](https://agentengineering.it/ispra-idrogeo/).
630
+ - **The calibration bench** in `app/`, for public bodies.
631
+
632
+ Using it somewhere else? [Open an issue](https://github.com/agent-engineering-studio/rainfall-thresholds/issues)
557
633
  and tell us: we'd love to list it here.
558
634
 
559
635
  ## References
@@ -19,6 +19,7 @@ mark the hours it could not measure as `None`.
19
19
 
20
20
  [![ci](https://github.com/agent-engineering-studio/rainfall-thresholds/actions/workflows/ci.yml/badge.svg)](https://github.com/agent-engineering-studio/rainfall-thresholds/actions/workflows/ci.yml)
21
21
  [![PyPI](https://img.shields.io/pypi/v/rainfall-thresholds)](https://pypi.org/project/rainfall-thresholds/)
22
+ [![docs](https://img.shields.io/badge/docs-agentengineering.it-blue)](https://agentengineering.it/rainfall-thresholds/)
22
23
  [![Python](https://img.shields.io/pypi/pyversions/rainfall-thresholds)](https://pypi.org/project/rainfall-thresholds/)
23
24
  [![Dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen)](https://github.com/agent-engineering-studio/rainfall-thresholds/blob/main/pyproject.toml)
24
25
  [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/agent-engineering-studio/rainfall-thresholds/blob/main/LICENSE)
@@ -33,6 +34,13 @@ catalogue). The blue line is the threshold this library fits: only 5 % of
33
34
  those storms fall below it. The red star is the storm from the
34
35
  [quick start](#quick-start).</sub>
35
36
 
37
+ **Read the story:** [Basta questa pioggia per far franare?](https://agentengineering.it/blog/soglie-pioggia-frane-rainfall-thresholds/)
38
+ ([English](https://agentengineering.it/en/blog/soglie-pioggia-frane-rainfall-thresholds/)),
39
+ the last episode of the Open Data series, after
40
+ [dpc-radar](https://agentengineering.it/blog/pioggia-radar-protezione-civile-dpc-radar/)
41
+ and [ispra-idrogeo](https://agentengineering.it/blog/frane-pericolo-idrogeologico-ispra-idrogeo/).
42
+ **Try it** in the browser: [the intensity-duration plane](https://agentengineering.it/rainfall-thresholds/explainer/).
43
+
36
44
  ---
37
45
 
38
46
  ## Contents
@@ -51,7 +59,9 @@ those storms fall below it. The red star is the storm from the
51
59
  - [API at a glance](#api-at-a-glance)
52
60
  - [Benchmark](#benchmark)
53
61
  - [Notebooks and Docker](#notebooks-and-docker)
62
+ - [A calibration bench for public bodies](#a-calibration-bench-for-public-bodies)
54
63
  - [For assistants and agents](#for-assistants-and-agents)
64
+ - [Roadmap: what is measured, what is open](#roadmap-what-is-measured-what-is-open)
55
65
  - [Good to know](#good-to-know)
56
66
  - [References](#references) · [Citing](#citing) · [Contributing](#contributing)
57
67
 
@@ -425,7 +435,7 @@ rainfall part of a simple monitoring loop: a number to watch, not an alert.
425
435
 
426
436
  | Name | Kind | What it is |
427
437
  |---|---|---|
428
- | `PowerLawThreshold(alpha, beta)` | frozen dataclass | `I = α·D^(-β)`, with `.intensity(D)`, `.cumulated(D)`, `.exceedance(I, D)` |
438
+ | `PowerLawThreshold(alpha, beta)` | frozen dataclass | `I = α·D^(-β)`, with `.intensity(D)`, `.cumulated(D)`, `.exceedance(I, D)`, `.scaled(factor)` |
429
439
  | `reconstruct_events(series, *, no_rain_break_hours, min_event_mm, source=None)` | function | hourly `(datetime, mm or None)` pairs → `list[RainfallEvent]`; `None` is not measured |
430
440
  | `strongest_event(events, threshold)` | function | the event furthest above the threshold, or `None` |
431
441
  | `latest_event(events)` | function | the event that ended last, or `None` |
@@ -443,7 +453,18 @@ rainfall part of a simple monitoring loop: a number to watch, not an alert.
443
453
  | `mcp_server.create_server()`, `rainfall-thresholds-mcp` | MCP (extra `mcp`) | tools `threshold`, `assess`, `fit`, `check` |
444
454
  | `ITALICA_T5` | read-only mapping | `"italy"`, `"northern"`, `"central"`, `"southern"` → `PowerLawThreshold` |
445
455
  | `MACROREGIONS` | read-only mapping | macroregion → set of region names (e-ITALICA spelling) |
446
- | `macroregion_of(region)` | function | region name → macroregion, or `None` |
456
+ | `macroregion_of(region)` | function | region name or ISTAT region code (`8`, `"08"`) → macroregion, or `None` |
457
+ | `ISTAT_REGIONS` | read-only mapping | ISTAT region code → region name |
458
+ | `threshold_for(macroregion, thresholds=ITALICA_T5, *, default="italy")` | function | the threshold of a macroregion, or the default one |
459
+ | `event_against_threshold(hours, threshold, *, no_rain_break_hours, min_event_mm, choice="latest", source=None, radar_gauge_factor=1.0)` | function | `{datetime: mm or None}` → `EventAssessment` or `None` |
460
+ | `EventAssessment` | frozen dataclass | `event`, `threshold`, `borders_unmeasured`; `.threshold_mm_h`, `.threshold_mm`, `.ratio`, `.excess_decades`, `.at_least` |
461
+ | `cumulate(hours, end, *, windows_hours)` | function | the totals of the last N hours → `{N: WindowTotal}`; no total when an hour is not measured |
462
+ | `caine_excess(event, threshold, *, radar_gauge_factor=1.0)` | function | decades above the line, zero on or below it |
463
+ | `api_kohler_linsley(daily_precip_mm, *, decay_k, initial=0.0)` | function | the Antecedent Precipitation Index, mm |
464
+ | `api_factor(api_mm, *, fallback_baseline_mm, fallback_sigma_mm, sigma_min_mm, baseline_mm=None, sigma_mm=None)` | function | an API as a wetness factor in 0..1; 0.5 when not known |
465
+ | `load_regional_catalogue()` | function | published regional thresholds with their sources → `RegionalCatalogue` of `RegionalThreshold` and `Source` |
466
+ | `RainSource` | `typing.Protocol` | `hourly(points, start, end) -> dict[datetime, list[float or None]]`: what can feed the package |
467
+ | `point_series(rain, index)` | function | the series of one point out of `RainSource.hourly` |
447
468
 
448
469
  Everything is fully typed (`py.typed`) and checked with `mypy --strict`.
449
470
 
@@ -464,10 +485,13 @@ uv run python -m benchmarks.run
464
485
 
465
486
  ## Notebooks and Docker
466
487
 
467
- Three [example notebooks](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/notebooks)
468
- need no network: the Italian thresholds over the e-ITALICA landslides, the
469
- storm of Melito on the DPC radar, and fitting your own threshold. Open them
470
- with uv, or with Docker alone:
488
+ Four [example notebooks](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/notebooks):
489
+ the Italian thresholds over the e-ITALICA landslides, the storm of Melito on
490
+ the DPC radar, and fitting your own threshold, with no network; and the join
491
+ with the sister libraries, landslides dated by
492
+ [ispra-idrogeo](https://agentengineering.it/ispra-idrogeo/) against radar rain
493
+ from [dpc-radar](https://agentengineering.it/dpc-radar/). Open them with uv, or
494
+ with Docker alone:
471
495
 
472
496
  ```bash
473
497
  uv run --group examples jupyter lab notebooks/
@@ -478,6 +502,21 @@ make docker-bench # the benchmark, in a container
478
502
  The compose file gives no fixed name to containers or images: Compose names
479
503
  them after the project, so two copies run side by side.
480
504
 
505
+ ## A calibration bench for public bodies
506
+
507
+ [`app/`](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/app)
508
+ is a page in Italian, with Bootstrap Italia, for a public body: it opens on
509
+ the e-ITALICA landslides of its region, fits a threshold on the ones that
510
+ matter, compares it with the national one, measures its cost in false alarms
511
+ on the body's own rain gauge, and exports it. It is not a warning system and
512
+ reads no live rain. `docker compose up taratura`, then http://localhost:3001.
513
+ [Riuso nella PA](https://agentengineering.it/rainfall-thresholds/riuso/)
514
+ says, in Italian, what it does and what stays with the body.
515
+
516
+ To explain what a threshold is, the docs site has
517
+ [Try it](https://agentengineering.it/rainfall-thresholds/explainer/): an
518
+ interactive intensity-duration plane that runs in the browser.
519
+
481
520
  ## For assistants and agents
482
521
 
483
522
  A language model may word the numbers; it should never compute them. The
@@ -507,6 +546,31 @@ library gives them as data, and checks the words.
507
546
  The base package still has no dependencies: the MCP SDK comes only with the
508
547
  `mcp` extra.
509
548
 
549
+ ## Roadmap: what is measured, what is open
550
+
551
+ The plan is in [#4](https://github.com/agent-engineering-studio/rainfall-thresholds/issues/4),
552
+ and the [roadmap page](https://agentengineering.it/rainfall-thresholds/roadmap/)
553
+ says what each phase measured.
554
+
555
+ - **Done:** the benchmark (#5), the strongest event and hours not measured
556
+ (#6), the functions to measure a threshold (#7), the AI layer (#9), the
557
+ calibration bench, Try it and `publiccode.yml` (#10), notebooks and Docker
558
+ (#14), the rule that the package depends on no sister library (#21).
559
+ - **A pilot on 2026** ([`benchmarks/measures/`](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/benchmarks/measures)):
560
+ on 9 dated landslides and Limen's archive of DPC frames, the «Merging»
561
+ caught 7 of 9 with 9.4 alerts per landslide caught; the radar alone 8 of 9
562
+ with 12.25. Nine landslides: a first look, not a validation.
563
+ - **The measure from 2018 to 2025** ([`benchmarks/measures/`](https://github.com/agent-engineering-studio/rainfall-thresholds/tree/main/benchmarks/measures)):
564
+ on the radar history and 4,200 dated landslides, the rain is above T5 at
565
+ the gauge for 95.6 % of the same landslides and on the radar for 66.0 %.
566
+ The threshold still separates on radar rain (AUC 0.85 and 0.73), and a
567
+ threshold fitted on radar rain does not hold: none goes in.
568
+ - **Open, and measured in Limen, not here:** the numbers of
569
+ [limen#243](https://github.com/agent-engineering-studio/limen/issues/243)
570
+ recomputed with `measure` (#7); `strongest_event` against the
571
+ last event on the twelve backtest windows of Limen, before it is switched
572
+ on there.
573
+
510
574
  ## Good to know
511
575
 
512
576
  - **A threshold is not a forecast.** Rain above T5 means "conditions like
@@ -522,12 +586,24 @@ The base package still has no dependencies: the MCP SDK comes only with the
522
586
  thresholds to events from `reconstruct_events` mixes the two: fine for
523
587
  monitoring, worth knowing for a study.
524
588
  - **Units are fixed:** hours, millimetres, millimetres per hour.
589
+ - **No sister library inside.** The package imports neither dpc-radar nor
590
+ ispra-idrogeo, and a test keeps it so: [Limen](https://github.com/agent-engineering-studio/limen)
591
+ pins all three, and a library that imported another would tie their
592
+ releases together. The join lives in Limen, in notebook 04 and in `app/`.
525
593
 
526
594
  ## Where it's used
527
595
 
528
- Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
529
- which uses it for the rainfall component of its landslide score. Using it
530
- somewhere else? [Open an issue](https://github.com/agent-engineering-studio/rainfall-thresholds/issues)
596
+ - **[Limen](https://github.com/agent-engineering-studio/limen)**, an open
597
+ early-warning system for landslides, floods and wildfires in Italy, from
598
+ which the library was extracted. It pins `rainfall-thresholds~=0.3.0` for
599
+ the rainfall trigger of its landslide score; the choice of the strongest
600
+ event is in its `landslide.yaml`, off until its backtest measures it.
601
+ - **The Open Data series** of Agent Engineering Studio, with its sister
602
+ libraries [dpc-radar](https://agentengineering.it/dpc-radar/) and
603
+ [ispra-idrogeo](https://agentengineering.it/ispra-idrogeo/).
604
+ - **The calibration bench** in `app/`, for public bodies.
605
+
606
+ Using it somewhere else? [Open an issue](https://github.com/agent-engineering-studio/rainfall-thresholds/issues)
531
607
  and tell us: we'd love to list it here.
532
608
 
533
609
  ## References
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rainfall-thresholds"
3
- version = "0.3.0"
3
+ version = "0.4.0"
4
4
  description = "Rainfall intensity-duration thresholds for shallow landslides (Caine power law, frequentist fitting)"
5
5
  readme = "README.md"
6
6
  keywords = [
@@ -61,6 +61,8 @@ examples = [
61
61
  "jupyterlab>=4.2",
62
62
  "nbconvert>=7.16",
63
63
  "matplotlib>=3.9",
64
+ "dpc-radar~=0.3.0",
65
+ "ispra-idrogeo~=0.10.0",
64
66
  ]
65
67
  docs = [
66
68
  "zensical>=0.1.0",
@@ -92,6 +94,7 @@ select = [
92
94
  "ARG",
93
95
  "B018",
94
96
  ]
97
+ "docs/make_blog_figures.py" = ["E501"]
95
98
 
96
99
  [tool.mypy]
97
100
  strict = true
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rainfall-thresholds"
3
- version = "0.3.0"
3
+ version = "0.4.0"
4
4
  description = "Rainfall intensity-duration thresholds for shallow landslides (Caine power law, frequentist fitting)"
5
5
  readme = "README.md"
6
6
  keywords = ["landslide", "rainfall threshold", "intensity-duration", "caine", "hydrology", "natural hazards", "italy", "italica"]
@@ -53,6 +53,10 @@ examples = [
53
53
  "jupyterlab>=4.2",
54
54
  "nbconvert>=7.16",
55
55
  "matplotlib>=3.9",
56
+ # Only for notebooks/04: the sister libraries, joined in a notebook as Limen
57
+ # joins them. The package itself never imports them (tests/test_package.py).
58
+ "dpc-radar~=0.3.0",
59
+ "ispra-idrogeo~=0.10.0",
56
60
  ]
57
61
 
58
62
  docs = [
@@ -69,6 +73,7 @@ select = ["E", "F", "W", "I", "N", "UP", "B", "C4", "SIM", "ARG", "PTH", "RUF"]
69
73
 
70
74
  [tool.ruff.lint.per-file-ignores]
71
75
  "tests/**" = ["ARG", "B018"]
76
+ "docs/make_blog_figures.py" = ["E501"] # labels in two languages
72
77
 
73
78
  [tool.mypy]
74
79
  strict = true
@@ -0,0 +1,72 @@
1
+ """Rainfall intensity-duration thresholds for shallow landslides."""
2
+
3
+ from importlib.metadata import version
4
+
5
+ from rainfall_thresholds.antecedent import api_factor, api_kohler_linsley
6
+ from rainfall_thresholds.assess import (
7
+ EventAssessment,
8
+ WindowTotal,
9
+ caine_excess,
10
+ cumulate,
11
+ event_against_threshold,
12
+ )
13
+ from rainfall_thresholds.events import (
14
+ RainfallEvent,
15
+ latest_event,
16
+ reconstruct_events,
17
+ strongest_event,
18
+ )
19
+ from rainfall_thresholds.fit import ThresholdFit, fit_threshold, percentile_of
20
+ from rainfall_thresholds.italy import (
21
+ ISTAT_REGIONS,
22
+ ITALICA_T5,
23
+ MACROREGIONS,
24
+ macroregion_of,
25
+ threshold_for,
26
+ )
27
+ from rainfall_thresholds.measure import Skill, auc, cutoff_at_budget, skill, skill_at_budget
28
+ from rainfall_thresholds.regional import (
29
+ RegionalCatalogue,
30
+ RegionalThreshold,
31
+ Source,
32
+ load_regional_catalogue,
33
+ )
34
+ from rainfall_thresholds.sources import RainSource, point_series
35
+ from rainfall_thresholds.threshold import PowerLawThreshold
36
+
37
+ __version__ = version("rainfall-thresholds")
38
+
39
+ __all__ = [
40
+ "ISTAT_REGIONS",
41
+ "ITALICA_T5",
42
+ "MACROREGIONS",
43
+ "EventAssessment",
44
+ "PowerLawThreshold",
45
+ "RainSource",
46
+ "RainfallEvent",
47
+ "RegionalCatalogue",
48
+ "RegionalThreshold",
49
+ "Skill",
50
+ "Source",
51
+ "ThresholdFit",
52
+ "WindowTotal",
53
+ "__version__",
54
+ "api_factor",
55
+ "api_kohler_linsley",
56
+ "auc",
57
+ "caine_excess",
58
+ "cumulate",
59
+ "cutoff_at_budget",
60
+ "event_against_threshold",
61
+ "fit_threshold",
62
+ "latest_event",
63
+ "load_regional_catalogue",
64
+ "macroregion_of",
65
+ "percentile_of",
66
+ "point_series",
67
+ "reconstruct_events",
68
+ "skill",
69
+ "skill_at_budget",
70
+ "strongest_event",
71
+ "threshold_for",
72
+ ]
@@ -0,0 +1,79 @@
1
+ """The Antecedent Precipitation Index (Kohler & Linsley 1951) and a wetness factor.
2
+
3
+ API_t = k * API_(t-1) + P_t P in mm per day, 0 < k < 1
4
+
5
+ How wet the ground already is when the rain comes: every day keeps a share
6
+ ``k`` of the day before and adds its own rain. :func:`api_factor` reads an
7
+ API against a baseline as a number between 0 and 1.
8
+
9
+ There are no defaults for ``k``, the baseline or the sigma: they depend on
10
+ the place and on what the factor is used for, and are the caller's
11
+ configuration. Moved from Limen (``core/scoring/api.py``); a parity test
12
+ keeps the numbers the same.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import math
18
+ from collections.abc import Iterable
19
+
20
+
21
+ def api_kohler_linsley(
22
+ daily_precip_mm: Iterable[float],
23
+ *,
24
+ decay_k: float,
25
+ initial: float = 0.0,
26
+ ) -> float:
27
+ """The API at the end of a series of daily totals, in mm.
28
+
29
+ Args:
30
+ daily_precip_mm: Daily totals in chronological order.
31
+ decay_k: Daily decay coefficient, ``0 < k < 1``.
32
+ initial: API at the start of the series.
33
+ """
34
+ if not 0.0 < decay_k < 1.0:
35
+ raise ValueError(f"decay_k must be in (0, 1), got {decay_k}")
36
+ api = float(initial)
37
+ for p in daily_precip_mm:
38
+ if p < 0.0:
39
+ raise ValueError(f"daily_precip_mm must be >= 0, got {p}")
40
+ api = decay_k * api + float(p)
41
+ return api
42
+
43
+
44
+ def api_factor(
45
+ api_mm: float | None,
46
+ *,
47
+ fallback_baseline_mm: float,
48
+ fallback_sigma_mm: float,
49
+ sigma_min_mm: float,
50
+ baseline_mm: float | None = None,
51
+ sigma_mm: float | None = None,
52
+ ) -> float:
53
+ """An API as a wetness factor between 0 and 1.
54
+
55
+ The logistic of the standardised anomaly, ``(API - baseline) / sigma``:
56
+ 0.5 at the baseline, towards 1 when wetter. ``baseline_mm`` and
57
+ ``sigma_mm`` are the place's own climatology for the month; a place
58
+ without one is read against ``fallback_baseline_mm`` and
59
+ ``fallback_sigma_mm``. A place's own sigma is never taken below
60
+ ``sigma_min_mm``: where the rain of a month varies by a few millimetres,
61
+ an ordinary storm would read as an anomaly of ten sigma.
62
+
63
+ ``None`` (no API known) gives 0.5, neutral: not knowing moves the factor
64
+ neither up nor down.
65
+ """
66
+ if api_mm is None:
67
+ return 0.5
68
+ baseline = baseline_mm if baseline_mm is not None else fallback_baseline_mm
69
+ sigma = max(sigma_mm, sigma_min_mm) if sigma_mm is not None else fallback_sigma_mm
70
+ if sigma <= 0:
71
+ raise ValueError(f"sigma must be > 0, got {sigma}")
72
+ return _sigmoid((api_mm - baseline) / sigma)
73
+
74
+
75
+ def _sigmoid(z: float) -> float:
76
+ if z >= 0:
77
+ return 1.0 / (1.0 + math.exp(-z))
78
+ ez = math.exp(z)
79
+ return ez / (1.0 + ez)