1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
use std::borrow::Cow;
use crate::query::AsApiStr;
/// Aggregation applied to a variable, primarily for daily values.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
#[non_exhaustive]
pub enum Aggregation {
/// Minimum over the aggregation period.
Minimum,
/// Maximum over the aggregation period.
Maximum,
/// Mean over the aggregation period.
Mean,
/// Median over the aggregation period.
Median,
/// Sum over the aggregation period.
Sum,
/// 10th percentile over the aggregation period.
P10,
/// 25th percentile over the aggregation period.
P25,
/// 75th percentile over the aggregation period.
P75,
/// 90th percentile over the aggregation period.
P90,
/// Dominant direction or category.
Dominant,
}
impl Aggregation {
/// Returns the Open-Meteo suffix for this aggregation.
pub fn suffix(self) -> &'static str {
match self {
Self::Minimum => "_min",
Self::Maximum => "_max",
Self::Mean => "_mean",
Self::Median => "_median",
Self::Sum => "_sum",
Self::P10 => "_p10",
Self::P25 => "_p25",
Self::P75 => "_p75",
Self::P90 => "_p90",
Self::Dominant => "_dominant",
}
}
}
/// Pressure levels exposed by the general forecast endpoint.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i16)]
#[non_exhaustive]
pub enum PressureLevel {
/// 1000 hPa.
Hpa1000 = 1000,
/// 975 hPa.
Hpa975 = 975,
/// 950 hPa.
Hpa950 = 950,
/// 925 hPa.
Hpa925 = 925,
/// 900 hPa.
Hpa900 = 900,
/// 850 hPa.
Hpa850 = 850,
/// 800 hPa.
Hpa800 = 800,
/// 700 hPa.
Hpa700 = 700,
/// 600 hPa.
Hpa600 = 600,
/// 500 hPa.
Hpa500 = 500,
/// 400 hPa.
Hpa400 = 400,
/// 300 hPa.
Hpa300 = 300,
/// 250 hPa.
Hpa250 = 250,
/// 200 hPa.
Hpa200 = 200,
/// 150 hPa.
Hpa150 = 150,
/// 100 hPa.
Hpa100 = 100,
/// 70 hPa.
Hpa70 = 70,
/// 50 hPa.
Hpa50 = 50,
/// 30 hPa.
Hpa30 = 30,
}
impl PressureLevel {
pub(crate) fn hpa(self) -> i16 {
self as i16
}
}
/// Tower and near-surface measurement levels exposed by forecast variables.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i16)]
#[non_exhaustive]
pub enum TowerLevel {
/// 10 m above ground.
M10 = 10,
/// 80 m above ground.
M80 = 80,
/// 120 m above ground.
M120 = 120,
/// 180 m above ground.
M180 = 180,
}
impl TowerLevel {
pub(crate) fn meters(self) -> i16 {
self as i16
}
}
/// Weather model selector for forecast requests.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum WeatherModel {
/// Open-Meteo's automatic best-match model.
BestMatch,
/// NOAA GFS seamless model.
GfsSeamless,
/// ECMWF IFS 0.25 degree model.
EcmwfIfs025,
/// DWD ICON seamless model.
IconSeamless,
/// MeteoFrance seamless model.
MeteofranceSeamless,
/// Exact Open-Meteo model token not yet represented by this enum.
///
/// This is an escape hatch for documented model names that have not been
/// promoted to first-class variants yet. The token is not validated by the
/// crate.
Other(Cow<'static, str>),
}
/// Reanalysis model selector for archive requests.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ArchiveModel {
/// Open-Meteo's automatic best-match reanalysis model.
BestMatch,
/// Open-Meteo's seamless ERA5 model selection.
Era5Seamless,
/// ECMWF ERA5 reanalysis.
Era5,
/// ECMWF ERA5-Land reanalysis.
Era5Land,
/// ECMWF ERA5 ensemble reanalysis.
Era5Ensemble,
/// Open-Meteo's assembled ECMWF IFS archive.
EcmwfIfs,
/// ECMWF IFS assimilation long-window archive.
EcmwfIfsAnalysisLongWindow,
/// Copernicus European Regional Reanalysis.
Cerra,
/// Exact Open-Meteo archive model token not yet represented by this enum.
///
/// This is an escape hatch for documented model names that have not been
/// promoted to first-class variants yet. The token is not validated by the
/// crate.
Other(Cow<'static, str>),
}
/// Model selector for ensemble forecast requests.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum EnsembleModel {
/// DWD ICON EPS seamless ensemble model.
IconSeamlessEps,
/// DWD ICON EPS global model.
IconGlobalEps,
/// DWD ICON EPS Europe model.
IconEuEps,
/// DWD ICON EPS D2 model.
IconD2Eps,
/// NOAA/NCEP GEFS seamless ensemble model.
NcepGefsSeamless,
/// NOAA/NCEP GEFS 0.25 degree ensemble model.
NcepGefs025,
/// NOAA/NCEP GEFS 0.5 degree ensemble model.
NcepGefs05,
/// NOAA/NCEP AIGEPS 0.25 degree ensemble model.
NcepAigefs025,
/// ECMWF IFS 0.25 degree ensemble model.
EcmwfIfs025Ensemble,
/// ECMWF AIFS 0.25 degree ensemble model.
EcmwfAifs025Ensemble,
/// Canadian GEM global ensemble model.
GemGlobalEnsemble,
/// Australian BOM ACCESS global ensemble model.
BomAccessGlobalEnsemble,
/// UK Met Office global 20 km ensemble model.
UkmoGlobalEnsemble20km,
/// UK Met Office UK 2 km ensemble model.
UkmoUkEnsemble2km,
/// MeteoSwiss ICON CH1 ensemble model.
MeteoswissIconCh1Ensemble,
/// MeteoSwiss ICON CH2 ensemble model.
MeteoswissIconCh2Ensemble,
/// Exact Open-Meteo ensemble model token not yet represented by this enum.
///
/// The token is passed through unchanged and is not validated by the crate.
Other(Cow<'static, str>),
}
impl EnsembleModel {
/// Creates an exact Open-Meteo ensemble model token not yet represented by this enum.
///
/// The token is passed through unchanged and is not validated by the crate.
pub fn other(token: impl Into<Cow<'static, str>>) -> Self {
Self::Other(token.into())
}
}
impl AsApiStr for EnsembleModel {
fn as_api_str(&self) -> Cow<'static, str> {
match self {
Self::IconSeamlessEps => Cow::Borrowed("icon_seamless_eps"),
Self::IconGlobalEps => Cow::Borrowed("icon_global_eps"),
Self::IconEuEps => Cow::Borrowed("icon_eu_eps"),
Self::IconD2Eps => Cow::Borrowed("icon_d2_eps"),
Self::NcepGefsSeamless => Cow::Borrowed("ncep_gefs_seamless"),
Self::NcepGefs025 => Cow::Borrowed("ncep_gefs025"),
Self::NcepGefs05 => Cow::Borrowed("ncep_gefs05"),
Self::NcepAigefs025 => Cow::Borrowed("ncep_aigefs025"),
Self::EcmwfIfs025Ensemble => Cow::Borrowed("ecmwf_ifs025_ensemble"),
Self::EcmwfAifs025Ensemble => Cow::Borrowed("ecmwf_aifs025_ensemble"),
Self::GemGlobalEnsemble => Cow::Borrowed("gem_global_ensemble"),
Self::BomAccessGlobalEnsemble => Cow::Borrowed("bom_access_global_ensemble"),
Self::UkmoGlobalEnsemble20km => Cow::Borrowed("ukmo_global_ensemble_20km"),
Self::UkmoUkEnsemble2km => Cow::Borrowed("ukmo_uk_ensemble_2km"),
Self::MeteoswissIconCh1Ensemble => Cow::Borrowed("meteoswiss_icon_ch1_ensemble"),
Self::MeteoswissIconCh2Ensemble => Cow::Borrowed("meteoswiss_icon_ch2_ensemble"),
Self::Other(token) => token.clone(),
}
}
}
impl ArchiveModel {
/// Creates an exact Open-Meteo archive model token not yet represented by this enum.
///
/// The token is passed through unchanged and is not validated by the crate.
pub fn other(token: impl Into<Cow<'static, str>>) -> Self {
Self::Other(token.into())
}
}
impl AsApiStr for ArchiveModel {
fn as_api_str(&self) -> Cow<'static, str> {
match self {
Self::BestMatch => Cow::Borrowed("best_match"),
Self::Era5Seamless => Cow::Borrowed("era5_seamless"),
Self::Era5 => Cow::Borrowed("era5"),
Self::Era5Land => Cow::Borrowed("era5_land"),
Self::Era5Ensemble => Cow::Borrowed("era5_ensemble"),
Self::EcmwfIfs => Cow::Borrowed("ecmwf_ifs"),
Self::EcmwfIfsAnalysisLongWindow => Cow::Borrowed("ecmwf_ifs_analysis_long_window"),
Self::Cerra => Cow::Borrowed("cerra"),
Self::Other(token) => token.clone(),
}
}
}
impl WeatherModel {
/// Creates an exact Open-Meteo model token not yet represented by this enum.
///
/// The token is passed through unchanged and is not validated by the crate.
pub fn other(token: impl Into<Cow<'static, str>>) -> Self {
Self::Other(token.into())
}
}
impl AsApiStr for WeatherModel {
fn as_api_str(&self) -> Cow<'static, str> {
match self {
Self::BestMatch => Cow::Borrowed("best_match"),
Self::GfsSeamless => Cow::Borrowed("gfs_seamless"),
Self::EcmwfIfs025 => Cow::Borrowed("ecmwf_ifs025"),
Self::IconSeamless => Cow::Borrowed("icon_seamless"),
Self::MeteofranceSeamless => Cow::Borrowed("meteofrance_seamless"),
Self::Other(token) => token.clone(),
}
}
}
/// Soil-temperature depth supported by the forecast API.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i16)]
#[non_exhaustive]
pub enum SoilTemperatureDepth {
/// Surface soil temperature.
Cm0 = 0,
/// Soil temperature at 6 cm.
Cm6 = 6,
/// Soil temperature at 18 cm.
Cm18 = 18,
/// Soil temperature at 54 cm.
Cm54 = 54,
}
impl SoilTemperatureDepth {
pub(crate) fn cm(self) -> i16 {
self as i16
}
}
/// Soil-moisture depth boundary.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i16)]
#[non_exhaustive]
pub enum SoilMoistureDepth {
/// 0 cm.
Cm0 = 0,
/// 1 cm.
Cm1 = 1,
/// 3 cm.
Cm3 = 3,
/// 9 cm.
Cm9 = 9,
/// 27 cm.
Cm27 = 27,
/// 81 cm.
Cm81 = 81,
}
impl SoilMoistureDepth {
pub(crate) fn cm(self) -> i16 {
self as i16
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::query::AsApiStr;
#[test]
fn archive_model_tokens_are_formatted() {
assert_eq!(ArchiveModel::Era5Land.as_api_str(), "era5_land");
assert_eq!(ArchiveModel::EcmwfIfs.as_api_str(), "ecmwf_ifs");
assert_eq!(ArchiveModel::Cerra.as_api_str(), "cerra");
assert_eq!(
ArchiveModel::other("custom_archive_model").as_api_str(),
"custom_archive_model"
);
}
#[test]
fn ensemble_model_tokens_are_formatted() {
assert_eq!(
EnsembleModel::IconSeamlessEps.as_api_str(),
"icon_seamless_eps"
);
assert_eq!(EnsembleModel::IconGlobalEps.as_api_str(), "icon_global_eps");
assert_eq!(EnsembleModel::IconEuEps.as_api_str(), "icon_eu_eps");
assert_eq!(EnsembleModel::IconD2Eps.as_api_str(), "icon_d2_eps");
assert_eq!(
EnsembleModel::NcepGefsSeamless.as_api_str(),
"ncep_gefs_seamless"
);
assert_eq!(EnsembleModel::NcepGefs025.as_api_str(), "ncep_gefs025");
assert_eq!(EnsembleModel::NcepGefs05.as_api_str(), "ncep_gefs05");
assert_eq!(EnsembleModel::NcepAigefs025.as_api_str(), "ncep_aigefs025");
assert_eq!(
EnsembleModel::EcmwfIfs025Ensemble.as_api_str(),
"ecmwf_ifs025_ensemble"
);
assert_eq!(
EnsembleModel::EcmwfAifs025Ensemble.as_api_str(),
"ecmwf_aifs025_ensemble"
);
assert_eq!(
EnsembleModel::GemGlobalEnsemble.as_api_str(),
"gem_global_ensemble"
);
assert_eq!(
EnsembleModel::BomAccessGlobalEnsemble.as_api_str(),
"bom_access_global_ensemble"
);
assert_eq!(
EnsembleModel::UkmoGlobalEnsemble20km.as_api_str(),
"ukmo_global_ensemble_20km"
);
assert_eq!(
EnsembleModel::UkmoUkEnsemble2km.as_api_str(),
"ukmo_uk_ensemble_2km"
);
assert_eq!(
EnsembleModel::MeteoswissIconCh1Ensemble.as_api_str(),
"meteoswiss_icon_ch1_ensemble"
);
assert_eq!(
EnsembleModel::MeteoswissIconCh2Ensemble.as_api_str(),
"meteoswiss_icon_ch2_ensemble"
);
assert_eq!(
EnsembleModel::other("custom_ensemble_model").as_api_str(),
"custom_ensemble_model"
);
}
}