Skip to content

Tag flow-path limit timeslices with their region's demand condition#113

Open
nick-gorman wants to merge 3 commits into
new-manually-extracted-tablesfrom
109-flow-path-timeslice-mapping
Open

Tag flow-path limit timeslices with their region's demand condition#113
nick-gorman wants to merge 3 commits into
new-manually-extracted-tablesfrom
109-flow-path-timeslice-mapping

Conversation

@nick-gorman

@nick-gorman nick-gorman commented Jun 3, 2026

Copy link
Copy Markdown
Member

Background

Two tables on this branch describe transmission limits by demand condition, and they were inconsistent. The custom-constraints templater (#112) emits region-tagged timeslices read from PLEXOS — qld_peak_demand, vic_winter_reference, and so on. The flow-path limits templater, sourced from the IASR workbook, emitted region-agnostic ones — plain peak_demand, summer_typical, winter_reference. AEMO defines these demand conditions per region, so the flow-path limits should carry the same region-specific timeslices as the rest of the model. For an intraregional link the region is implied, but for an interregional link a region-agnostic timeslice is also ambiguous: a NSW↔QLD limit has a peak_demand value in each direction with nothing to say which region's demand condition each belongs to.

PLEXOS tags a path's forward limit with the destination region's demand condition and its reverse limit with the origin region's (the receiving region's load is what tightens an import limit). The investigation is written up in #109. This PR adopts the same convention for the flow-path limits so they're consistent with the custom constraints: each limit's timeslice is prefixed with the lowercased region id, and both tables end up using one vocabulary.

What to expect in the diff

The logic is one new helper, _add_region_to_timeslices, slotted into the existing orchestrator. Most of the line count is the test files relearning the prefixed values and the docstring I/O examples being brought up to date.

A few design choices worth knowing before reading the code:

  • Prefixing happens at the sub-regional level, before any granularity aggregation. A REZ connects its REZ id (geo_from) to its parent sub-region (geo_to), both in the same region, so its symmetric limit should get the same prefix in both directions. single_region later rewrites geo_to to the single NEM geo — so prefixing afterwards would tag the forward limit nem_* and the reverse qld_*. Prefixing first gives both qld_*, and aggregation only re-keys the path id, leaving the prefix alone.
  • The region lookup comes from sub_regional_geography, which already maps both sub-regions and REZs to their region id. NEM regions are added as identities so already-aggregated geos still resolve.
  • A missing geo fails loudly. _assert_geos_have_regions runs before prefixing for every granularity, so an endpoint absent from the geography raises rather than silently producing a NaN prefix.

Where the changes live

src/ispypsa/templater/
└── transmission.py                          ← all the logic: _add_region_to_timeslices,
                                                _build_geo_region_lookup, _assert_geos_have_regions
tests/test_templater/
├── test_transmission.py                     ← sub_regions cases + helper unit tests
├── test_transmission_nem_regions.py         ← nem_regions cases
├── test_transmission_single_region.py       ← single_region cases
└── test_create_ispypsa_inputs_template.py   ← end-to-end wiring

The timeslice column isn't consumed downstream yet, so this is a no-op at runtime; it brings the flow-path timeslices into line with the custom constraints for when both are used together.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/ispypsa/templater/transmission.py 98.83% <100.00%> (+0.12%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

nick-gorman and others added 3 commits June 10, 2026 13:36
The custom-constraints templater emits region-tagged timeslices
(qld_peak_demand etc.) lifted from PLEXOS, but the IASR-derived flow-path
limits carried region-agnostic ones (peak_demand). For intraregional links
that's harmless, but for interregional links the two tables couldn't be lined
up — it wasn't clear which region's demand condition a cross-region limit
belonged to.

The PLEXOS model resolves it consistently: a path's forward limit is tagged
with the destination region's demand condition and its reverse limit with the
origin region's, because the receiving region's load is what tightens the
limit. This applies that rule while the sub-regional limits are built (before
any granularity aggregation, so a REZ stays symmetric even when single_region
retargets its geo_to to NEM), prefixing each timeslice with the lowercased
region id so the flow-path and custom-constraint tables share one vocabulary.

See #109.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The region->region identities in _build_geo_region_lookup were unexercised. The
documented parallel-path injection case (CNSW-SNW) is intra-region, so it drops
out at nem_regions and nothing reached _add_region_to_timeslices with endpoints
that are already NEM regions. This pins that path: a cross-region corridor whose
only base sibling is suffixed is injected at nem_regions and must still read
forward=qld, reverse=nsw — which needs the identities to resolve NSW/QLD.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Captures the conventions used for this PR so future descriptions are
consistent: lead with the story, include a directory-tree diagram, flag the
non-obvious design choices, drop sections that say nothing distinctive, and keep
the tone dry and understated rather than effusive.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nick-gorman nick-gorman force-pushed the 109-flow-path-timeslice-mapping branch from 188cc9a to 4e9366d Compare June 10, 2026 03:37
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