effis-client 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.
- effis_client-0.1.0/LICENSE +202 -0
- effis_client-0.1.0/PKG-INFO +147 -0
- effis_client-0.1.0/README.md +119 -0
- effis_client-0.1.0/pyproject.toml +114 -0
- effis_client-0.1.0/pyproject.toml.orig +83 -0
- effis_client-0.1.0/src/effis_client/__init__.py +46 -0
- effis_client-0.1.0/src/effis_client/errors.py +25 -0
- effis_client-0.1.0/src/effis_client/fwi.py +123 -0
- effis_client-0.1.0/src/effis_client/perimeters.py +150 -0
- effis_client-0.1.0/src/effis_client/py.typed +0 -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,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: effis-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Client for the public EFFIS services: burnt-area perimeters and official FWI rasters
|
|
5
|
+
Keywords: effis,copernicus,wildfire,burnt area,fire weather index,fwi,wfs,wms,mapserver
|
|
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: Topic :: Scientific/Engineering :: GIS
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Dist: httpx>=0.27
|
|
20
|
+
Requires-Dist: numpy>=2.0 ; extra == 'raster'
|
|
21
|
+
Requires-Dist: rasterio>=1.4 ; extra == 'raster'
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Project-URL: Homepage, https://github.com/agent-engineering-studio/effis-client
|
|
24
|
+
Project-URL: Issues, https://github.com/agent-engineering-studio/effis-client/issues
|
|
25
|
+
Project-URL: Changelog, https://github.com/agent-engineering-studio/effis-client/blob/main/CHANGELOG.md
|
|
26
|
+
Provides-Extra: raster
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# effis-client
|
|
30
|
+
|
|
31
|
+
Async Python client for the public services of
|
|
32
|
+
[EFFIS](https://forest-fire.emergency.copernicus.eu/), the European Forest
|
|
33
|
+
Fire Information System (Copernicus Emergency Management Service):
|
|
34
|
+
|
|
35
|
+
- **burnt-area perimeters**, from the WFS (`nrt.ba.poly`);
|
|
36
|
+
- the **official Fire Weather Index** chain (FWI, FFMC, DMC, DC, ISI, BUI) as
|
|
37
|
+
raw float values from the WMS, sampled at any point.
|
|
38
|
+
|
|
39
|
+
No account and no API key: both services are public.
|
|
40
|
+
|
|
41
|
+
[](https://github.com/agent-engineering-studio/effis-client/actions/workflows/ci.yml)
|
|
42
|
+
[](https://pypi.org/project/effis-client/)
|
|
43
|
+
|
|
44
|
+
## Why a library for two HTTP calls
|
|
45
|
+
|
|
46
|
+
Because the EFFIS endpoints are **MapServer**, not GeoServer, and every
|
|
47
|
+
GeoServer habit fails differently — usually without an error:
|
|
48
|
+
|
|
49
|
+
| You try | What happens |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `/gwis/ows` | the request hangs (use `/gwis`) |
|
|
52
|
+
| a wrong `typeName` | the connection closes mid-response, no 404 |
|
|
53
|
+
| `CQL_FILTER` for dates | silently ignored: you get every fire ever |
|
|
54
|
+
| `bbox` + `filter` together | the connection dies |
|
|
55
|
+
| camelCase WFS parameters | refused by MapServer's WFS 1.1.0 |
|
|
56
|
+
| `ecmwf007.fwi` (the layer in the EFFIS docs) | `LayerNotDefined` |
|
|
57
|
+
| any error | HTTP **200** with an XML body |
|
|
58
|
+
| FWI for a day past the forecast | HTTP 200 with a raster of **zeros** |
|
|
59
|
+
|
|
60
|
+
The last one is the dangerous one: an all-zero FWI raster reads as "no fire
|
|
61
|
+
danger anywhere" when it means "no data". This library returns `None` for
|
|
62
|
+
it. Each of these was found the hard way, and checked again against the live
|
|
63
|
+
service on 2 November 2026.
|
|
64
|
+
|
|
65
|
+
## Install
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install effis-client # perimeters
|
|
69
|
+
pip install "effis-client[raster]" # + FWI sampling (numpy, rasterio)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Use
|
|
73
|
+
|
|
74
|
+
The fetch functions take your `httpx.AsyncClient`, so timeouts, retries,
|
|
75
|
+
proxies and connection pooling stay yours. Network errors propagate; an
|
|
76
|
+
error disguised as a 200 raises `EffisError`.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import asyncio
|
|
80
|
+
from datetime import date
|
|
81
|
+
|
|
82
|
+
import httpx
|
|
83
|
+
|
|
84
|
+
from effis_client import fetch_fwi, fetch_perimeters
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
async def main() -> None:
|
|
88
|
+
async with httpx.AsyncClient(timeout=60) as client:
|
|
89
|
+
# Bounding boxes are (west, south, east, north), EPSG:4326.
|
|
90
|
+
perimeters = await fetch_perimeters(
|
|
91
|
+
client,
|
|
92
|
+
(16.5, 40.3, 16.8, 40.6),
|
|
93
|
+
start=date(2021, 1, 1),
|
|
94
|
+
end=date(2026, 12, 31),
|
|
95
|
+
)
|
|
96
|
+
print(len(perimeters.features), "fires since 2021")
|
|
97
|
+
|
|
98
|
+
fwi = await fetch_fwi(
|
|
99
|
+
client,
|
|
100
|
+
date(2026, 11, 1),
|
|
101
|
+
points=[(16.6, 40.6)], # (lon, lat)
|
|
102
|
+
bbox=(15.0, 39.5, 17.5, 41.5),
|
|
103
|
+
)
|
|
104
|
+
print(fwi) # {(16.6, 40.6): 10.34...} — or None if EFFIS has no data
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
asyncio.run(main())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Dates are filtered locally, because MapServer cannot filter them server
|
|
111
|
+
side; one bbox returns the whole history (an Italian region is a few hundred
|
|
112
|
+
perimeters, a few hundred KB). If the response hits `max_features`,
|
|
113
|
+
`perimeters.truncated` is `True`: shrink the bbox rather than trusting the
|
|
114
|
+
gap.
|
|
115
|
+
|
|
116
|
+
### Bring your own HTTP
|
|
117
|
+
|
|
118
|
+
Everything the fetch functions do is also exposed as pure functions, for
|
|
119
|
+
callers with their own HTTP layer:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from effis_client import WFS_URL, perimeters_params, parse_perimeters
|
|
123
|
+
from effis_client import WMS_URL, fwi_params, check_tiff, sample_fwi
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Data licence
|
|
127
|
+
|
|
128
|
+
EFFIS data are © European Union, Copernicus Emergency Management Service,
|
|
129
|
+
published under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
|
|
130
|
+
Anything you publish from them must say so. The test fixtures are small
|
|
131
|
+
EFFIS responses under the same licence.
|
|
132
|
+
|
|
133
|
+
Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
|
|
134
|
+
which uses the perimeters as the truth set for its wildfire backtest and the
|
|
135
|
+
FWI rasters to check its own FWI chain
|
|
136
|
+
([`fwi-chain`](https://github.com/agent-engineering-studio/fwi-chain)).
|
|
137
|
+
|
|
138
|
+
## Development
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uv sync
|
|
142
|
+
make check
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
Code: [Apache-2.0](./LICENSE).
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# effis-client
|
|
2
|
+
|
|
3
|
+
Async Python client for the public services of
|
|
4
|
+
[EFFIS](https://forest-fire.emergency.copernicus.eu/), the European Forest
|
|
5
|
+
Fire Information System (Copernicus Emergency Management Service):
|
|
6
|
+
|
|
7
|
+
- **burnt-area perimeters**, from the WFS (`nrt.ba.poly`);
|
|
8
|
+
- the **official Fire Weather Index** chain (FWI, FFMC, DMC, DC, ISI, BUI) as
|
|
9
|
+
raw float values from the WMS, sampled at any point.
|
|
10
|
+
|
|
11
|
+
No account and no API key: both services are public.
|
|
12
|
+
|
|
13
|
+
[](https://github.com/agent-engineering-studio/effis-client/actions/workflows/ci.yml)
|
|
14
|
+
[](https://pypi.org/project/effis-client/)
|
|
15
|
+
|
|
16
|
+
## Why a library for two HTTP calls
|
|
17
|
+
|
|
18
|
+
Because the EFFIS endpoints are **MapServer**, not GeoServer, and every
|
|
19
|
+
GeoServer habit fails differently — usually without an error:
|
|
20
|
+
|
|
21
|
+
| You try | What happens |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `/gwis/ows` | the request hangs (use `/gwis`) |
|
|
24
|
+
| a wrong `typeName` | the connection closes mid-response, no 404 |
|
|
25
|
+
| `CQL_FILTER` for dates | silently ignored: you get every fire ever |
|
|
26
|
+
| `bbox` + `filter` together | the connection dies |
|
|
27
|
+
| camelCase WFS parameters | refused by MapServer's WFS 1.1.0 |
|
|
28
|
+
| `ecmwf007.fwi` (the layer in the EFFIS docs) | `LayerNotDefined` |
|
|
29
|
+
| any error | HTTP **200** with an XML body |
|
|
30
|
+
| FWI for a day past the forecast | HTTP 200 with a raster of **zeros** |
|
|
31
|
+
|
|
32
|
+
The last one is the dangerous one: an all-zero FWI raster reads as "no fire
|
|
33
|
+
danger anywhere" when it means "no data". This library returns `None` for
|
|
34
|
+
it. Each of these was found the hard way, and checked again against the live
|
|
35
|
+
service on 2 November 2026.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install effis-client # perimeters
|
|
41
|
+
pip install "effis-client[raster]" # + FWI sampling (numpy, rasterio)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Use
|
|
45
|
+
|
|
46
|
+
The fetch functions take your `httpx.AsyncClient`, so timeouts, retries,
|
|
47
|
+
proxies and connection pooling stay yours. Network errors propagate; an
|
|
48
|
+
error disguised as a 200 raises `EffisError`.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import asyncio
|
|
52
|
+
from datetime import date
|
|
53
|
+
|
|
54
|
+
import httpx
|
|
55
|
+
|
|
56
|
+
from effis_client import fetch_fwi, fetch_perimeters
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def main() -> None:
|
|
60
|
+
async with httpx.AsyncClient(timeout=60) as client:
|
|
61
|
+
# Bounding boxes are (west, south, east, north), EPSG:4326.
|
|
62
|
+
perimeters = await fetch_perimeters(
|
|
63
|
+
client,
|
|
64
|
+
(16.5, 40.3, 16.8, 40.6),
|
|
65
|
+
start=date(2021, 1, 1),
|
|
66
|
+
end=date(2026, 12, 31),
|
|
67
|
+
)
|
|
68
|
+
print(len(perimeters.features), "fires since 2021")
|
|
69
|
+
|
|
70
|
+
fwi = await fetch_fwi(
|
|
71
|
+
client,
|
|
72
|
+
date(2026, 11, 1),
|
|
73
|
+
points=[(16.6, 40.6)], # (lon, lat)
|
|
74
|
+
bbox=(15.0, 39.5, 17.5, 41.5),
|
|
75
|
+
)
|
|
76
|
+
print(fwi) # {(16.6, 40.6): 10.34...} — or None if EFFIS has no data
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
asyncio.run(main())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Dates are filtered locally, because MapServer cannot filter them server
|
|
83
|
+
side; one bbox returns the whole history (an Italian region is a few hundred
|
|
84
|
+
perimeters, a few hundred KB). If the response hits `max_features`,
|
|
85
|
+
`perimeters.truncated` is `True`: shrink the bbox rather than trusting the
|
|
86
|
+
gap.
|
|
87
|
+
|
|
88
|
+
### Bring your own HTTP
|
|
89
|
+
|
|
90
|
+
Everything the fetch functions do is also exposed as pure functions, for
|
|
91
|
+
callers with their own HTTP layer:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from effis_client import WFS_URL, perimeters_params, parse_perimeters
|
|
95
|
+
from effis_client import WMS_URL, fwi_params, check_tiff, sample_fwi
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Data licence
|
|
99
|
+
|
|
100
|
+
EFFIS data are © European Union, Copernicus Emergency Management Service,
|
|
101
|
+
published under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
|
|
102
|
+
Anything you publish from them must say so. The test fixtures are small
|
|
103
|
+
EFFIS responses under the same licence.
|
|
104
|
+
|
|
105
|
+
Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
|
|
106
|
+
which uses the perimeters as the truth set for its wildfire backtest and the
|
|
107
|
+
FWI rasters to check its own FWI chain
|
|
108
|
+
([`fwi-chain`](https://github.com/agent-engineering-studio/fwi-chain)).
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
uv sync
|
|
114
|
+
make check
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
Code: [Apache-2.0](./LICENSE).
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "effis-client"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Client for the public EFFIS services: burnt-area perimeters and official FWI rasters"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
keywords = [
|
|
7
|
+
"effis",
|
|
8
|
+
"copernicus",
|
|
9
|
+
"wildfire",
|
|
10
|
+
"burnt area",
|
|
11
|
+
"fire weather index",
|
|
12
|
+
"fwi",
|
|
13
|
+
"wfs",
|
|
14
|
+
"wms",
|
|
15
|
+
"mapserver",
|
|
16
|
+
]
|
|
17
|
+
requires-python = ">=3.12"
|
|
18
|
+
license = "Apache-2.0"
|
|
19
|
+
license-files = ["LICENSE"]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Development Status :: 4 - Beta",
|
|
22
|
+
"Intended Audience :: Science/Research",
|
|
23
|
+
"Topic :: Scientific/Engineering :: GIS",
|
|
24
|
+
"Framework :: AsyncIO",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Typing :: Typed",
|
|
30
|
+
]
|
|
31
|
+
dependencies = ["httpx>=0.27"]
|
|
32
|
+
|
|
33
|
+
[[project.authors]]
|
|
34
|
+
name = "Giuseppe Zileni"
|
|
35
|
+
email = "giuseppe.zileni@gmail.com"
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
raster = [
|
|
39
|
+
"numpy>=2.0",
|
|
40
|
+
"rasterio>=1.4",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://github.com/agent-engineering-studio/effis-client"
|
|
45
|
+
Issues = "https://github.com/agent-engineering-studio/effis-client/issues"
|
|
46
|
+
Changelog = "https://github.com/agent-engineering-studio/effis-client/blob/main/CHANGELOG.md"
|
|
47
|
+
|
|
48
|
+
[build-system]
|
|
49
|
+
requires = ["uv_build>=0.13.6,<0.14"]
|
|
50
|
+
build-backend = "uv_build"
|
|
51
|
+
|
|
52
|
+
[dependency-groups]
|
|
53
|
+
dev = [
|
|
54
|
+
"mypy>=1.13",
|
|
55
|
+
"pytest>=8.3",
|
|
56
|
+
"numpy>=2.0",
|
|
57
|
+
"rasterio>=1.4",
|
|
58
|
+
"pytest-cov>=6.0",
|
|
59
|
+
"ruff>=0.8",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[tool.ruff]
|
|
63
|
+
line-length = 100
|
|
64
|
+
target-version = "py312"
|
|
65
|
+
|
|
66
|
+
[tool.ruff.lint]
|
|
67
|
+
select = [
|
|
68
|
+
"E",
|
|
69
|
+
"F",
|
|
70
|
+
"W",
|
|
71
|
+
"I",
|
|
72
|
+
"N",
|
|
73
|
+
"UP",
|
|
74
|
+
"B",
|
|
75
|
+
"C4",
|
|
76
|
+
"SIM",
|
|
77
|
+
"ARG",
|
|
78
|
+
"PTH",
|
|
79
|
+
"RUF",
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
[tool.ruff.lint.per-file-ignores]
|
|
83
|
+
"tests/**" = [
|
|
84
|
+
"ARG",
|
|
85
|
+
"B018",
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
[tool.mypy]
|
|
89
|
+
strict = true
|
|
90
|
+
python_version = "3.12"
|
|
91
|
+
files = [
|
|
92
|
+
"src",
|
|
93
|
+
"tests",
|
|
94
|
+
]
|
|
95
|
+
warn_unused_ignores = true
|
|
96
|
+
warn_redundant_casts = true
|
|
97
|
+
|
|
98
|
+
[[tool.mypy.overrides]]
|
|
99
|
+
module = [
|
|
100
|
+
"rasterio",
|
|
101
|
+
"rasterio.*",
|
|
102
|
+
]
|
|
103
|
+
ignore_missing_imports = true
|
|
104
|
+
|
|
105
|
+
[tool.pytest.ini_options]
|
|
106
|
+
testpaths = ["tests"]
|
|
107
|
+
addopts = "--strict-markers"
|
|
108
|
+
|
|
109
|
+
[tool.coverage.run]
|
|
110
|
+
source = ["effis_client"]
|
|
111
|
+
|
|
112
|
+
[tool.coverage.report]
|
|
113
|
+
fail_under = 90
|
|
114
|
+
show_missing = true
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "effis-client"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Client for the public EFFIS services: burnt-area perimeters and official FWI rasters"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
keywords = ["effis", "copernicus", "wildfire", "burnt area", "fire weather index", "fwi", "wfs", "wms", "mapserver"]
|
|
7
|
+
requires-python = ">=3.12"
|
|
8
|
+
license = "Apache-2.0"
|
|
9
|
+
license-files = ["LICENSE"]
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Giuseppe Zileni", email = "giuseppe.zileni@gmail.com" },
|
|
12
|
+
]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Intended Audience :: Science/Research",
|
|
16
|
+
"Topic :: Scientific/Engineering :: GIS",
|
|
17
|
+
"Framework :: AsyncIO",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"httpx>=0.27",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
raster = [
|
|
30
|
+
"numpy>=2.0",
|
|
31
|
+
"rasterio>=1.4",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/agent-engineering-studio/effis-client"
|
|
36
|
+
Issues = "https://github.com/agent-engineering-studio/effis-client/issues"
|
|
37
|
+
Changelog = "https://github.com/agent-engineering-studio/effis-client/blob/main/CHANGELOG.md"
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["uv_build>=0.13.6,<0.14"]
|
|
41
|
+
build-backend = "uv_build"
|
|
42
|
+
|
|
43
|
+
[dependency-groups]
|
|
44
|
+
dev = [
|
|
45
|
+
"mypy>=1.13",
|
|
46
|
+
"pytest>=8.3",
|
|
47
|
+
"numpy>=2.0",
|
|
48
|
+
"rasterio>=1.4",
|
|
49
|
+
"pytest-cov>=6.0",
|
|
50
|
+
"ruff>=0.8",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[tool.ruff]
|
|
54
|
+
line-length = 100
|
|
55
|
+
target-version = "py312"
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint]
|
|
58
|
+
select = ["E", "F", "W", "I", "N", "UP", "B", "C4", "SIM", "ARG", "PTH", "RUF"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint.per-file-ignores]
|
|
61
|
+
"tests/**" = ["ARG", "B018"]
|
|
62
|
+
|
|
63
|
+
[tool.mypy]
|
|
64
|
+
strict = true
|
|
65
|
+
python_version = "3.12"
|
|
66
|
+
files = ["src", "tests"]
|
|
67
|
+
warn_unused_ignores = true
|
|
68
|
+
warn_redundant_casts = true
|
|
69
|
+
|
|
70
|
+
[[tool.mypy.overrides]]
|
|
71
|
+
module = ["rasterio", "rasterio.*"]
|
|
72
|
+
ignore_missing_imports = true
|
|
73
|
+
|
|
74
|
+
[tool.pytest.ini_options]
|
|
75
|
+
testpaths = ["tests"]
|
|
76
|
+
addopts = "--strict-markers"
|
|
77
|
+
|
|
78
|
+
[tool.coverage.run]
|
|
79
|
+
source = ["effis_client"]
|
|
80
|
+
|
|
81
|
+
[tool.coverage.report]
|
|
82
|
+
fail_under = 90
|
|
83
|
+
show_missing = true
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Client for the public EFFIS services: burnt-area perimeters and official FWI rasters."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import version
|
|
4
|
+
|
|
5
|
+
from effis_client.errors import EffisError
|
|
6
|
+
from effis_client.fwi import (
|
|
7
|
+
COMPONENTS,
|
|
8
|
+
WMS_URL,
|
|
9
|
+
Component,
|
|
10
|
+
check_tiff,
|
|
11
|
+
fetch_fwi,
|
|
12
|
+
fwi_params,
|
|
13
|
+
sample_fwi,
|
|
14
|
+
)
|
|
15
|
+
from effis_client.perimeters import (
|
|
16
|
+
DEFAULT_MAX_FEATURES,
|
|
17
|
+
LAYER,
|
|
18
|
+
WFS_URL,
|
|
19
|
+
Perimeters,
|
|
20
|
+
feature_date,
|
|
21
|
+
fetch_perimeters,
|
|
22
|
+
parse_perimeters,
|
|
23
|
+
perimeters_params,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
__version__ = version("effis-client")
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"COMPONENTS",
|
|
30
|
+
"DEFAULT_MAX_FEATURES",
|
|
31
|
+
"LAYER",
|
|
32
|
+
"WFS_URL",
|
|
33
|
+
"WMS_URL",
|
|
34
|
+
"Component",
|
|
35
|
+
"EffisError",
|
|
36
|
+
"Perimeters",
|
|
37
|
+
"__version__",
|
|
38
|
+
"check_tiff",
|
|
39
|
+
"feature_date",
|
|
40
|
+
"fetch_fwi",
|
|
41
|
+
"fetch_perimeters",
|
|
42
|
+
"fwi_params",
|
|
43
|
+
"parse_perimeters",
|
|
44
|
+
"perimeters_params",
|
|
45
|
+
"sample_fwi",
|
|
46
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
_SERVICE_EXCEPTION = re.compile(
|
|
4
|
+
r'<ServiceException(?=[\s>])(?:\s+code="(?P<code>[^"]*)")?[^>]*>(?P<text>.*?)</ServiceException>',
|
|
5
|
+
re.DOTALL,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class EffisError(Exception):
|
|
10
|
+
"""EFFIS answered, but not with the data asked for.
|
|
11
|
+
|
|
12
|
+
MapServer reports most errors as HTTP 200 with an XML body, so a status
|
|
13
|
+
check alone never sees them.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def describe(body: bytes | str) -> str:
|
|
18
|
+
"""The code and message of a MapServer exception report, else the body's start."""
|
|
19
|
+
text = body if isinstance(body, str) else body.decode("utf-8", "replace")
|
|
20
|
+
match = _SERVICE_EXCEPTION.search(text)
|
|
21
|
+
if match is None:
|
|
22
|
+
return repr(text[:200])
|
|
23
|
+
code = match.group("code")
|
|
24
|
+
message = " ".join(match.group("text").split())
|
|
25
|
+
return f"{code}: {message}" if code else message
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""The official EFFIS Fire Weather Index from its WMS, as numbers, not colours.
|
|
2
|
+
|
|
3
|
+
EFFIS publishes the FWI chain computed on Météo-France weather on the same
|
|
4
|
+
MapServer as the perimeters, but at ``/effis``, not ``/gwis``. Requested with
|
|
5
|
+
``FORMAT=image/tiff`` it returns a float32 GeoTIFF of raw values, which can
|
|
6
|
+
be sampled at any point.
|
|
7
|
+
|
|
8
|
+
Verified against the live service (2026-10-19, again 2026-11-02), and not
|
|
9
|
+
what the EFFIS documentation says:
|
|
10
|
+
|
|
11
|
+
* the layers are ``mf010.<component>`` (fwi, ffmc, dmc, dc, isi, bui); the
|
|
12
|
+
``ecmwf007.fwi`` of the EFFIS example answers ``LayerNotDefined``;
|
|
13
|
+
* ``TIME`` accepts past days, today and the next two; beyond that the
|
|
14
|
+
answer is a 200 with a raster that is **all zeros** -- the absence of data,
|
|
15
|
+
not a calm day. :func:`sample_fwi` returns ``None`` for it;
|
|
16
|
+
* the sea is zero on valid days too: a point on land reads its own pixel,
|
|
17
|
+
and a single zero pixel stays a value;
|
|
18
|
+
* errors come back as HTTP 200 with an XML exception report.
|
|
19
|
+
|
|
20
|
+
Public, no credentials, CC BY 4.0. Sampling needs the ``raster`` extra
|
|
21
|
+
(``pip install effis-client[raster]``).
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from datetime import date
|
|
27
|
+
from typing import TYPE_CHECKING, Literal
|
|
28
|
+
|
|
29
|
+
from effis_client.errors import EffisError, describe
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
import httpx
|
|
33
|
+
|
|
34
|
+
WMS_URL = "https://maps.effis.emergency.copernicus.eu/effis"
|
|
35
|
+
Component = Literal["fwi", "ffmc", "dmc", "dc", "isi", "bui"]
|
|
36
|
+
COMPONENTS: tuple[Component, ...] = ("fwi", "ffmc", "dmc", "dc", "isi", "bui")
|
|
37
|
+
|
|
38
|
+
#: Pixel size of the requested raster, in degrees.
|
|
39
|
+
DEFAULT_STEP = 0.05
|
|
40
|
+
|
|
41
|
+
#: (west, south, east, north) in EPSG:4326 degrees.
|
|
42
|
+
BBox = tuple[float, float, float, float]
|
|
43
|
+
#: (lon, lat).
|
|
44
|
+
Point = tuple[float, float]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def fwi_params(
|
|
48
|
+
day: date,
|
|
49
|
+
bbox: BBox,
|
|
50
|
+
*,
|
|
51
|
+
component: Component = "fwi",
|
|
52
|
+
step: float = DEFAULT_STEP,
|
|
53
|
+
) -> dict[str, str]:
|
|
54
|
+
"""Query parameters of the WMS GetMap request for one component and day.
|
|
55
|
+
|
|
56
|
+
``bbox`` is in the usual lon/lat order; WMS 1.3.0 with EPSG:4326 wants
|
|
57
|
+
latitude first, and the swap happens here.
|
|
58
|
+
"""
|
|
59
|
+
west, south, east, north = bbox
|
|
60
|
+
return {
|
|
61
|
+
"SERVICE": "WMS",
|
|
62
|
+
"VERSION": "1.3.0",
|
|
63
|
+
"REQUEST": "GetMap",
|
|
64
|
+
"LAYERS": f"mf010.{component}",
|
|
65
|
+
"STYLES": "",
|
|
66
|
+
"CRS": "EPSG:4326",
|
|
67
|
+
"BBOX": f"{south},{west},{north},{east}",
|
|
68
|
+
"WIDTH": str(round((east - west) / step)),
|
|
69
|
+
"HEIGHT": str(round((north - south) / step)),
|
|
70
|
+
"FORMAT": "image/tiff",
|
|
71
|
+
"TIME": day.isoformat(),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def sample_fwi(tiff: bytes, points: list[Point]) -> dict[Point, float] | None:
|
|
76
|
+
"""The pixel value under each point; ``None`` when the raster is all zeros.
|
|
77
|
+
|
|
78
|
+
Points outside the raster, or on a non-finite pixel, are left out.
|
|
79
|
+
"""
|
|
80
|
+
import numpy as np
|
|
81
|
+
from rasterio.io import MemoryFile
|
|
82
|
+
|
|
83
|
+
with MemoryFile(tiff) as mem, mem.open() as raster:
|
|
84
|
+
values = raster.read(1)
|
|
85
|
+
if not np.any(values):
|
|
86
|
+
return None
|
|
87
|
+
height, width = raster.height, raster.width
|
|
88
|
+
out: dict[Point, float] = {}
|
|
89
|
+
for lon, lat in points:
|
|
90
|
+
row, col = raster.index(lon, lat)
|
|
91
|
+
if 0 <= row < height and 0 <= col < width:
|
|
92
|
+
v = float(values[row, col])
|
|
93
|
+
if np.isfinite(v):
|
|
94
|
+
out[(lon, lat)] = v
|
|
95
|
+
return out
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def check_tiff(content_type: str, body: bytes) -> bytes:
|
|
99
|
+
"""Return ``body`` if it is a GeoTIFF, else raise :class:`EffisError`."""
|
|
100
|
+
if not content_type.startswith("image/tiff"):
|
|
101
|
+
raise EffisError(f"EFFIS WMS did not return a GeoTIFF: {describe(body)}")
|
|
102
|
+
return body
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
async def fetch_fwi(
|
|
106
|
+
client: httpx.AsyncClient,
|
|
107
|
+
day: date,
|
|
108
|
+
points: list[Point],
|
|
109
|
+
bbox: BBox,
|
|
110
|
+
*,
|
|
111
|
+
component: Component = "fwi",
|
|
112
|
+
step: float = DEFAULT_STEP,
|
|
113
|
+
url: str = WMS_URL,
|
|
114
|
+
) -> dict[Point, float] | None:
|
|
115
|
+
"""One component of the EFFIS chain for ``day``, sampled at ``points``.
|
|
116
|
+
|
|
117
|
+
``None`` means EFFIS has no data for that day. Network and HTTP errors
|
|
118
|
+
propagate; an XML error disguised as a 200 raises :class:`EffisError`.
|
|
119
|
+
"""
|
|
120
|
+
response = await client.get(url, params=fwi_params(day, bbox, component=component, step=step))
|
|
121
|
+
response.raise_for_status()
|
|
122
|
+
tiff = check_tiff(response.headers.get("content-type", ""), response.content)
|
|
123
|
+
return sample_fwi(tiff, points)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Burnt-area perimeters from the EFFIS WFS.
|
|
2
|
+
|
|
3
|
+
The endpoint is **MapServer**, not GeoServer, and that shapes every choice
|
|
4
|
+
below. Verified against the live service:
|
|
5
|
+
|
|
6
|
+
* the base path is ``/gwis``, not ``/gwis/ows`` -- the latter hangs;
|
|
7
|
+
* the layer is ``nrt.ba.poly``. A layer that does not exist makes MapServer
|
|
8
|
+
close the connection mid-response, which surfaces as a transport error
|
|
9
|
+
rather than a 404;
|
|
10
|
+
* ``CQL_FILTER`` is a GeoServer vendor parameter. MapServer ignores it, so a
|
|
11
|
+
date range expressed that way silently filters nothing;
|
|
12
|
+
* ``bbox`` and ``filter`` are mutually exclusive in WFS (and combining them
|
|
13
|
+
kills the connection), so the bbox goes on the wire and the dates are
|
|
14
|
+
applied locally. Cheap in practice: one Italian region's whole history is
|
|
15
|
+
a single response -- Basilicata is 515 perimeters across 2012-2026, 305 KB;
|
|
16
|
+
* parameter names are lowercase: MapServer's WFS 1.1.0 does not accept the
|
|
17
|
+
camelCase spellings GeoServer tolerates.
|
|
18
|
+
|
|
19
|
+
No credentials are needed.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import json
|
|
25
|
+
from dataclasses import dataclass
|
|
26
|
+
from datetime import date
|
|
27
|
+
from typing import TYPE_CHECKING, Any
|
|
28
|
+
|
|
29
|
+
from effis_client.errors import EffisError, describe
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
import httpx
|
|
33
|
+
|
|
34
|
+
WFS_URL = "https://maps.effis.emergency.copernicus.eu/gwis"
|
|
35
|
+
LAYER = "nrt.ba.poly"
|
|
36
|
+
|
|
37
|
+
#: Server-side cap. Above the largest single-region history measured, so the
|
|
38
|
+
#: local date filter never sees a truncated set.
|
|
39
|
+
DEFAULT_MAX_FEATURES = 5000
|
|
40
|
+
|
|
41
|
+
#: (west, south, east, north) in EPSG:4326 degrees.
|
|
42
|
+
BBox = tuple[float, float, float, float]
|
|
43
|
+
|
|
44
|
+
_DATE_FIELDS = ("initialdate", "firedate", "FIREDATE", "fire_date")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True, slots=True)
|
|
48
|
+
class Perimeters:
|
|
49
|
+
"""The perimeters in the requested window, and how many came back in all.
|
|
50
|
+
|
|
51
|
+
``truncated`` is true when the server returned exactly its cap: the
|
|
52
|
+
local date filter then worked on a partial set, and a gap would read as
|
|
53
|
+
"no fires that season". Raise ``max_features`` or shrink the bbox.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
features: list[dict[str, Any]]
|
|
57
|
+
fetched: int
|
|
58
|
+
truncated: bool
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def perimeters_params(
|
|
62
|
+
bbox: BBox,
|
|
63
|
+
*,
|
|
64
|
+
layer: str = LAYER,
|
|
65
|
+
max_features: int = DEFAULT_MAX_FEATURES,
|
|
66
|
+
) -> dict[str, str]:
|
|
67
|
+
"""Query parameters of the WFS GetFeature request for ``bbox``."""
|
|
68
|
+
west, south, east, north = bbox
|
|
69
|
+
return {
|
|
70
|
+
"service": "WFS",
|
|
71
|
+
"version": "1.1.0",
|
|
72
|
+
"request": "GetFeature",
|
|
73
|
+
"typename": layer,
|
|
74
|
+
"outputformat": "geojson",
|
|
75
|
+
"srsname": "EPSG:4326",
|
|
76
|
+
"bbox": f"{west},{south},{east},{north}",
|
|
77
|
+
"maxfeatures": str(max_features),
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def feature_date(feature: dict[str, Any]) -> date | None:
|
|
82
|
+
"""The day a fire started, from whichever field the layer carries."""
|
|
83
|
+
props = feature.get("properties") or {}
|
|
84
|
+
for key in _DATE_FIELDS:
|
|
85
|
+
raw = props.get(key)
|
|
86
|
+
if raw:
|
|
87
|
+
try:
|
|
88
|
+
return date.fromisoformat(str(raw)[:10])
|
|
89
|
+
except ValueError:
|
|
90
|
+
return None
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def parse_perimeters(
|
|
95
|
+
content: bytes | str,
|
|
96
|
+
*,
|
|
97
|
+
start: date,
|
|
98
|
+
end: date,
|
|
99
|
+
max_features: int = DEFAULT_MAX_FEATURES,
|
|
100
|
+
) -> Perimeters:
|
|
101
|
+
"""Parse a GetFeature response and keep the fires started in ``[start, end]``.
|
|
102
|
+
|
|
103
|
+
A feature with no readable date is **kept**: dropping it would lose a
|
|
104
|
+
perimeter that is still real. An empty body is an empty result.
|
|
105
|
+
|
|
106
|
+
Raises :class:`EffisError` when the body is not GeoJSON -- MapServer
|
|
107
|
+
answers 200 with an XML exception report.
|
|
108
|
+
"""
|
|
109
|
+
if not content:
|
|
110
|
+
return Perimeters(features=[], fetched=0, truncated=False)
|
|
111
|
+
try:
|
|
112
|
+
payload = json.loads(content)
|
|
113
|
+
except ValueError as exc:
|
|
114
|
+
raise EffisError(f"EFFIS WFS did not return GeoJSON: {describe(content)}") from exc
|
|
115
|
+
features = list(payload.get("features") or [])
|
|
116
|
+
in_window = [f for f in features if _within(f, start, end)]
|
|
117
|
+
return Perimeters(
|
|
118
|
+
features=in_window,
|
|
119
|
+
fetched=len(features),
|
|
120
|
+
truncated=len(features) >= max_features,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
async def fetch_perimeters(
|
|
125
|
+
client: httpx.AsyncClient,
|
|
126
|
+
bbox: BBox,
|
|
127
|
+
*,
|
|
128
|
+
start: date,
|
|
129
|
+
end: date,
|
|
130
|
+
url: str = WFS_URL,
|
|
131
|
+
layer: str = LAYER,
|
|
132
|
+
max_features: int = DEFAULT_MAX_FEATURES,
|
|
133
|
+
) -> Perimeters:
|
|
134
|
+
"""Fetch the burnt-area perimeters intersecting ``bbox``, started in ``[start, end]``.
|
|
135
|
+
|
|
136
|
+
Network and HTTP errors propagate (``httpx.HTTPError``); retries and
|
|
137
|
+
timeouts are the caller's, through ``client``.
|
|
138
|
+
"""
|
|
139
|
+
response = await client.get(
|
|
140
|
+
url, params=perimeters_params(bbox, layer=layer, max_features=max_features)
|
|
141
|
+
)
|
|
142
|
+
response.raise_for_status()
|
|
143
|
+
if response.status_code == 204:
|
|
144
|
+
return Perimeters(features=[], fetched=0, truncated=False)
|
|
145
|
+
return parse_perimeters(response.content, start=start, end=end, max_features=max_features)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _within(feature: dict[str, Any], start: date, end: date) -> bool:
|
|
149
|
+
when = feature_date(feature)
|
|
150
|
+
return when is None or start <= when <= end
|
|
File without changes
|