glofas-ewds 0.1.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.
- glofas_ewds-0.1.0/LICENSE +202 -0
- glofas_ewds-0.1.0/PKG-INFO +288 -0
- glofas_ewds-0.1.0/README.md +259 -0
- glofas_ewds-0.1.0/pyproject.toml +119 -0
- glofas_ewds-0.1.0/pyproject.toml.orig +90 -0
- glofas_ewds-0.1.0/src/glofas_ewds/__init__.py +61 -0
- glofas_ewds-0.1.0/src/glofas_ewds/_netcdf.py +15 -0
- glofas_ewds-0.1.0/src/glofas_ewds/cells.py +102 -0
- glofas_ewds-0.1.0/src/glofas_ewds/client.py +104 -0
- glofas_ewds-0.1.0/src/glofas_ewds/download.py +130 -0
- glofas_ewds-0.1.0/src/glofas_ewds/errors.py +10 -0
- glofas_ewds-0.1.0/src/glofas_ewds/fwi.py +120 -0
- glofas_ewds-0.1.0/src/glofas_ewds/glofas.py +88 -0
- glofas_ewds-0.1.0/src/glofas_ewds/py.typed +0 -0
- glofas_ewds-0.1.0/src/glofas_ewds/reference.py +53 -0
- glofas_ewds-0.1.0/src/glofas_ewds/request.py +134 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: glofas-ewds
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: GloFAS river discharge and Copernicus fire danger from the EWDS, on the right grid cell
|
|
5
|
+
Keywords: glofas,copernicus,ewds,river discharge,flood,fire weather index,cems
|
|
6
|
+
Author: Giuseppe Zileni
|
|
7
|
+
Author-email: Giuseppe Zileni <giuseppe.zileni@gmail.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Hydrology
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Dist: numpy>=2.0
|
|
20
|
+
Requires-Dist: cdsapi>=0.7 ; extra == 'ewds'
|
|
21
|
+
Requires-Dist: netcdf4>=1.7 ; extra == 'netcdf'
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Project-URL: Homepage, https://github.com/agent-engineering-studio/glofas-ewds
|
|
24
|
+
Project-URL: Issues, https://github.com/agent-engineering-studio/glofas-ewds/issues
|
|
25
|
+
Project-URL: Changelog, https://github.com/agent-engineering-studio/glofas-ewds/blob/main/CHANGELOG.md
|
|
26
|
+
Provides-Extra: ewds
|
|
27
|
+
Provides-Extra: netcdf
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# glofas-ewds
|
|
31
|
+
|
|
32
|
+
**Is this river high for *this* river?** GloFAS river discharge and the
|
|
33
|
+
Copernicus Fire Weather Index from the Early Warning Data Store, read on the
|
|
34
|
+
right grid cell.
|
|
35
|
+
|
|
36
|
+
[](https://github.com/agent-engineering-studio/glofas-ewds/actions/workflows/ci.yml)
|
|
37
|
+
[](https://pypi.org/project/glofas-ewds/)
|
|
38
|
+
[](https://agentengineering.it/glofas-ewds/)
|
|
39
|
+

|
|
40
|
+

|
|
41
|
+

|
|
42
|
+
[](https://github.com/agent-engineering-studio/glofas-ewds/blob/main/LICENSE)
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
open_meteo_cell(8.43, 45.97) # (8.475, 45.975): the cell whose numbers you are really reading
|
|
46
|
+
discharge_ratio(600.2, 181.9) # 3.3: the Toce's peak against its own ordinary high flow
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
<picture>
|
|
50
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/agent-engineering-studio/glofas-ewds/main/docs/images/cells-dark.png">
|
|
51
|
+
<img alt="A 7 by 7 grid of 0.05 degree GloFAS cells around the Toce near Candoglia, each labelled with its 90th percentile of daily discharge. The cell under the point reads 16 m³/s, the cell just west of it 147 m³/s, the row below 177 to 182 m³/s." src="https://raw.githubusercontent.com/agent-engineering-studio/glofas-ewds/main/docs/images/cells-light.png">
|
|
52
|
+
</picture>
|
|
53
|
+
<sub>One river, 49 cells. The 90th percentile of daily GloFAS 4 discharge in each
|
|
54
|
+
0.05° cell around the Toce near Candoglia, Nov 2024 to Oct 2026, from the public
|
|
55
|
+
Open-Meteo flood API, on Open-Meteo's own coordinates. The red cell is the one
|
|
56
|
+
under the point (16 m³/s); one cell west, 147 m³/s. Drawn by
|
|
57
|
+
<a href="https://github.com/agent-engineering-studio/glofas-ewds/blob/main/docs/make_images.py"><code>docs/make_images.py</code></a>.</sub>
|
|
58
|
+
|
|
59
|
+
- [What is it, in 30 seconds](#what-is-it-in-30-seconds)
|
|
60
|
+
- [Who is it for](#who-is-it-for)
|
|
61
|
+
- [Quick start](#quick-start)
|
|
62
|
+
- [How it works](#how-it-works)
|
|
63
|
+
- [Recipes](#recipes)
|
|
64
|
+
- [The traps we already fell into](#the-traps-we-already-fell-into)
|
|
65
|
+
- [API at a glance](#api-at-a-glance)
|
|
66
|
+
- [Data licence and credits](#data-licence-and-credits)
|
|
67
|
+
|
|
68
|
+
## What is it, in 30 seconds
|
|
69
|
+
|
|
70
|
+
[GloFAS](https://global-flood.emergency.copernicus.eu/), the Global Flood
|
|
71
|
+
Awareness System of Copernicus, models the discharge of every river on Earth
|
|
72
|
+
on a 0.05° grid (about 5 km), every day, with a forecast for the days ahead.
|
|
73
|
+
The [Early Warning Data Store](https://ewds.climate.copernicus.eu/) (EWDS)
|
|
74
|
+
serves it as NetCDF grids, together with the Fire Weather Index Copernicus
|
|
75
|
+
computes on ERA5.
|
|
76
|
+
|
|
77
|
+
The data is free. Using it well is not: a cell too far west turns a river into
|
|
78
|
+
a creek, a model version too new halves every number, and a recent month asked
|
|
79
|
+
for the wrong way does not exist. This package holds the requests and the
|
|
80
|
+
readers that get those right.
|
|
81
|
+
|
|
82
|
+
| | What you get |
|
|
83
|
+
|---|---|
|
|
84
|
+
| 🎯 | **The right cell** for a point: `open_meteo_cell`, the same cell Open-Meteo serves, so a reference from the EWDS and a forecast from Open-Meteo describe the same water |
|
|
85
|
+
| 📜 | **The requests, built for you**: GloFAS 4 history (consolidated, then intermediate), the 00 UTC control forecast, the six FWI components; split by month |
|
|
86
|
+
| 📦 | **Downloads you can re-run**: one file per month or run, nothing asked twice, never half a file left behind |
|
|
87
|
+
| 📈 | **Numbers per node**: daily series, forecast peaks, FWI components, for your own list of points |
|
|
88
|
+
| 📏 | **A reference per river**: `references` and `discharge_ratio`, the forecast peak against the node's own ordinary high flow |
|
|
89
|
+
| 🧪 | **Pure where it can be**: `import glofas_ewds` needs only numpy; `cdsapi` and `netCDF4` are extras |
|
|
90
|
+
|
|
91
|
+
## Who is it for
|
|
92
|
+
|
|
93
|
+
- Anyone who turns GloFAS into **alerts or scores**: a flood model, a
|
|
94
|
+
dashboard, a newsroom map. A ratio to the river's own high flow is
|
|
95
|
+
comparable between the Po and a torrent; a raw m³/s is not.
|
|
96
|
+
- People who already read the **Open-Meteo flood API** and want the history
|
|
97
|
+
in bulk from Copernicus instead of node by node, without the two disagreeing.
|
|
98
|
+
- Fire-weather people checking **their own FWI** against the Copernicus one.
|
|
99
|
+
|
|
100
|
+
It was extracted from [Limen](https://github.com/agent-engineering-studio/limen),
|
|
101
|
+
the landslide, flood and wildfire monitor for Italy, where it fills the
|
|
102
|
+
reference of 3,366 river nodes from about 25 monthly requests instead of about
|
|
103
|
+
52 calls per node to a public API capped at 10,000 calls a day. On 36,637
|
|
104
|
+
points (the whole 0.1° lattice of Italy plus 20,000 random ones) it picks the
|
|
105
|
+
same cell as Limen's own code, and every request and reader gives identical
|
|
106
|
+
results.
|
|
107
|
+
|
|
108
|
+
## Quick start
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install "glofas-ewds[ewds,netcdf]"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
You need an [EWDS account](https://ewds.climate.copernicus.eu/) and its API
|
|
115
|
+
key, in `CDSAPI_URL` / `CDSAPI_KEY` or `~/.cdsapirc`, and you must accept the
|
|
116
|
+
licence of each dataset once on its page.
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
import asyncio
|
|
120
|
+
from datetime import date
|
|
121
|
+
|
|
122
|
+
from glofas_ewds import (
|
|
123
|
+
EwdsClient,
|
|
124
|
+
discharge_ratio,
|
|
125
|
+
discharge_series,
|
|
126
|
+
forecast_peaks,
|
|
127
|
+
references,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
NODES = [(8.43, 45.97), (11.88, 44.29), (11.25, 43.77)] # Toce, Lamone, Arno
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
async def main() -> None:
|
|
134
|
+
ewds = EwdsClient("data/ewds")
|
|
135
|
+
start, end = date(2024, 11, 1), date(2026, 10, 31)
|
|
136
|
+
|
|
137
|
+
history = await ewds.history(start, end) # 24 monthly files
|
|
138
|
+
ref = references(discharge_series(history, NODES, start=start, end=end), p=0.9)
|
|
139
|
+
|
|
140
|
+
latest = await ewds.latest_forecast() # today's run, or yesterday's
|
|
141
|
+
if latest is not None:
|
|
142
|
+
run, path = latest
|
|
143
|
+
for node, peak in forecast_peaks(path, NODES).items():
|
|
144
|
+
print(run, node, round(peak), discharge_ratio(peak, ref[node]))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
asyncio.run(main())
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Each EWDS request waits in a queue, often for minutes; `EwdsClient` waits in a
|
|
151
|
+
thread, so your event loop keeps serving. No live output is shown here: this
|
|
152
|
+
release was built without an EWDS key, and the readers were checked against
|
|
153
|
+
synthetic files and against Limen's code.
|
|
154
|
+
|
|
155
|
+
## How it works
|
|
156
|
+
|
|
157
|
+
```mermaid
|
|
158
|
+
flowchart LR
|
|
159
|
+
N["your nodes<br/>(lon, lat)"] --> C["open_meteo_cell<br/>the cell to read"]
|
|
160
|
+
R["historical_request<br/>forecast_request<br/>fire_request"] --> Q["EWDS queue<br/>(cdsapi)"]
|
|
161
|
+
Q -->|"NetCDF, one per month / run"| D["download_*<br/>.part, then rename"]
|
|
162
|
+
D --> S["discharge_series<br/>forecast_peaks<br/>fire_values"]
|
|
163
|
+
C --> S
|
|
164
|
+
S --> P["references (p90)<br/>discharge_ratio"]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
<picture>
|
|
168
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/agent-engineering-studio/glofas-ewds/main/docs/images/series-dark.png">
|
|
169
|
+
<img alt="Three panels of daily GloFAS 4 discharge from November 2024 to October 2026 with a dashed line at each river's 90th percentile: Toce at Candoglia 182 m³/s with a peak of 600, Lamone at Faenza 14 with a peak of 90, Arno at Florence 97 with a peak of 616." src="https://raw.githubusercontent.com/agent-engineering-studio/glofas-ewds/main/docs/images/series-light.png">
|
|
170
|
+
</picture>
|
|
171
|
+
<sub>Three rivers, three scales. The dashed line is each river's own 90th
|
|
172
|
+
percentile: the Lamone's 90 m³/s is 6.3 times its ordinary high flow, the
|
|
173
|
+
Toce's 600 only 3.3. Real GloFAS 4 data via Open-Meteo, on the cell of the nine
|
|
174
|
+
around each town with the largest mean flow.</sub>
|
|
175
|
+
|
|
176
|
+
## Recipes
|
|
177
|
+
|
|
178
|
+
**A reference without an account.** The pure parts work on any series:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from glofas_ewds import references
|
|
182
|
+
|
|
183
|
+
references({"toce": series}, p=0.9, min_days=365) # None below a year of days
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Your own retry, budget or timeout.** Every download takes any object with
|
|
187
|
+
`retrieve(dataset, request, target)`:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from glofas_ewds import cdsapi_client, download_history
|
|
191
|
+
|
|
192
|
+
download_history(folder, start, end, client=MyQueueWithTimeout(cdsapi_client()))
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Another area.** Every request and download takes `area=(north, west, south,
|
|
196
|
+
east)`; files for an area other than Italy carry the area in their name, so
|
|
197
|
+
two areas can share a folder.
|
|
198
|
+
|
|
199
|
+
**The official FWI next to yours.**
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
files = await ewds.fire(date(2025, 6, 1), date(2025, 9, 30))
|
|
203
|
+
fire_values(files, nodes) # {(node, day): {"fwi": ..., "ffmc": ..., "dc": ...}}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## The traps we already fell into
|
|
207
|
+
|
|
208
|
+
1. **Open-Meteo's numbers belong to the cell one step east.** Open-Meteo
|
|
209
|
+
declares a cell for each point, but the values it returns are the ones the
|
|
210
|
+
EWDS labels 0.05° further east: on 28 real nodes, 28 matched with the
|
|
211
|
+
shift and 0 without it. On the Toce that is 2 m³/s against 22. Comparing
|
|
212
|
+
the declared coordinates does not show it. `open_meteo_cell` applies the
|
|
213
|
+
shift.
|
|
214
|
+
2. **The cell is picked in float32.** Open-Meteo rounds away from zero from an
|
|
215
|
+
origin at -59.975 / -180.025 in single precision, so on the edge between
|
|
216
|
+
two cells it goes up for some points and down for others. Doing it in
|
|
217
|
+
float64 can pick the other neighbour.
|
|
218
|
+
3. **The cell next door is another river.** In the map above the cell under
|
|
219
|
+
the point holds 16 m³/s and the one west of it 147. Never interpolate
|
|
220
|
+
GloFAS between cells, and never trust a point without checking its cell.
|
|
221
|
+
4. **GloFAS 4, not 5.** Open-Meteo's forecast is GloFAS 4 (at Faenza on
|
|
222
|
+
11 October 2026: 7.1 / 6.1 / 8.9 m³/s from the EWDS against 7.3 / 5.9 / 8.9
|
|
223
|
+
from Open-Meteo); version 5 gives about half. A v4 forecast over a v5
|
|
224
|
+
reference is a number without meaning. The requests pin `version_4_0`.
|
|
225
|
+
5. **Recent months are "intermediate".** The consolidated history arrives
|
|
226
|
+
months late (on 11 October 2026 it ended in June; intermediate reached
|
|
227
|
+
8 October). Asking a recent month as consolidated answers "not a valid
|
|
228
|
+
combination"; the downloads then ask it as intermediate, and only for that
|
|
229
|
+
error.
|
|
230
|
+
6. **`valid_time` is the end of the day.** The EWDS stamps a daily mean with
|
|
231
|
+
the end of its 24 hours, the day after the one you asked for.
|
|
232
|
+
`discharge_series` keys values by the day asked.
|
|
233
|
+
7. **Accept the licence first.** Every dataset has a licence to accept once on
|
|
234
|
+
its EWDS page; until then each request answers 403, which looks like a bad
|
|
235
|
+
key. That error is never turned into "intermediate".
|
|
236
|
+
8. **FWI variables have GRIB names.** In the fire NetCDF the variables are
|
|
237
|
+
`fwinx`, `drtcode`, ..., not the names you asked for; `fire_values` finds
|
|
238
|
+
them by `long_name`. The build-up index is "Fire buildup index" there.
|
|
239
|
+
9. **Mind the quotas.** The public Open-Meteo API caps at 10,000 calls a day,
|
|
240
|
+
and two years of discharge cost about 52 calls per node. The EWDS gives the
|
|
241
|
+
same history as a grid: two years of Italy are 24 or 25 monthly requests.
|
|
242
|
+
10. **Absent is not zero.** A node outside the file or on a masked cell (sea,
|
|
243
|
+
no river network) gets no value. `discharge_ratio` returns `None` when it
|
|
244
|
+
does not know how big the river is, never a reassuring 0.
|
|
245
|
+
|
|
246
|
+
## API at a glance
|
|
247
|
+
|
|
248
|
+
| Name | What it does |
|
|
249
|
+
|---|---|
|
|
250
|
+
| `open_meteo_cell(lon, lat)` / `declared_cell(lon, lat)` | the cell Open-Meteo serves / the one it declares |
|
|
251
|
+
| `historical_request`, `forecast_request`, `fire_request`, `months` | the EWDS requests, without sending them |
|
|
252
|
+
| `download_history`, `download_forecast`, `download_fire` | one NetCDF per month or run, re-runnable, with any `retrieve` client |
|
|
253
|
+
| `EwdsClient(folder, *, url=None, key=None, retriever=None, area=ITALY)` | the same downloads, async, plus `latest_forecast()` |
|
|
254
|
+
| `discharge_series`, `forecast_peaks`, `fire_values` | NetCDF to numbers per node (extra `netcdf`) |
|
|
255
|
+
| `percentile`, `references`, `discharge_ratio` | a river's own reference, and how far above it a forecast is |
|
|
256
|
+
| `candidate_runs(today, latest_saved=None)` | the forecast runs worth trying, newest first |
|
|
257
|
+
| `GlofasEwdsError` | the package's exception |
|
|
258
|
+
|
|
259
|
+
The full reference is on the [documentation site](https://agentengineering.it/glofas-ewds/).
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
uv sync
|
|
265
|
+
make check # ruff, mypy --strict, pytest with coverage
|
|
266
|
+
make docs # the documentation site, built with --strict
|
|
267
|
+
uv run --group docs python docs/make_images.py # the README figures
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Data licence and credits
|
|
271
|
+
|
|
272
|
+
- **GloFAS (CEMS-Floods).** Under the
|
|
273
|
+
[CEMS-FLOODS datasets licence](https://ewds.climate.copernicus.eu/licences/cems-floods).
|
|
274
|
+
If you publish data derived from it, say so with a notice such as
|
|
275
|
+
*"Contains modified Copernicus Emergency Management Service information
|
|
276
|
+
[Year]"*. The data is provided for information only: **a ratio computed with
|
|
277
|
+
this package is not a flood warning**, and must not be presented as one.
|
|
278
|
+
Official warnings come from your national and regional services.
|
|
279
|
+
- **Fire danger (`cems-fire-historical-v1`).** © Copernicus Emergency
|
|
280
|
+
Management Service, under the licence stated on its EWDS page, to be
|
|
281
|
+
accepted once there.
|
|
282
|
+
- **The figures** use GloFAS 4 discharge served by the
|
|
283
|
+
[Open-Meteo flood API](https://open-meteo.com/en/docs/flood-api)
|
|
284
|
+
([CC BY 4.0](https://open-meteo.com/en/license)). Contains modified
|
|
285
|
+
Copernicus Emergency Management Service information 2026.
|
|
286
|
+
|
|
287
|
+
This package is not affiliated with Copernicus, ECMWF, the JRC or Open-Meteo.
|
|
288
|
+
Code under [Apache-2.0](https://github.com/agent-engineering-studio/glofas-ewds/blob/main/LICENSE).
|