climate-toolkit 0.1.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.
Files changed (85) hide show
  1. climate_toolkit/__init__.py +109 -0
  2. climate_toolkit/_resources.py +45 -0
  3. climate_toolkit/calculate_hazards/__init__.py +14 -0
  4. climate_toolkit/calculate_hazards/crop_water_balance_params.json +58 -0
  5. climate_toolkit/calculate_hazards/ensemble_hazards.py +1317 -0
  6. climate_toolkit/calculate_hazards/hazards.py +3272 -0
  7. climate_toolkit/cli.py +89 -0
  8. climate_toolkit/climate_statistics/__init__.py +14 -0
  9. climate_toolkit/climate_statistics/ensemble_statistics.py +1065 -0
  10. climate_toolkit/climate_statistics/statistics.py +3375 -0
  11. climate_toolkit/climatology/__init__.py +104 -0
  12. climate_toolkit/climatology/_cli_common.py +172 -0
  13. climate_toolkit/climatology/heat_stress.py +675 -0
  14. climate_toolkit/climatology/human_heat_stress.py +389 -0
  15. climate_toolkit/climatology/long_term_climatology.py +1939 -0
  16. climate_toolkit/climatology/spei.py +745 -0
  17. climate_toolkit/climatology/vpd.py +246 -0
  18. climate_toolkit/climatology/xclim_reference.py +988 -0
  19. climate_toolkit/compare_datasets/__init__.py +14 -0
  20. climate_toolkit/compare_datasets/compare_datasets.py +1070 -0
  21. climate_toolkit/compare_periods/__init__.py +14 -0
  22. climate_toolkit/compare_periods/ensemble_periods.py +2899 -0
  23. climate_toolkit/compare_periods/periods.py +1892 -0
  24. climate_toolkit/crop_calendar/__init__.py +94 -0
  25. climate_toolkit/crop_calendar/ggcmi.py +198 -0
  26. climate_toolkit/crop_calendar/registry.py +102 -0
  27. climate_toolkit/data/__init__.py +1 -0
  28. climate_toolkit/data/ggcmi_phase3/__init__.py +1 -0
  29. climate_toolkit/data/ggcmi_phase3/crop_calendar.parquet +0 -0
  30. climate_toolkit/data/ggcmi_phase3/crop_calendar_manifest.json +42 -0
  31. climate_toolkit/fetch_data/__init__.py +61 -0
  32. climate_toolkit/fetch_data/cache_inventory.py +378 -0
  33. climate_toolkit/fetch_data/fetch_data.py +645 -0
  34. climate_toolkit/fetch_data/gee_xee_batch.py +1133 -0
  35. climate_toolkit/fetch_data/multi_site.py +220 -0
  36. climate_toolkit/fetch_data/nex_gddp_batch.py +1017 -0
  37. climate_toolkit/fetch_data/preprocess_data/__init__.py +18 -0
  38. climate_toolkit/fetch_data/preprocess_data/preprocess_data.py +332 -0
  39. climate_toolkit/fetch_data/runtime_notes.py +80 -0
  40. climate_toolkit/fetch_data/source_data/__init__.py +15 -0
  41. climate_toolkit/fetch_data/source_data/source_data.py +398 -0
  42. climate_toolkit/fetch_data/source_data/sources/agera_5.py +15 -0
  43. climate_toolkit/fetch_data/source_data/sources/chirps.py +63 -0
  44. climate_toolkit/fetch_data/source_data/sources/chirts.py +63 -0
  45. climate_toolkit/fetch_data/source_data/sources/era_5.py +15 -0
  46. climate_toolkit/fetch_data/source_data/sources/gee.py +999 -0
  47. climate_toolkit/fetch_data/source_data/sources/gee_xee.py +107 -0
  48. climate_toolkit/fetch_data/source_data/sources/ghcn_daily.py +87 -0
  49. climate_toolkit/fetch_data/source_data/sources/gsod.py +87 -0
  50. climate_toolkit/fetch_data/source_data/sources/imerg.py +106 -0
  51. climate_toolkit/fetch_data/source_data/sources/nasa_power.py +414 -0
  52. climate_toolkit/fetch_data/source_data/sources/nex_gddp.py +357 -0
  53. climate_toolkit/fetch_data/source_data/sources/nex_gddp_xee.py +1062 -0
  54. climate_toolkit/fetch_data/source_data/sources/soil_grid.py +58 -0
  55. climate_toolkit/fetch_data/source_data/sources/tamsat.py +647 -0
  56. climate_toolkit/fetch_data/source_data/sources/terraclimate.py +96 -0
  57. climate_toolkit/fetch_data/source_data/sources/utils/__init__.py +177 -0
  58. climate_toolkit/fetch_data/source_data/sources/utils/config.yaml +227 -0
  59. climate_toolkit/fetch_data/source_data/sources/utils/models.py +539 -0
  60. climate_toolkit/fetch_data/source_data/sources/utils/settings.py +206 -0
  61. climate_toolkit/fetch_data/source_data/sources/xee_common.py +221 -0
  62. climate_toolkit/fetch_data/transform_data/__init__.py +20 -0
  63. climate_toolkit/fetch_data/transform_data/data_dictionary.yaml +96 -0
  64. climate_toolkit/fetch_data/transform_data/transform_data.py +343 -0
  65. climate_toolkit/gee_check.py +280 -0
  66. climate_toolkit/pipeline.py +307 -0
  67. climate_toolkit/season_analysis/__init__.py +24 -0
  68. climate_toolkit/season_analysis/ensemble.py +1016 -0
  69. climate_toolkit/season_analysis/season_identity.py +58 -0
  70. climate_toolkit/season_analysis/seasons.py +1817 -0
  71. climate_toolkit/weather_station/__init__.py +73 -0
  72. climate_toolkit/weather_station/compare.py +3236 -0
  73. climate_toolkit/weather_station/custom_station.py +464 -0
  74. climate_toolkit/weather_station/dem.py +153 -0
  75. climate_toolkit/weather_station/download.py +1440 -0
  76. climate_toolkit/weather_station/ghcn_daily.py +832 -0
  77. climate_toolkit/weather_station/gsod.py +835 -0
  78. climate_toolkit/weather_station/overrides.py +174 -0
  79. climate_toolkit/weather_station/station_selector.py +607 -0
  80. climate_toolkit-0.1.0.dist-info/METADATA +1548 -0
  81. climate_toolkit-0.1.0.dist-info/RECORD +85 -0
  82. climate_toolkit-0.1.0.dist-info/WHEEL +5 -0
  83. climate_toolkit-0.1.0.dist-info/entry_points.txt +18 -0
  84. climate_toolkit-0.1.0.dist-info/licenses/LICENSE +21 -0
  85. climate_toolkit-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,58 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ import pandas as pd
