Skip to content

Refactor MC generators into utils/pre/marginal_costs/ package with shared utilities #304

@sherryzuo

Description

@sherryzuo

What

Refactor the three marginal cost generator scripts into a dedicated utils/pre/marginal_costs/ package with a shared common.py module, replacing the current flat layout under utils/pre/.

Current layout:

  • utils/pre/generate_utility_supply_mc.py (energy LBMP + capacity ICAP)
  • utils/pre/generate_utility_tx_dx_mc.py (distribution + sub-transmission via PoP)
  • utils/pre/generate_bulk_tx_mc.py (bulk transmission via SCR)

Proposed layout:

utils/pre/marginal_costs/
├── __init__.py
├── common.py          # shared utilities (see below)
├── supply.py          # energy LBMP + capacity ICAP (from generate_utility_supply_mc.py)
├── distribution.py    # distribution + sub-tx via PoP (from generate_utility_tx_dx_mc.py)
└── bulk_transmission.py  # bulk Tx via SCR (from generate_bulk_tx_mc.py)

Why

The three generators share significant code that is currently handled by cross-imports:

  • build_cairo_8760_timestamps() — supply MC defines it, bulk Tx imports it
  • load_utility_load_profile() + normalize_load_to_cairo_8760() — tx_dx MC defines them, supply MC and bulk Tx import them
  • load_zone_mapping() + get_utility_mapping() — supply MC defines them, bulk Tx imports them
  • S3 save/output patterns are similar across all three

This creates a fragile import graph. A shared common.py would make the dependency clearer and reduce coupling.

How

  1. Create utils/pre/marginal_costs/ package with __init__.py.
  2. Extract shared functions into common.py: build_cairo_8760_timestamps, load_utility_load_profile, normalize_load_to_cairo_8760, load_zone_mapping, get_utility_mapping.
  3. Move each generator into the package, updating imports to use common.
  4. Update all consumers: tests (tests/test_marginal_cost_allocation.py, tests/test_bulk_tx_mc.py), Justfiles (rate_design/hp_rates/ny/Justfile, rate_design/hp_rates/Justfile), and run_scenario.py.
  5. Verify just check and just test pass.

Deliverables

  • utils/pre/marginal_costs/ package with common.py and three generator modules
  • All existing tests pass with updated imports
  • Justfile recipes updated to point to new module paths
  • No remaining cross-imports between generator modules (all shared code in common.py)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions