Reinforcement Learning
stable-baselines3
deep-reinforcement-learning
agricultural-ai
weather-modelling
curriculum-learning
edge-ai
Instructions to use DHDRL/monsoon-rl with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- stable-baselines3
How to use DHDRL/monsoon-rl with stable-baselines3:
from huggingface_sb3 import load_from_hub checkpoint = load_from_hub( repo_id="DHDRL/monsoon-rl", filename="{MODEL FILENAME}.zip", ) - Notebooks
- Google Colab
- Kaggle
Update test_crop_risk_scorer.py
Browse files- test_crop_risk_scorer.py +2 -21
test_crop_risk_scorer.py
CHANGED
|
@@ -29,7 +29,6 @@ from zone_observation import (
|
|
| 29 |
@pytest.fixture
|
| 30 |
def base_inputs():
|
| 31 |
obs = make_synthetic_zone_obs("z", seed=0)
|
| 32 |
-
# FIX: parameter is horizon_days, not horizon
|
| 33 |
fc = make_synthetic_forecast_result("z", horizon_days=14, valid_time=obs.valid_time)
|
| 34 |
return obs, fc
|
| 35 |
|
|
@@ -120,7 +119,6 @@ class TestForecastInfluence:
|
|
| 120 |
def test_heavy_rain_forecast_increases_flood_risk(self, base_inputs):
|
| 121 |
obs, fc = base_inputs
|
| 122 |
|
| 123 |
-
# FIX: parameter is horizon_days, not horizon
|
| 124 |
fc_heavy = make_synthetic_forecast_result(
|
| 125 |
"z", horizon_days=14, valid_time=obs.valid_time, flood=True
|
| 126 |
)
|
|
@@ -133,7 +131,6 @@ class TestForecastInfluence:
|
|
| 133 |
def test_drought_forecast_increases_drought_risk(self, base_inputs):
|
| 134 |
obs, fc = base_inputs
|
| 135 |
|
| 136 |
-
# FIX: parameter is horizon_days, not horizon
|
| 137 |
fc_dry = make_synthetic_forecast_result(
|
| 138 |
"z", horizon_days=14, valid_time=obs.valid_time, drought=True
|
| 139 |
)
|
|
@@ -153,19 +150,6 @@ class TestAlertThresholds:
|
|
| 153 |
def test_critical_threshold(self, base_inputs):
|
| 154 |
obs, fc = base_inputs
|
| 155 |
|
| 156 |
-
# PRE-EXISTING TEST BUG (found running this suite against the current
|
| 157 |
-
# scorer, not caused by it): supply_drought_weight only affects the
|
| 158 |
-
# `supply` composite, not drought_risk/flood_risk themselves, and
|
| 159 |
-
# WARNING's 0.65 cutoff has never moved regardless of any ADVISORY/
|
| 160 |
-
# WATCH threshold fix -- this test could never have passed as
|
| 161 |
-
# written. Fixed by maxing the raw fields drought_signal()/
|
| 162 |
-
# flood_signal() actually read, on BOTH the obs and forecast sides
|
| 163 |
-
# (_drought_risk/_flood_risk are 60/40 and 55/45 obs/forecast
|
| 164 |
-
# blends -- maxing only the obs left forecast pulling the blend back
|
| 165 |
-
# down). precip_anomaly_idx is a single shared axis (negative =
|
| 166 |
-
# drought, positive = flood), so "drought AND flood" both at max is
|
| 167 |
-
# constructed via the independent flood_extent_pct/drainage_risk_idx
|
| 168 |
-
# terms rather than via precip_anomaly_idx's sign.
|
| 169 |
from zone_observation import ForecastResult
|
| 170 |
|
| 171 |
obs_extreme = make_synthetic_zone_obs("z", drought=True, flood=True, seed=10)
|
|
@@ -223,11 +207,10 @@ class TestConfidence:
|
|
| 223 |
|
| 224 |
def test_observational_data_has_higher_confidence(self):
|
| 225 |
obs_obs = make_synthetic_zone_obs("z", seed=0)
|
| 226 |
-
# FIX: parameter is horizon_days, not horizon
|
| 227 |
fc_obs = make_synthetic_forecast_result("z", horizon_days=14, valid_time=obs_obs.valid_time)
|
| 228 |
|
| 229 |
obs_lowq = make_synthetic_zone_obs("z", seed=1)
|
| 230 |
-
obs_lowq.quality_flag = 3
|
| 231 |
|
| 232 |
rs_high = compute_risk_score(obs_obs, fc_obs)
|
| 233 |
rs_low = compute_risk_score(obs_lowq, fc_obs)
|
|
@@ -251,8 +234,6 @@ class TestStability:
|
|
| 251 |
|
| 252 |
def test_no_nan_under_extreme_inputs(self):
|
| 253 |
obs = make_synthetic_zone_obs("z", seed=99)
|
| 254 |
-
# FIX: ForecastResult is a frozen dataclass — cannot assign to fc.precip_mm.
|
| 255 |
-
# Construct a fresh instance with extreme precipitation values instead.
|
| 256 |
fc_base = make_synthetic_forecast_result("z", horizon_days=30, valid_time=obs.valid_time)
|
| 257 |
from zone_observation import ForecastResult
|
| 258 |
fc = ForecastResult(
|
|
@@ -274,4 +255,4 @@ class TestStability:
|
|
| 274 |
|
| 275 |
rs = compute_risk_score(obs, fc)
|
| 276 |
|
| 277 |
-
assert np.isfinite(rs.supply_shortfall_prob)
|
|
|
|
| 29 |
@pytest.fixture
|
| 30 |
def base_inputs():
|
| 31 |
obs = make_synthetic_zone_obs("z", seed=0)
|
|
|
|
| 32 |
fc = make_synthetic_forecast_result("z", horizon_days=14, valid_time=obs.valid_time)
|
| 33 |
return obs, fc
|
| 34 |
|
|
|
|
| 119 |
def test_heavy_rain_forecast_increases_flood_risk(self, base_inputs):
|
| 120 |
obs, fc = base_inputs
|
| 121 |
|
|
|
|
| 122 |
fc_heavy = make_synthetic_forecast_result(
|
| 123 |
"z", horizon_days=14, valid_time=obs.valid_time, flood=True
|
| 124 |
)
|
|
|
|
| 131 |
def test_drought_forecast_increases_drought_risk(self, base_inputs):
|
| 132 |
obs, fc = base_inputs
|
| 133 |
|
|
|
|
| 134 |
fc_dry = make_synthetic_forecast_result(
|
| 135 |
"z", horizon_days=14, valid_time=obs.valid_time, drought=True
|
| 136 |
)
|
|
|
|
| 150 |
def test_critical_threshold(self, base_inputs):
|
| 151 |
obs, fc = base_inputs
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
from zone_observation import ForecastResult
|
| 154 |
|
| 155 |
obs_extreme = make_synthetic_zone_obs("z", drought=True, flood=True, seed=10)
|
|
|
|
| 207 |
|
| 208 |
def test_observational_data_has_higher_confidence(self):
|
| 209 |
obs_obs = make_synthetic_zone_obs("z", seed=0)
|
|
|
|
| 210 |
fc_obs = make_synthetic_forecast_result("z", horizon_days=14, valid_time=obs_obs.valid_time)
|
| 211 |
|
| 212 |
obs_lowq = make_synthetic_zone_obs("z", seed=1)
|
| 213 |
+
obs_lowq.quality_flag = 3
|
| 214 |
|
| 215 |
rs_high = compute_risk_score(obs_obs, fc_obs)
|
| 216 |
rs_low = compute_risk_score(obs_lowq, fc_obs)
|
|
|
|
| 234 |
|
| 235 |
def test_no_nan_under_extreme_inputs(self):
|
| 236 |
obs = make_synthetic_zone_obs("z", seed=99)
|
|
|
|
|
|
|
| 237 |
fc_base = make_synthetic_forecast_result("z", horizon_days=30, valid_time=obs.valid_time)
|
| 238 |
from zone_observation import ForecastResult
|
| 239 |
fc = ForecastResult(
|
|
|
|
| 255 |
|
| 256 |
rs = compute_risk_score(obs, fc)
|
| 257 |
|
| 258 |
+
assert np.isfinite(rs.supply_shortfall_prob)
|