6
+
7
+
8
+ def build_season_identity(
9
+ onset: Any,
10
+ cessation: Any,
11
+ *,
12
+ length_days: Optional[int] = None,
13
+ regime: Optional[str] = None,
14
+ season_number: Optional[int] = None,
15
+ total_seasons_per_year: Optional[int] = None,
16
+ ) -> Dict[str, Any]:
17
+ onset_ts = pd.to_datetime(onset)
18
+ cess_ts = pd.to_datetime(cessation)
19
+ midpoint_ts = onset_ts + (cess_ts - onset_ts) / 2
20
+ duration = (
21
+ int(length_days)
22
+ if length_days is not None
23
+ else int((cess_ts - onset_ts).days + 1)
24
+ )
25
+
26
+ onset_month = int(onset_ts.month)
27
+ cess_month = int(cess_ts.month)
28
+ regime_name = regime or "unknown"
29
+
30
+ alignment_candidates = [
31
+ f"onset_month:{onset_month:02d}",
32
+ f"month_pair:{onset_month:02d}-{cess_month:02d}",
33
+ f"regime:{regime_name}|onset_month:{onset_month:02d}",
34
+ ]
35
+
36
+ return {
37
+ "onset_date": onset_ts.strftime("%Y-%m-%d"),
38
+ "cessation_date": cess_ts.strftime("%Y-%m-%d"),
39
+ "midpoint_date": midpoint_ts.strftime("%Y-%m-%d"),
40
+ "onset_month": onset_month,
41
+ "cessation_month": cess_month,
42
+ "midpoint_month": int(midpoint_ts.month),
43
+ "onset_doy": int(onset_ts.dayofyear),
44
+ "cessation_doy": int(cess_ts.dayofyear),
45
+ "midpoint_doy": int(midpoint_ts.dayofyear),
46
+ "length_days": duration,
47
+ "crosses_year_boundary": bool(cess_ts.year > onset_ts.year),
48
+ "regime": regime_name,
49
+ "season_number": season_number,
50
+ "total_seasons_per_year": total_seasons_per_year,
51
+ "slot_label": (
52
+ f"season_{season_number}_of_{total_seasons_per_year}"
53
+ if season_number is not None and total_seasons_per_year is not None
54
+ else None
55
+ ),
56
+ "candidate_alignment_keys": alignment_candidates,
57
+ "experimental_alignment_key": alignment_candidates[-1],
58
+ }