1pub mod forcing;
9pub mod metrics;
10
11pub use forcing::{Forcing, BasinInfo, Outlet};
12pub use metrics::{
13 MetricsReport, nse, kge, rmse, pbias, r2, dc_grade, compute_metrics,
14 GbtEventErrors, QualificationTolerance, QualificationReport,
15 event_errors, event_qualified, qualified_rate, qualification_grade, scheme_grade,
16 compute_metrics_gbt,
17 ProbabilisticReport, crps, brier, pod_far_csi, ensemble_exceedance, compute_probabilistic,
18 rank_histogram,
19};
20
21use serde::{Serialize, Deserialize};
22
23#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
25pub enum ModelType {
26 Xinanjiang,
27 Topmodel,
28 Swat,
29 Apicont,
30}
31
32impl ModelType {
33 pub fn name(&self) -> &'static str {
34 match self {
35 ModelType::Xinanjiang => "新安江",
36 ModelType::Topmodel => "TOPMODEL",
37 ModelType::Swat => "SWAT",
38 ModelType::Apicont => "API-CONT",
39 }
40 }
41}
42
43pub trait HydroModel: Send {
49 type Params: Serialize + for<'de> Deserialize<'de> + Clone + Send;
51
52 fn new(params: Self::Params) -> Self;
54
55 fn step(&mut self, forcing: &Forcing, dt_h: f64);
57
58 fn discharge(&self) -> f64;
60
61 fn state(&self) -> serde_json::Value;
63
64 fn reset(&mut self);
66
67 fn name(&self) -> &'static str;
69
70 fn params(&self) -> &Self::Params;
72
73 fn params_mut(&mut self) -> &mut Self::Params;
75}
76
77pub trait DynHydroModel: Send {
80 fn step(&mut self, forcing: &Forcing, dt_h: f64);
81 fn discharge(&self) -> f64;
82 fn name(&self) -> &'static str;
83 fn params_json(&self) -> serde_json::Value;
84 fn set_params_json(&mut self, v: &serde_json::Value);
85 fn reset(&mut self);
86}
87
88impl<M: HydroModel> DynHydroModel for M {
90 fn step(&mut self, forcing: &Forcing, dt_h: f64) {
91 HydroModel::step(self, forcing, dt_h);
92 }
93 fn discharge(&self) -> f64 {
94 HydroModel::discharge(self)
95 }
96 fn name(&self) -> &'static str {
97 HydroModel::name(self)
98 }
99 fn params_json(&self) -> serde_json::Value {
100 serde_json::to_value(self.params()).unwrap_or(serde_json::Value::Null)
101 }
102 fn set_params_json(&mut self, v: &serde_json::Value) {
103 if let Ok(p) = serde_json::from_value::<M::Params>(v.clone()) {
104 *self.params_mut() = p;
105 }
106 }
107 fn reset(&mut self) {
108 HydroModel::reset(self);
109 }
110}