fix: correct hourly index calculation for 25-year data
- Reset index per year caused out-of-bounds error - Simplified loop using sequential hour_idx 0-8759 per year Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
5e49926289
commit
38797736a4
1 changed files with 30 additions and 19 deletions
|
|
@ -508,26 +508,37 @@ def run_scenario(inputs: ScenarioInput) -> ScenarioResult:
|
||||||
fy_start = cod_year + year
|
fy_start = cod_year + year
|
||||||
fy_label = f"{fy_start}-{str(fy_start + 1)[-2:]}"
|
fy_label = f"{fy_start}-{str(fy_start + 1)[-2:]}"
|
||||||
|
|
||||||
# Generate timestamps for this year
|
# Run through each hour sequentially (0 to 8759)
|
||||||
hour_idx = 0
|
for hour_idx in range(8760):
|
||||||
for month in range(12):
|
# Map hour_idx to month/day/hour
|
||||||
month_len = month_lengths[month]
|
hour_of_year = hour_idx
|
||||||
for day in range(1, month_len + 1):
|
# Find month by cumulative hours
|
||||||
for hour in range(24):
|
cum_hours = 0
|
||||||
# ISO timestamp
|
for m in range(12):
|
||||||
month_num = month + 4 if month < 8 else month - 8
|
month_len = month_lengths[m]
|
||||||
year_adj = fy_start + 1 if month >= 8 else fy_start
|
if hour_of_year < cum_hours + month_len * 24:
|
||||||
dt = f"{year_adj:04d}-{month_num:02d}-{day:02d}T{hour:02d}:00:00"
|
month = m
|
||||||
hourly_timestamps.append(dt)
|
day_of_month = (hour_of_year - cum_hours) // 24 + 1
|
||||||
hourly_fy.append(fy_label)
|
hour_of_day = (hour_of_year - cum_hours) % 24
|
||||||
hourly_proj_year.append(proj_year)
|
break
|
||||||
|
cum_hours += month_len * 24
|
||||||
|
|
||||||
idx = year * 8760 + hour_idx
|
# ISO timestamp
|
||||||
total_re = pipe.solar_hourly[idx] + pipe.wind_hourly[idx]
|
month_num = month + 4 if month < 8 else month - 8
|
||||||
hourly_total_re.append(total_re)
|
year_adj = fy_start + 1 if month >= 8 else fy_start
|
||||||
hourly_client_end.append(total_re * loss_factor)
|
dt = f"{year_adj:04d}-{month_num:02d}-{day_of_month:02d}T{hour_of_day:02d}:00:00"
|
||||||
hourly_load.append(client_load_mw)
|
hourly_timestamps.append(dt)
|
||||||
hour_idx += 1
|
hourly_fy.append(fy_label)
|
||||||
|
hourly_proj_year.append(proj_year)
|
||||||
|
|
||||||
|
# Use full index into hourly arrays
|
||||||
|
idx = year * 8760 + hour_idx
|
||||||
|
solar_val = pipe.solar_hourly[idx] if pipe.solar_hourly and idx < len(pipe.solar_hourly) else 0.0
|
||||||
|
wind_val = pipe.wind_hourly[idx] if pipe.wind_hourly and idx < len(pipe.wind_hourly) else 0.0
|
||||||
|
total_re = solar_val + wind_val
|
||||||
|
hourly_total_re.append(total_re)
|
||||||
|
hourly_client_end.append(total_re * loss_factor)
|
||||||
|
hourly_load.append(client_load_mw)
|
||||||
|
|
||||||
return ScenarioResult(
|
return ScenarioResult(
|
||||||
inputs=inputs,
|
inputs=inputs,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue