DHDRL commited on
Commit
a34fe6d
·
verified ·
1 Parent(s): b71f249

Update backtest_indonesia.py

Browse files
Files changed (1) hide show
  1. backtest_indonesia.py +12 -9
backtest_indonesia.py CHANGED
@@ -226,10 +226,6 @@ def compute_product_l1_metrics(records: Sequence[Dict[str, Any]]) -> Dict[str, A
226
  tp += 1
227
  else:
228
  fn += 1
229
- # else: labeled day with no drought/flood event recorded --
230
- # not currently reachable given how replay_zone sets gt_source,
231
- # but excluded from tp/fn rather than silently counted as tn,
232
- # consistent with "no confirmed negatives" below.
233
  else:
234
  n_unlabeled += 1
235
  if emitted:
@@ -324,8 +320,18 @@ def replay_zone(
324
  vt = start
325
  while vt <= end:
326
  if mode == "live":
327
- dr = (vt - timedelta(days=35), vt)
328
- obs = edp.fetch_zone_obs(zone_id, dr, cfg)
 
 
 
 
 
 
 
 
 
 
329
  forecast = forecast_backend.forecast(obs)
330
  else:
331
  flag: Dict[str, bool] = {}
@@ -617,8 +623,6 @@ def _self_test() -> int:
617
  )
618
 
619
  # 1. Metrics on a fabricated series with known expected values.
620
- # alerts: 5,6,7 (early), 25 (isolated), 40,41 (inside run 2)
621
- # events: 10-14 (run 1), 40-42 (run 2)
622
  recs: List[DayRecord] = []
623
  for day in range(50):
624
  alert = day in (5, 6, 7, 25, 40, 41)
@@ -688,7 +692,6 @@ def _self_test() -> int:
688
  {"gt_source": "l1", "event_drought": True, "product_emit": "EMITTED"}, # TP
689
  {"gt_source": "l1", "event_flood": True, "product_emit": "EMITTED"}, # TP
690
  {"gt_source": "l1", "event_drought": True, "product_emit": "skipped"}, # FN
691
- # Unlabeled days that got emitted must NOT count as FP under this design.
692
  {"gt_source": "proxy", "event_drought": True, "product_emit": "EMITTED"},
693
  {"gt_source": "proxy+l1_miss", "event_flood": True, "product_emit": "EMITTED"},
694
  {"gt_source": "proxy", "event_drought": False, "product_emit": "skipped"},
 
226
  tp += 1
227
  else:
228
  fn += 1
 
 
 
 
229
  else:
230
  n_unlabeled += 1
231
  if emitted:
 
320
  vt = start
321
  while vt <= end:
322
  if mode == "live":
323
+ # FIX (this session): era5_data_pipeline.fetch_zone_obs now
324
+ # takes an explicit valid_time instead of an ambiguous
325
+ # (start, end) date_range tuple. The old call here --
326
+ # dr = (vt - timedelta(days=35), vt); fetch_zone_obs(zone_id, dr, cfg)
327
+ # -- assumed date_range[1] (vt) was the anchor, but the OLD
328
+ # fetch_zone_obs/_fetch_openmeteo always used date_range[0] as
329
+ # valid_time, so obs.valid_time here was silently vt-35, not
330
+ # vt, for every single --mode live backtest ever run. This is
331
+ # now simpler AND correct: passing vt directly makes that
332
+ # class of bug structurally impossible (no tuple position to
333
+ # get backwards).
334
+ obs = edp.fetch_zone_obs(zone_id, vt, cfg)
335
  forecast = forecast_backend.forecast(obs)
336
  else:
337
  flag: Dict[str, bool] = {}
 
623
  )
624
 
625
  # 1. Metrics on a fabricated series with known expected values.
 
 
626
  recs: List[DayRecord] = []
627
  for day in range(50):
628
  alert = day in (5, 6, 7, 25, 40, 41)
 
692
  {"gt_source": "l1", "event_drought": True, "product_emit": "EMITTED"}, # TP
693
  {"gt_source": "l1", "event_flood": True, "product_emit": "EMITTED"}, # TP
694
  {"gt_source": "l1", "event_drought": True, "product_emit": "skipped"}, # FN
 
695
  {"gt_source": "proxy", "event_drought": True, "product_emit": "EMITTED"},
696
  {"gt_source": "proxy+l1_miss", "event_flood": True, "product_emit": "EMITTED"},
697
  {"gt_source": "proxy", "event_drought": False, "product_emit": "skipped"},