fwi-chain 1.0.0__py3-none-any.whl
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.
- fwi_chain/__init__.py +34 -0
- fwi_chain/chain.py +300 -0
- fwi_chain/py.typed +0 -0
- fwi_chain-1.0.0.dist-info/METADATA +125 -0
- fwi_chain-1.0.0.dist-info/RECORD +7 -0
- fwi_chain-1.0.0.dist-info/WHEEL +4 -0
- fwi_chain-1.0.0.dist-info/licenses/LICENSE +202 -0
fwi_chain/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Canadian Fire Weather Index chain (Van Wagner 1987)."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import version
|
|
4
|
+
|
|
5
|
+
from fwi_chain.chain import (
|
|
6
|
+
STANDARD_PARAMS,
|
|
7
|
+
FwiOutputs,
|
|
8
|
+
FwiParams,
|
|
9
|
+
FwiState,
|
|
10
|
+
advance,
|
|
11
|
+
buildup_index,
|
|
12
|
+
drought_code,
|
|
13
|
+
duff_moisture_code,
|
|
14
|
+
fine_fuel_moisture_code,
|
|
15
|
+
fire_weather_index,
|
|
16
|
+
initial_spread_index,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__version__ = version("fwi-chain")
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"STANDARD_PARAMS",
|
|
23
|
+
"FwiOutputs",
|
|
24
|
+
"FwiParams",
|
|
25
|
+
"FwiState",
|
|
26
|
+
"__version__",
|
|
27
|
+
"advance",
|
|
28
|
+
"buildup_index",
|
|
29
|
+
"drought_code",
|
|
30
|
+
"duff_moisture_code",
|
|
31
|
+
"fine_fuel_moisture_code",
|
|
32
|
+
"fire_weather_index",
|
|
33
|
+
"initial_spread_index",
|
|
34
|
+
]
|
fwi_chain/chain.py
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"""Canadian Fire Weather Index chain — Van Wagner (1987), pure functions.
|
|
2
|
+
|
|
3
|
+
Six numbers computed from four daily readings taken at local noon
|
|
4
|
+
(temperature, relative humidity, 10 m wind, rain over the previous 24 h):
|
|
5
|
+
|
|
6
|
+
FFMC fine fuel moisture, memory ~2/3 day ┐
|
|
7
|
+
DMC duff moisture, memory ~12 days ├─ three moisture codes
|
|
8
|
+
DC drought code, memory ~52 days ┘
|
|
9
|
+
ISI FFMC × wind → rate of spread
|
|
10
|
+
BUI DMC + DC → available fuel
|
|
11
|
+
FWI ISI + BUI → the index EFFIS publishes for Europe
|
|
12
|
+
|
|
13
|
+
The three moisture codes are **recursive**: today's value is a function of
|
|
14
|
+
yesterday's. That is the whole reason this module has a state DTO: a code
|
|
15
|
+
started from its standard initial value needs weeks of spin-up before it
|
|
16
|
+
means anything, so a caller running the chain day by day has to persist the
|
|
17
|
+
state between runs.
|
|
18
|
+
|
|
19
|
+
Everything here is a pure function of its arguments plus a
|
|
20
|
+
:class:`FwiParams`: no I/O, no clock, no configuration lookup. The numeric
|
|
21
|
+
constants below are Van Wagner's, transcribed from the equations rather than
|
|
22
|
+
tuned, so they are *not* parameters -- what is a parameter is anything a
|
|
23
|
+
deployment may legitimately choose (initial codes, day-length tables), and
|
|
24
|
+
that is what :class:`FwiParams` carries. :data:`STANDARD_PARAMS` holds the
|
|
25
|
+
published defaults.
|
|
26
|
+
|
|
27
|
+
Reference: Van Wagner, C.E. (1987), *Development and structure of the
|
|
28
|
+
Canadian Forest Fire Weather Index System*, Forestry Technical Report 35.
|
|
29
|
+
Equation numbers in the comments are that report's.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
import math
|
|
35
|
+
from dataclasses import dataclass
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"STANDARD_PARAMS",
|
|
39
|
+
"FwiOutputs",
|
|
40
|
+
"FwiParams",
|
|
41
|
+
"FwiState",
|
|
42
|
+
"advance",
|
|
43
|
+
"buildup_index",
|
|
44
|
+
"drought_code",
|
|
45
|
+
"duff_moisture_code",
|
|
46
|
+
"fine_fuel_moisture_code",
|
|
47
|
+
"fire_weather_index",
|
|
48
|
+
"initial_spread_index",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass(frozen=True, slots=True)
|
|
53
|
+
class FwiState:
|
|
54
|
+
"""The three recursive codes carried from one day to the next."""
|
|
55
|
+
|
|
56
|
+
ffmc: float
|
|
57
|
+
dmc: float
|
|
58
|
+
dc: float
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True, slots=True)
|
|
62
|
+
class FwiOutputs:
|
|
63
|
+
"""A day's full chain: the new state plus the three derived indices."""
|
|
64
|
+
|
|
65
|
+
state: FwiState
|
|
66
|
+
isi: float
|
|
67
|
+
bui: float
|
|
68
|
+
fwi: float
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass(frozen=True, slots=True)
|
|
72
|
+
class FwiParams:
|
|
73
|
+
"""What a deployment may choose, as opposed to what Van Wagner fixed.
|
|
74
|
+
|
|
75
|
+
``day_length_dmc`` and ``day_length_dc`` are the 12 monthly factors
|
|
76
|
+
(January first) for the latitude band in use. Van Wagner tabulates them
|
|
77
|
+
for 46°N; a deployment far from that latitude, or in the southern
|
|
78
|
+
hemisphere, passes its own tables.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
ffmc_start: float
|
|
82
|
+
dmc_start: float
|
|
83
|
+
dc_start: float
|
|
84
|
+
day_length_dmc: tuple[float, ...]
|
|
85
|
+
day_length_dc: tuple[float, ...]
|
|
86
|
+
|
|
87
|
+
def __post_init__(self) -> None:
|
|
88
|
+
for name, table in (
|
|
89
|
+
("day_length_dmc", self.day_length_dmc),
|
|
90
|
+
("day_length_dc", self.day_length_dc),
|
|
91
|
+
):
|
|
92
|
+
if len(table) != 12:
|
|
93
|
+
raise ValueError(f"{name} must have 12 monthly entries, got {len(table)}")
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def initial_state(self) -> FwiState:
|
|
97
|
+
return FwiState(ffmc=self.ffmc_start, dmc=self.dmc_start, dc=self.dc_start)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
STANDARD_PARAMS = FwiParams(
|
|
101
|
+
ffmc_start=85.0,
|
|
102
|
+
dmc_start=6.0,
|
|
103
|
+
dc_start=15.0,
|
|
104
|
+
day_length_dmc=(6.5, 7.5, 9.0, 12.8, 13.9, 13.9, 12.4, 10.9, 9.4, 8.0, 7.0, 6.0),
|
|
105
|
+
day_length_dc=(-1.6, -1.6, -1.6, 0.9, 3.8, 5.8, 6.4, 5.0, 2.4, 0.4, -1.6, -1.6),
|
|
106
|
+
)
|
|
107
|
+
"""Van Wagner's spring start-up codes (§4) and day-length factors for 46°N
|
|
108
|
+
(Tables 2 and 3, January first)."""
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _ffmc_to_moisture(ffmc: float) -> float:
|
|
112
|
+
"""Eq. 1 inverted: the FFMC scale back to % moisture content."""
|
|
113
|
+
return 147.2 * (101.0 - ffmc) / (59.5 + ffmc)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def fine_fuel_moisture_code(
|
|
117
|
+
previous: float,
|
|
118
|
+
*,
|
|
119
|
+
temperature_c: float,
|
|
120
|
+
relative_humidity_pct: float,
|
|
121
|
+
wind_speed_kmh: float,
|
|
122
|
+
rain_24h_mm: float,
|
|
123
|
+
) -> float:
|
|
124
|
+
"""Eqs. 1-10. Fine fuel moisture on the 0-101 FFMC scale."""
|
|
125
|
+
h = min(max(relative_humidity_pct, 0.0), 100.0)
|
|
126
|
+
w = max(wind_speed_kmh, 0.0)
|
|
127
|
+
mo = _ffmc_to_moisture(previous)
|
|
128
|
+
|
|
129
|
+
if rain_24h_mm > 0.5: # Eq. 2 — the 0.5 mm is canopy interception.
|
|
130
|
+
rf = rain_24h_mm - 0.5
|
|
131
|
+
absorbed = 42.5 * rf * math.exp(-100.0 / (251.0 - mo)) * (1.0 - math.exp(-6.93 / rf))
|
|
132
|
+
# Eq. 3a. Both the test and the correction read the moisture *before*
|
|
133
|
+
# the rain was added: above 150 % the fuel is already saturated, so
|
|
134
|
+
# the extra water runs off rather than being absorbed. Testing the
|
|
135
|
+
# post-rain value instead would apply the correction to fuels that
|
|
136
|
+
# were dry at dawn, overstating their wetting.
|
|
137
|
+
mo = mo + absorbed + (0.0015 * (mo - 150.0) ** 2 * math.sqrt(rf) if mo > 150.0 else 0.0)
|
|
138
|
+
mo = min(mo, 250.0)
|
|
139
|
+
|
|
140
|
+
# Eq. 4 / 5 — equilibrium moisture content for drying and for wetting.
|
|
141
|
+
ed = (
|
|
142
|
+
0.942 * h**0.679
|
|
143
|
+
+ 11.0 * math.exp((h - 100.0) / 10.0)
|
|
144
|
+
+ 0.18 * (21.1 - temperature_c) * (1.0 - math.exp(-0.115 * h))
|
|
145
|
+
)
|
|
146
|
+
if mo > ed:
|
|
147
|
+
# Eq. 6 / 7 — log drying rate, then the day's drying.
|
|
148
|
+
ko = 0.424 * (1.0 - (h / 100.0) ** 1.7) + 0.0694 * math.sqrt(w) * (1.0 - (h / 100.0) ** 8)
|
|
149
|
+
kd = ko * 0.581 * math.exp(0.0365 * temperature_c)
|
|
150
|
+
m = ed + (mo - ed) * 10.0**-kd
|
|
151
|
+
else:
|
|
152
|
+
ew = (
|
|
153
|
+
0.618 * h**0.753
|
|
154
|
+
+ 10.0 * math.exp((h - 100.0) / 10.0)
|
|
155
|
+
+ 0.18 * (21.1 - temperature_c) * (1.0 - math.exp(-0.115 * h))
|
|
156
|
+
)
|
|
157
|
+
if mo < ew:
|
|
158
|
+
# Eq. 8 / 9 — wetting, the mirror of the drying rate.
|
|
159
|
+
kl = 0.424 * (1.0 - ((100.0 - h) / 100.0) ** 1.7) + 0.0694 * math.sqrt(w) * (
|
|
160
|
+
1.0 - ((100.0 - h) / 100.0) ** 8
|
|
161
|
+
)
|
|
162
|
+
kw = kl * 0.581 * math.exp(0.0365 * temperature_c)
|
|
163
|
+
m = ew - (ew - mo) * 10.0**-kw
|
|
164
|
+
else:
|
|
165
|
+
# Between the two equilibria nothing moves: this is the flat
|
|
166
|
+
# hysteresis band, not a missing branch.
|
|
167
|
+
m = mo
|
|
168
|
+
|
|
169
|
+
ffmc = 59.5 * (250.0 - m) / (147.2 + m) # Eq. 10
|
|
170
|
+
# float(): `x ** y` on two floats is Any to mypy (the result may be complex).
|
|
171
|
+
return float(min(max(ffmc, 0.0), 101.0))
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def duff_moisture_code(
|
|
175
|
+
previous: float,
|
|
176
|
+
*,
|
|
177
|
+
temperature_c: float,
|
|
178
|
+
relative_humidity_pct: float,
|
|
179
|
+
rain_24h_mm: float,
|
|
180
|
+
day_length: float,
|
|
181
|
+
) -> float:
|
|
182
|
+
"""Eqs. 11-17. Moisture of loosely compacted organic layers."""
|
|
183
|
+
h = min(max(relative_humidity_pct, 0.0), 100.0)
|
|
184
|
+
# Eq. 16 — below -1.1 °C drying stops; the clamp *is* the equation.
|
|
185
|
+
t = max(temperature_c, -1.1)
|
|
186
|
+
rk = 1.894 * (t + 1.1) * (100.0 - h) * day_length * 1e-4
|
|
187
|
+
|
|
188
|
+
if rain_24h_mm <= 1.5: # Eq. 11 — below this the duff layer stays dry.
|
|
189
|
+
return max(previous + rk, 0.0)
|
|
190
|
+
|
|
191
|
+
re = 0.92 * rain_24h_mm - 1.27 # Eq. 11
|
|
192
|
+
mo = 20.0 + math.exp(5.6348 - previous / 43.43) # Eq. 12
|
|
193
|
+
if previous <= 33.0: # Eq. 13 a/b/c — slope of the wetting curve.
|
|
194
|
+
b = 100.0 / (0.5 + 0.3 * previous)
|
|
195
|
+
elif previous <= 65.0:
|
|
196
|
+
b = 14.0 - 1.3 * math.log(previous)
|
|
197
|
+
else:
|
|
198
|
+
b = 6.2 * math.log(previous) - 17.2
|
|
199
|
+
mr = mo + 1000.0 * re / (48.77 + b * re) # Eq. 14
|
|
200
|
+
pr = 244.72 - 43.43 * math.log(mr - 20.0) # Eq. 15
|
|
201
|
+
return max(max(pr, 0.0) + rk, 0.0)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def drought_code(
|
|
205
|
+
previous: float,
|
|
206
|
+
*,
|
|
207
|
+
temperature_c: float,
|
|
208
|
+
rain_24h_mm: float,
|
|
209
|
+
day_length: float,
|
|
210
|
+
) -> float:
|
|
211
|
+
"""Eqs. 18-23. Deep, compact organic layers — the seasonal drought memory."""
|
|
212
|
+
t = max(temperature_c, -2.8) # Eq. 22
|
|
213
|
+
pe = max((0.36 * (t + 2.8) + day_length) / 2.0, 0.0) # Eq. 22
|
|
214
|
+
|
|
215
|
+
if rain_24h_mm <= 2.8: # Eq. 18
|
|
216
|
+
return max(previous + pe, 0.0)
|
|
217
|
+
|
|
218
|
+
rd = 0.83 * rain_24h_mm - 1.27 # Eq. 18
|
|
219
|
+
qo = 800.0 * math.exp(-previous / 400.0) # Eq. 19
|
|
220
|
+
qr = qo + 3.937 * rd # Eq. 20
|
|
221
|
+
dr = max(400.0 * math.log(800.0 / qr), 0.0) # Eq. 21
|
|
222
|
+
return max(dr + pe, 0.0)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def initial_spread_index(ffmc: float, *, wind_speed_kmh: float) -> float:
|
|
226
|
+
"""Eqs. 24-26. Expected rate of spread — where wind enters the chain."""
|
|
227
|
+
m = _ffmc_to_moisture(ffmc)
|
|
228
|
+
f_wind = math.exp(0.05039 * max(wind_speed_kmh, 0.0)) # Eq. 24
|
|
229
|
+
f_fine = 91.9 * math.exp(-0.1386 * m) * (1.0 + m**5.31 / 4.93e7) # Eq. 25
|
|
230
|
+
return float(0.208 * f_wind * f_fine) # Eq. 26
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def buildup_index(dmc: float, dc: float) -> float:
|
|
234
|
+
"""Eqs. 27-28. Total fuel available to the fire."""
|
|
235
|
+
denominator = dmc + 0.4 * dc
|
|
236
|
+
if denominator <= 0.0:
|
|
237
|
+
# Both codes at zero — a saturated landscape. Van Wagner's Eq. 27
|
|
238
|
+
# divides by this sum, so the degenerate case is handled here rather
|
|
239
|
+
# than left to raise on a rain-soaked cell.
|
|
240
|
+
return 0.0
|
|
241
|
+
if dmc <= 0.4 * dc:
|
|
242
|
+
return max(0.8 * dmc * dc / denominator, 0.0) # Eq. 27
|
|
243
|
+
bui = dmc - (1.0 - 0.8 * dc / denominator) * (0.92 + (0.0114 * dmc) ** 1.7) # Eq. 28
|
|
244
|
+
return float(max(bui, 0.0))
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def fire_weather_index(isi: float, bui: float) -> float:
|
|
248
|
+
"""Eqs. 29-31. The published index: intensity of a spreading fire."""
|
|
249
|
+
if bui <= 80.0: # Eq. 29
|
|
250
|
+
f_duff = 0.626 * bui**0.809 + 2.0
|
|
251
|
+
else:
|
|
252
|
+
f_duff = 1000.0 / (25.0 + 108.64 * math.exp(-0.023 * bui))
|
|
253
|
+
b = 0.1 * isi * f_duff # Eq. 30
|
|
254
|
+
if b <= 1.0:
|
|
255
|
+
return float(max(b, 0.0))
|
|
256
|
+
return float(math.exp(2.72 * (0.434 * math.log(b)) ** 0.647)) # Eq. 31
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def advance(
|
|
260
|
+
state: FwiState,
|
|
261
|
+
*,
|
|
262
|
+
month: int,
|
|
263
|
+
temperature_c: float,
|
|
264
|
+
relative_humidity_pct: float,
|
|
265
|
+
wind_speed_kmh: float,
|
|
266
|
+
rain_24h_mm: float,
|
|
267
|
+
params: FwiParams,
|
|
268
|
+
) -> FwiOutputs:
|
|
269
|
+
"""One day of the chain: yesterday's codes plus today's noon reading."""
|
|
270
|
+
if not 1 <= month <= 12:
|
|
271
|
+
raise ValueError(f"month must be in 1..12, got {month}")
|
|
272
|
+
idx = month - 1
|
|
273
|
+
ffmc = fine_fuel_moisture_code(
|
|
274
|
+
state.ffmc,
|
|
275
|
+
temperature_c=temperature_c,
|
|
276
|
+
relative_humidity_pct=relative_humidity_pct,
|
|
277
|
+
wind_speed_kmh=wind_speed_kmh,
|
|
278
|
+
rain_24h_mm=rain_24h_mm,
|
|
279
|
+
)
|
|
280
|
+
dmc = duff_moisture_code(
|
|
281
|
+
state.dmc,
|
|
282
|
+
temperature_c=temperature_c,
|
|
283
|
+
relative_humidity_pct=relative_humidity_pct,
|
|
284
|
+
rain_24h_mm=rain_24h_mm,
|
|
285
|
+
day_length=params.day_length_dmc[idx],
|
|
286
|
+
)
|
|
287
|
+
dc = drought_code(
|
|
288
|
+
state.dc,
|
|
289
|
+
temperature_c=temperature_c,
|
|
290
|
+
rain_24h_mm=rain_24h_mm,
|
|
291
|
+
day_length=params.day_length_dc[idx],
|
|
292
|
+
)
|
|
293
|
+
isi = initial_spread_index(ffmc, wind_speed_kmh=wind_speed_kmh)
|
|
294
|
+
bui = buildup_index(dmc, dc)
|
|
295
|
+
return FwiOutputs(
|
|
296
|
+
state=FwiState(ffmc=ffmc, dmc=dmc, dc=dc),
|
|
297
|
+
isi=isi,
|
|
298
|
+
bui=bui,
|
|
299
|
+
fwi=fire_weather_index(isi, bui),
|
|
300
|
+
)
|
fwi_chain/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fwi-chain
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Canadian Fire Weather Index chain (Van Wagner 1987): pure, typed, zero-dependency, verified against the reference day
|
|
5
|
+
Keywords: fire weather index,fwi,wildfire,van wagner,cffdrs,ffmc,drought code
|
|
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 :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Project-URL: Homepage, https://github.com/agent-engineering-studio/fwi-chain
|
|
20
|
+
Project-URL: Issues, https://github.com/agent-engineering-studio/fwi-chain/issues
|
|
21
|
+
Project-URL: Changelog, https://github.com/agent-engineering-studio/fwi-chain/blob/main/CHANGELOG.md
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# fwi-chain
|
|
25
|
+
|
|
26
|
+
The Canadian Forest Fire Weather Index chain (Van Wagner 1987) as pure,
|
|
27
|
+
typed Python functions with no dependencies — verified against the published
|
|
28
|
+
reference day to 1e-9.
|
|
29
|
+
|
|
30
|
+
[](https://github.com/agent-engineering-studio/fwi-chain/actions/workflows/ci.yml)
|
|
31
|
+
[](https://pypi.org/project/fwi-chain/)
|
|
32
|
+
|
|
33
|
+
Four noon readings a day (temperature, relative humidity, 10 m wind, rain
|
|
34
|
+
over the previous 24 h) give six numbers:
|
|
35
|
+
|
|
36
|
+
| Code | What it tracks | Memory |
|
|
37
|
+
|------|----------------|--------|
|
|
38
|
+
| FFMC | fine fuel moisture | ~2/3 day |
|
|
39
|
+
| DMC | duff moisture | ~12 days |
|
|
40
|
+
| DC | deep drought | ~52 days |
|
|
41
|
+
| ISI | rate of spread (FFMC × wind) | — |
|
|
42
|
+
| BUI | available fuel (DMC + DC) | — |
|
|
43
|
+
| FWI | fire intensity, the index EFFIS publishes for Europe | — |
|
|
44
|
+
|
|
45
|
+
The three moisture codes are recursive: today's value depends on
|
|
46
|
+
yesterday's. A chain started from the standard values needs weeks of
|
|
47
|
+
spin-up, so the library gives you the state as a value (`FwiState`) and
|
|
48
|
+
leaves persisting it to you — a table, a file, a cache.
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install fwi-chain
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Use
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from fwi_chain import STANDARD_PARAMS, advance
|
|
60
|
+
|
|
61
|
+
state = STANDARD_PARAMS.initial_state # FFMC/DMC/DC = 85 / 6 / 15
|
|
62
|
+
out = advance(
|
|
63
|
+
state,
|
|
64
|
+
month=4,
|
|
65
|
+
temperature_c=17.0,
|
|
66
|
+
relative_humidity_pct=42.0,
|
|
67
|
+
wind_speed_kmh=25.0,
|
|
68
|
+
rain_24h_mm=0.0,
|
|
69
|
+
params=STANDARD_PARAMS,
|
|
70
|
+
)
|
|
71
|
+
print(round(out.fwi, 2)) # 10.1
|
|
72
|
+
state = out.state # store it: tomorrow starts from here
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The individual equations (`fine_fuel_moisture_code`, `duff_moisture_code`,
|
|
76
|
+
`drought_code`, `initial_spread_index`, `buildup_index`,
|
|
77
|
+
`fire_weather_index`) are exported too.
|
|
78
|
+
|
|
79
|
+
`STANDARD_PARAMS` carries Van Wagner's day-length tables for 46°N. Far from
|
|
80
|
+
that latitude, or south of the equator, build your own `FwiParams`:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from fwi_chain import FwiParams
|
|
84
|
+
|
|
85
|
+
params = FwiParams(
|
|
86
|
+
ffmc_start=85.0,
|
|
87
|
+
dmc_start=6.0,
|
|
88
|
+
dc_start=15.0,
|
|
89
|
+
day_length_dmc=(...), # 12 monthly factors, January first
|
|
90
|
+
day_length_dc=(...),
|
|
91
|
+
)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Why another FWI implementation
|
|
95
|
+
|
|
96
|
+
- **Zero dependencies, scalar, pure.** No NumPy, no xarray, no I/O, no clock.
|
|
97
|
+
It fits a database job, a stream processor or a small service. For gridded
|
|
98
|
+
climate data, [xclim](https://github.com/Ouranosinc/xclim)'s vectorised FWI
|
|
99
|
+
is the better tool.
|
|
100
|
+
- **The state is explicit.** One call is one day; persisting and resuming the
|
|
101
|
+
chain is the caller's choice, not hidden in an array dimension.
|
|
102
|
+
- **Verified, not just tested.** The suite checks the six outputs of the
|
|
103
|
+
reference day of the `cffdrs` test series to an absolute 1e-9, plus every
|
|
104
|
+
rain branch, physical bounds under extreme weather, and the memory
|
|
105
|
+
asymmetry between FFMC and DC.
|
|
106
|
+
|
|
107
|
+
Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
|
|
108
|
+
where it runs the wildfire danger chain for every ~9 km weather node in Italy.
|
|
109
|
+
|
|
110
|
+
## Reference
|
|
111
|
+
|
|
112
|
+
Van Wagner, C.E. (1987). *Development and structure of the Canadian Forest
|
|
113
|
+
Fire Weather Index System*. Canadian Forestry Service, Forestry Technical
|
|
114
|
+
Report 35. Equation numbers in the source comments are that report's.
|
|
115
|
+
|
|
116
|
+
## Development
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
uv sync
|
|
120
|
+
make check
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
[Apache-2.0](./LICENSE).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
fwi_chain/__init__.py,sha256=Lr3_q2v0ghLEFopA8_e_HTNNR-R_RIZIulIC8Txh9Ds,662
|
|
2
|
+
fwi_chain/chain.py,sha256=bOo0TqdpR3Mr-MGENBtl811-rFbGneUTY6qEl9jIPYE,10625
|
|
3
|
+
fwi_chain/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
fwi_chain-1.0.0.dist-info/licenses/LICENSE,sha256=yVuuHRzgI17MzTVgt3LsHvuX80innw--CmNPDCzO_iw,11358
|
|
5
|
+
fwi_chain-1.0.0.dist-info/WHEEL,sha256=3NO1oYsF7mANFUWVdyEQLM-zmecczWWEmmF5rEbXrWk,80
|
|
6
|
+
fwi_chain-1.0.0.dist-info/METADATA,sha256=awygO862x9zrOY25naaw17iD2LP4gJH9WloKZTj_ZPQ,4438
|
|
7
|
+
fwi_chain-1.0.0.dist-info/RECORD,,
|
|
@@ -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
|
+
|