S9c — 736-byte rain nowcaster for a microcontroller (Jena, Germany)
Versão em português: README.pt-BR.md
Task: will it rain (≥ 0.2 mm) at the MPI-BGC Jena weather station in the next 60 minutes? Size: 638 network weights (int8) + 9 combiner weights → 736 bytes. Runs on an ESP32 in well under a millisecond. Inputs: the station's own 10-minute sensors, 10-minute rain from 14 nearby DWD stations (10–108 km, mostly upwind), and the current public NWP forecast (Open-Meteo).
⚠️ Site-specific model. It was trained and evaluated only for the Jena roof station. The station features are tied to that location and its neighbors. Do not expect it to work elsewhere without retraining.
Results
AUC-PR (area under the precision-recall curve; random guessing = the rain rate). "Onset" = AP restricted to hours that are dry now (rain starting in the next hour). The hardest case: random guessing ≈ 0.011.
Frozen test set — year 2025 (used once; never seen during development)
8,760 h, 389 rain hours, 82 onsets. Decision threshold chosen on 2023. Mean over 4 neighbor-data delays (20–50 min).
| model | size | AUC-PR | onset AP | F1 | precision | recall | onset recall |
|---|---|---|---|---|---|---|---|
| no-NWP network (D8) | 3.3 KB | 0.682 | 0.203 | 0.622 | 0.595 | 0.650 | 14.6% |
| S9c (this model) | 736 B | 0.741 | 0.405 | 0.672 | 0.640 | 0.707 | 26.8% |
| larger blend (MLP 32 + 300 trees, NWP) | ~117 KB | 0.741 | 0.409 | 0.679 | 0.634 | 0.730 | 32.9% |
S9c vs. the no-NWP network (paired bootstrap in 72-hour blocks, so a storm's consecutive hours stay together; 1,000×): ΔAUC-PR +0.057 [95% CI +0.044, +0.071]; Δonset AP +0.191 [+0.134, +0.253].
Per neighbor-data delay (2025 test; the DWD "now" feed lags 20–50 min in practice):
| delay | no-NWP D8 AUC-PR | D8 onset AP | S9c AUC-PR | S9c onset AP |
|---|---|---|---|---|
| 20 min | 0.693 | 0.229 | 0.749 | 0.437 |
| 30 min | 0.685 | 0.216 | 0.743 | 0.414 |
| 40 min | 0.677 | 0.183 | 0.738 | 0.390 |
| 50 min | 0.673 | 0.183 | 0.734 | 0.378 |
Realistic forecast freshness — Apr–Nov 2026
The 2025 test uses Open-Meteo's historical forecast archive, which stitches the freshest run for each hour, so it is optimistic. To measure the real-time case, every individual ICON-D2 run (1,708 runs, every 3 h) was replayed, using for each hour only the latest run that would already have been published (delay 1–3 h → forecast lead 3–5 h).
S9c, 5,097 h, 264 rain hours, only 57 onsets (so onset numbers are noisy). Mean over 4 neighbor-data delays.
| forecast used | AUC-PR | onset AP |
|---|---|---|
| no NWP (D8) | 0.726 | 0.293 |
| archive (optimistic) | 0.792 | 0.479 |
| real runs, 1 h publication delay | 0.772 | 0.461 |
| real runs, 2 h publication delay | 0.775 | 0.483 |
| real runs, 3 h publication delay | 0.767 | 0.473 |
At 30-min neighbor delay, 72-h block bootstrap: ΔAUC-PR +0.046 [95% CI +0.031, +0.065]; Δonset +0.183 [+0.081, +0.272]. About three quarters of the archive's AUC-PR gain survives in real time. Note: this 2026 period was also used during development (twice), so treat it as a strong sanity check, not a clean test.
Reference points (dev 2023, 8,756 h)
Persistence ("rained in the last 10 min"): AUC-PR 0.380. ICON-D2 forecast alone: 0.593 (onset 0.392). S9c: 0.764 (onset 0.415). 2023 was reused for many confirmations during development, so these S9c numbers are optimistic. Use the 2025 test as the headline.
How it works
- Preprocessing (
preprocessing.json):log1p(10·mm)on rain amounts,sqrt(s/600)on rain durations, z-score with training statistics, clip to ±4. - Network: 90 inputs → 6 ReLU units (+ a linear skip connection) → logit. It was trained as 90→8→1. Two units were then merged by direct weight editing: they were near-linear copies of other units, so their output weight was folded in. The weights were then quantized to int8. Neither step lost accuracy (dev ΔAUC-PR +0.0001).
- Combiner (
s9c_combiner.json): logistic regression on[network logit, NWP rain next hour, NWP max rain ±1 h, NWP cloud cover, dry flag, dry × each NWP term]. Its learned weights say: in dry hours, trust the forecast's cloud and rain signal more.
Input features (order in preprocessing.json):
- 26 from the station: pressure, temperature, dew point, humidity, wind, radiation, rain and its tendencies, time of day and year, and a cloudiness index.
- 64 from DWD neighbors: rain in the last 10 min, 30 min, 1 h and 3 h at 14 stations, plus aggregates (max upwind, number of stations raining).
Neighbor data must be at least 20 min old. The DWD "now" feed lags 20–50 min, and the model was evaluated across that range.
from inference import predict_logit, will_rain
logit = predict_logit(x_raw, p_next_mm=0.4, p_prev_mm=0.0, p_after_mm=1.1, cloud_next_pct=95)
On-device (ESP32)
- Measured on an ESP32-D0WDQ6 at 240 MHz for this model family: the 90→8→1 network runs in 121 µs including preprocessing. Output matches Python to 1e-6.
- S9c on hardware (ESP32-D0WDQ6 @ 240 MHz, Arduino, -O2, 200 test vectors × 1000 reps, 2026-11-05): max |logit − Python| = 1.4e-6, median latency 194 µs (max 329 µs), stack high-water 6.5 KB, no heap allocation during inference; 183/200 correct at threshold 0.5 on these vectors.
- In production the device must also fetch about 60 neighbor values (DWD open data) and one small Open-Meteo JSON per hour. Doing that through a small server is simpler than TLS + unzip on the MCU.
Training and evaluation protocol
- Data: hourly samples, 2010–2022 for training. NWP terms were fit on 2017–2022, since the archive starts in 2017.
- Model selection used rolling-origin cross-validation (validation years 2020, 2021, 2022) × 4 neighbor-data delays.
- Dev 2023 was used only for confirmations. Test 2024 was used once for earlier models. Test 2025 was used once for the final models.
- Full decision log, including everything that did not work, is in
DECISOES.md(Portuguese) in the source project. Examples of what did not work: hand-written onset neurons, iterative magnitude pruning, wind-steered features, and neighbor pressure features.
Limitations
- One station. Hourly decisions. Rain onset in dry hours is still hard (onset AP ≈ 0.4).
- Depends on two external feeds: DWD open data and Open-Meteo. Without the NWP the model degrades to the D8 level (AUC-PR ≈ 0.68–0.73).
- The 2025 test used archived (optimistic) forecasts. The real-time estimate comes from 2026 replays.
- Not a safety system. Do not use it for decisions where a missed rain event causes harm.
License and attribution
- This model (weights, code, card): CC BY 4.0. All training data are CC BY 4.0 as well. Please credit this model and the sources below.
- Weather station data: © Max Planck Institute for Biogeochemistry, Jena — weather station data, https://www.bgc-jena.mpg.de/wetter/ (CC BY 4.0).
- Neighbor stations: Deutscher Wetterdienst (DWD), Climate Data Center (CDC) OpenData, https://opendata.dwd.de (CC BY 4.0; see https://www.dwd.de/copyright).
- NWP forecasts: weather data by Open-Meteo.com (https://open-meteo.com), CC BY 4.0. ICON-D2 output by DWD.
- ⚠️ Runtime use of the Open-Meteo API: the free API may only be used for non-commercial purposes (< 10,000 calls/day). Commercial deployments need an Open-Meteo subscription, or another source for the forecast inputs. This restriction concerns how you fetch the forecasts at run time. It is not a restriction on this model's license.
Files
| file | content |
|---|---|
s9c_network.safetensors | network weights (6 units, values exactly representable in int8 per row) |
preprocessing.json | feature names, transforms, mean/std, clip |
s9c_combiner.json | combiner weights, NWP definitions, dev-tuned threshold |
inference.py | numpy reference implementation (matches the evaluation pipeline to 1e-6) |
Changelog
- v1.1 (2026-11-05): fixed
preprocessing.json. The 60 DWD neighbor-rain inputs are now correctly markedlog1p(10·mm), sox_rawreally takes raw mm everywhere. v1.0 expected those 60 inputs already log-transformed. Passing raw mm to v1.0 gave AUC-PR 0.734 instead of 0.743 on the 2025 test. The time convention for the forecast inputs is now stated entirely in UTC. The model weights are unchanged. Found by an independent review. - v1.2 (2026-11-05):
inference.pynow raisesValueErrorwhen a forecast input or a station value is missing. Before, a missing NWP value silently madewill_rainreturn False. Added a per-delay table for the 2025 test. Both were found by an independent review (Codex). The weights are unchanged.