Phenology (kadi.weather.phenology)¶
The Phenology class manages phenological analysis for a location. It detects the start (onset) and end (cessation) of the agricultural season, and calculates growing degree days (GDD) for key crops in the Benin region.
It is used internally by the Weather facade, but can also be instantiated directly.
Direct Import¶
Initialization¶
In standard use, Phenology is created automatically by the Weather facade upon the first invocation of onset(), cessation(), or gdd(). It is then accessible via weather.phenology.
import kadi as kd
weather = kd.Weather(lat=9.3, lon=2.3, name="Parakou")
# Phenology loaded on demand
start_info = weather.onset()
phenology = weather.phenology # Instance available
For direct instantiation:
from kadi.weather import Phenology, Location
import pandas as pd
location = Location(lat=9.3, lon=2.3, name="Parakou")
# rainfall : daily pd.Series of precipitation, indexed by date
# temperature : pd.DataFrame with columns 'temperature_min' and 'temperature_max'
phenology = Phenology(location, rainfall, temperature)
Public Attributes:
| Attribute | Type | Description |
|---|---|---|
location |
Location |
Location of the analysis |
rainfall |
pd.Series |
Daily precipitation series |
temperature |
pd.DataFrame |
Temperature data (temperature_min, temperature_max) |
onset_ts |
pd.Timestamp |
Calculated onset date (None prior to first call) |
crop |
dict |
Crop parameters by crop |
Methods¶
onset()¶
Detects the start date of the agricultural season.
The algorithm used depends on the climate zone of the location:
- North Zone (unimodal regime): Sivakumar algorithm. Searches starting May 1st for the first 3-day sequence accumulating at least 20 mm, without a dry period of more than 7 days over the following 30 days.
- South and Center Zones (bimodal regime): hybrid Walter-Anyadike algorithm applied over two seasonal windows (S1: Jan-Jul, S2: Aug-Dec).
start_info = weather.onset()
print(f"S1 Start : {start_info['onset_1']}")
print(f"S2 Start : {start_info['onset_2']}") # None in North zone
print(f"Algorithm : {start_info['algorithm']}")
print(f"Zone : {start_info['zone']}")
print(f"Confidence : {start_info['confidence']}")
Returns: dict
| Key | Type | Description |
|---|---|---|
onset_date |
str |
Alias for onset_1 (backwards compatibility) |
onset_1 |
str |
Start date of the first season (YYYY-MM-DD) |
onset_2 |
str |
Start date of the second season, None in North zone |
algorithm |
str |
Algorithm used ('Sivakumar' or 'Walter-Anyadike bimodal') |
zone |
str |
Climate zone ('Nord', 'Centre', 'Sud') |
confidence |
float |
Confidence index (0.80 bimodal, 0.85 unimodal) |
Exceptions:
DataError: no precipitation data available.
cessation()¶
Determines the end date of effective rainfall.
Cessation is defined as the last day from which the remaining rainfall accumulation (calculated in reverse) falls below 20 mm.
- North Zone: a single cessation date calculated from September.
- South and Center Zones: two cessation dates (S1 around May-July, S2 around October-December).
end_info = weather.cessation()
print(f"S1 End : {end_info['cessation_1']}")
print(f"S2 End : {end_info['cessation_2']}") # None in North zone
print(f"Season duration : {end_info['duration_days']} days")
print(f"Annual total rain : {end_info['total_rainfall']:.0f} mm")
Returns: dict
| Key | Type | Description |
|---|---|---|
cessation_date |
str |
Alias for cessation_1 (backwards compatibility) |
cessation_1 |
str |
End date of the first season (YYYY-MM-DD) |
cessation_2 |
str |
End date of the second season, None in North zone |
duration_days |
int |
Duration of main season in days (North zone) |
total_rainfall |
float |
Annual total precipitation in mm |
zone |
str |
Climate zone |
Exceptions:
DataError: no precipitation data available.
gdd(crop, start, end)¶
Calculates accumulated Growing Degree Days (GDD) for a crop since the sowing date.
Daily GDD is calculated as:
where Tbase is the base temperature of the crop (threshold below which the plant does not grow).
# GDD for maize sown on May 15
result = weather.gdd(crop="maize", start="2026-05-15")
print(f"Accumulated GDD : {result['gdd_accumulated']:.1f} degC.day")
print(f"Cycle completed : {result['pct_cycle']} %")
print(f"Current stage : {result['phenology_stage']}")
# With an explicit end date
result = weather.gdd(
crop="rice",
start="2026-06-01",
end="2026-10-15",
)
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
crop |
str |
required | Crop name |
start |
str or pd.Timestamp |
required | Sowing date (YYYY-MM-DD) |
end |
str or pd.Timestamp |
None |
End date (today if None) |
Supported Crops:
| Crop | Base Temp (degC) | Total Required GDD |
|---|---|---|
'maize' |
10 | 1300 |
'rice' |
10 | 1500 |
'manioc' |
14 | 3000 |
'sorghum' |
10 | 1400 |
'tomato' |
10 | 1000 |
Returns: dict
| Key | Type | Description |
|---|---|---|
gdd_accumulated |
float |
GDD accumulation over period |
crop |
str |
Crop name |
gdd_total_cycle |
int |
Total GDD required for full cycle |
pct_cycle |
int |
Percentage of cycle completed (0 to 100) |
phenology_stage |
str |
Estimated stage: 'vegetative', 'tasseling/flowering', 'maturity' |
Exceptions:
CropError: unrecognized crop.DataError: insufficient temperature data over the period.
The growing_degree_days() method is deprecated since v1.2.0. Use gdd() instead.
Deprecated Attributes¶
| Legacy Attribute | Replaced By | Since |
|---|---|---|
rainfall_data |
rainfall |
v1.2.0 |
temperature_data |
temperature |
v1.2.0 |
onset_date |
onset_ts |
v1.2.0 |
crop_params |
crop |
v1.2.0 |
Complete Example¶
import kadi as kd
weather = kd.Weather(lat=6.4, lon=2.4, name="Cotonou")
# Season start and end (bimodal regime for South)
start_info = weather.onset()
end_info = weather.cessation()
print(f"S1 Season : {start_info['onset_1']} -> {end_info['cessation_1']}")
print(f"S2 Season : {start_info['onset_2']} -> {end_info['cessation_2']}")
# GDD for maize
gdd = weather.gdd(crop="maize", start=start_info["onset_1"])
print(f"Progress : {gdd['pct_cycle']} % - {gdd['phenology_stage']}")
Phenology ¶
Gère l'analyse phénologique (onset, cessation, GDD) pour une localisation.
Attributs
location (Location): Localisation de l'analyse. rainfall (pd.Series): Série de précipitations quotidiennes. temperature (pd.DataFrame): DataFrame avec temperature_min et temperature_max. onset (pd.Timestamp): Date d'onset calculée (None avant le premier appel). crop (dict): Paramètres culturaux par défaut.
Source code in kadi/weather/phenology.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | |
rainfall_data
property
writable
¶
Ancien nom de rainfall. Déprécié depuis v1.2.0.
temperature_data
property
writable
¶
Ancien nom de temperature. Déprécié depuis v1.2.0.
onset_date
property
writable
¶
Ancien nom de onset_ts. Déprécié depuis v1.2.0.
__init__ ¶
Initialise l'analyseur phénologique.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Location
|
Instance de Location. |
required |
rainfall_data
|
Series
|
Série de précipitations quotidiennes. |
required |
temperature_data
|
DataFrame
|
DataFrame avec les colonnes 'temperature_min' et 'temperature_max'. |
required |
Source code in kadi/weather/phenology.py
onset ¶
Détecte la date de démarrage de la saison agricole.
Pour le Nord (unimodal), utilise l'algorithme de Sivakumar. Pour le Sud et le Centre (bimodal), utilise l'hybride Walter-Anyadike sur deux fenêtres saisonnières (S1 : Jan-Juil, S2 : Aoùt-Déc).
La clé 'onset_date' est maintenue comme alias de 'onset_1' pour la rétrocompatibilité.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
int
|
Fenêtre de calcul (conservé pour la signature). |
120
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionnaire contenant les informations de l'onset. |
Raises:
| Type | Description |
|---|---|
DataError
|
Si aucune donnée de précipitation n'est disponible. |
Source code in kadi/weather/phenology.py
cessation ¶
Détermine la date de fin des pluies utiles.
Pour le Nord (unimodal), calcule une unique date de cessation après août. Pour le Sud et le Centre (bimodal), calcule deux dates de cessation : - cessation_1 : fin de la première saison (autour de juillet) - cessation_2 : fin de la deuxième saison (autour de novembre)
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionnaire avec la ou les dates de cessation. |
Raises:
| Type | Description |
|---|---|
DataError
|
Si aucune donnée de précipitation n'est disponible. |
Source code in kadi/weather/phenology.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
gdd ¶
Calcule l'accumulation des degrés-jours de croissance (GDD) pour une culture donnée.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crop
|
str
|
Nom de la culture ('maize', 'rice', etc.). |
required |
start
|
str or Timestamp
|
Date de début (semis). |
required |
end
|
str or Timestamp
|
Date de fin (défaut : aujourd'hui). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionnaire avec le cumul GDD, le stade phenologique et le pourcentage du cycle accompli. |
Raises:
| Type | Description |
|---|---|
CropError
|
Si la culture n'est pas reconnue. |
DataError
|
Si les données de température sont insuffisantes. |
Source code in kadi/weather/phenology.py
growing_degree_days ¶
growing_degree_days(crop: str, start_date: Union[str, Timestamp], end_date: Union[str, Timestamp] = None) -> dict
Ancienne méthode publique. Dépréciée depuis v1.2.0.
Utilisez gdd(crop, start, end) à la place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crop
|
str
|
Nom de la culture. |
required |
start_date
|
str or Timestamp
|
Ancien nom de |
required |
end_date
|
str or Timestamp
|
Ancien nom de |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Résultat du calcul des degrés-jours de croissance. |