//! Catchment rain series (`src/ml/rain.py`: `catchment_mean`). use chrono::NaiveDateTime; use std::collections::BTreeMap; /// Hourly catchment-average precipitation (mm); NaN = no value. pub type RainSeries = BTreeMap; /// pandas `mean(axis=1)` over the catchment points: the points that have a /// value, summed in column order, divided by their count. pub fn catchment_mean(points: &[Option]) -> Option { let mut sum = 0.0; let mut n = 0usize; for v in points.iter().flatten() { sum += *v; n += 1; } (n > 0).then(|| sum / n as f64) } /// The series on the given hours (`Series.reindex`), NaN where absent. pub fn reindex(rain: &RainSeries, times: &[NaiveDateTime]) -> Vec { times .iter() .map(|t| rain.get(t).copied().unwrap_or(f64::NAN)) .collect() }