Skip to content

Re-sequence new-format timeslice patterns onto snapshots - #130

Open
nick-gorman wants to merge 1 commit into
mainfrom
resequence-timeslices-onto-snapshots
Open

Re-sequence new-format timeslice patterns onto snapshots#130
nick-gorman wants to merge 1 commit into
mainfrom
resequence-timeslices-onto-snapshots

Conversation

@nick-gorman

Copy link
Copy Markdown
Member

Adds the translator-side timeslice module. It maps each templated timeslice window pattern onto the model's actual snapshots, producing a timeslice_snapshots table (timeslice_id, investment_periods, snapshots) that later PRs use to apply per-timeslice link limits and to scope the temporal custom constraints.

Each model financial year is assigned a reference year with the same construct_reference_year_mapping call the trace pipeline makes, so timeslice windows and demand/VRE traces always come from the same weather years — the binding interaction between hot-day limits and hot-day demand survives any configured cycle. The year before the first model year also gets a pattern (the cycle's last reference year, cycle-consistent) because winter windows run April–October and must cover the first model year's July–September snapshots.

  • Month-day boundaries of 29 February clamp to 28 February in non-leap model years. The wrap decision for exclusive ends compares month-day strings rather than the placed dates, so clamping a one-day 02-28..02-29 window collapses it to empty instead of stretching it out a year.
  • A configured cycle requesting reference years the timeslices table has no patterns for raises rather than silently never binding.

Dark: nothing imports the module yet (the new-format path is wired in a later PR), so no production behaviour changes — it merges on its unit tests alone.

src/ispypsa/translator/
└── timeslices.py                        → map timeslice patterns onto model snapshots
tests/test_translator/
└── test_timeslice_snapshots.py          → module tests (10)

The translator assigns a reference year to each model financial year
with the identical construct_reference_year_mapping call the trace
pipeline makes, so timeslice windows and demand/VRE traces always come
from the same weather years — the binding interaction between hot-day
limits and hot-day demand survives any configured cycle. The year before
the first model year also gets a pattern (the cycle's last reference
year, cycle-consistent) because winter windows run April-October and
must cover the first model year's July-September snapshots.

Month-day boundaries of 29 February (reference year 2024 carries them)
clamp to 28 February in non-leap model years. The wrap decision for
exclusive ends compares the month-day strings rather than the placed
dates, so clamping a one-day 02-28..02-29 window collapses it to empty
instead of stretching it out a year. A configured cycle requesting
reference years the timeslices table has no patterns for raises rather
than silently never binding.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.82540% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/ispypsa/translator/timeslices.py 96.82% 1 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
src/ispypsa/translator/timeslices.py 96.82% <96.82%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant