Skip to content

Conversation

@jtlangevin
Copy link
Collaborator

@jtlangevin jtlangevin commented Dec 8, 2025

  • Added methods test_incentives and test_alt_rates to existing MarketUpdatesTest class within ecm_prep_test module. These methods test the user-defined incentives and alternate utilty rate structure capabilities, respectively, which are further described in previously closed pull request Handle alternate rate structures and enhance incentives #532.
  • Both features are tested for a fuel switching measure that shifts from natural gas furnaces. The focus of the testing is CA single family homes.
  • In addition to the tests added to ecm_prep_test a very slight adjustment to the apply_incentives function in ecm_prep was made to improve its robustness to cases where a user provides an incentive for a segment that doesn't already have incentives defined in the AEO baseline data.

Addresses issue #544.

- Both are tested for a fuel switching measure that shifts from natural gas furnaces. The focus of the testing is CA single family homes.
- A slight adjustment to the 'apply_incentives' function was made to improve its robustness to cases where a user provides an incentive for a segment that doesn't already have incentives defined in the AEO baseline data.
@jtlangevin jtlangevin requested review from jmythms, rHorsey and trynthink and removed request for trynthink December 8, 2025 17:29
This was linked to issues Dec 8, 2025
Copy link
Collaborator

@jmythms jmythms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, works as intended, looks good to me:

  1. test_incentives() tests stacking incentives using the 'apply_incentives' in 'fill_mkts' function of ecm_prep.py. Verified test fails by changing numbers in the hv.incentives list.
  2. test_alt_rates() tests fill_mkts function ability to override standard prices using alternative electricity rates. Verfied tests failing by changing the low volume price to 0.07 in the hv.low_volume_rate for existing ASHP.

self.ok_map_frefr_mkts_out[idx])

def test_incentives(self):
"""Test 'apply_incentives' in 'fill_mkts' function given user-defined incentive inputs."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see other docstrings in the MarketUpdatesTest class (eg. test_mseg_ok_full_tp) follow a "description, notes, raises" pattern. Could be good to maintain that pattern for these tests as well.

Comment on lines +18611 to +18653
# Initialize dummy measure with state-level inputs to draw from
base_state_meas = self.ok_tpmeas_partchk_state_in[0]
# Pull handyvars from first sample measure and set year range
hv = copy.deepcopy(base_state_meas.handyvars)
# Set user-defined incentives information; test stacked federal and non-federal incentives
hv.incentives = [[
"CA", "single family home", "existing", "heating", "ASHP",
"electricity", "natural gas", "no", "replace", "federal", False,
0, "warm climates: 2.6; cold climates: 2.8", "COP", 30, 2000,
"$/unit", 2010, 2050, 1],
[
"CA", "single family home", "existing", "heating", "ASHP",
"electricity", "natural gas", "no", "replace", "non-federal", False,
0, 2.6, "COP", 50, float('nan'), "$/unit", 2010, 2050, 1]
]
years = [str(y) for y in hv.aeo_years]

# Seed BY-YEAR carbon price
carb_prices = hv.ccosts
carb_prices.update({y: 1 for y in years})

# Seed BY-YEAR electricity price & carbon intensities
el_prices = hv.ecosts.setdefault(
"residential", {}).setdefault("electricity", {})
el_prices.update({y: 60.0 for y in years})
ng_prices = hv.ecosts["residential"].setdefault("natural gas", {})
ng_prices.update({y: 11.0 for y in years})

el_carb = hv.carb_int.setdefault(
"residential", {}).setdefault("electricity", {})
el_carb.update({y: 5.0e-08 for y in years})
ng_carb = hv.carb_int["residential"].setdefault("natural gas", {})
ng_carb.update({y: 5.0e-08 for y in years})

hv.ss_conv.setdefault("electricity", {})
hv.ss_conv.setdefault("natural gas", {})
for y in years:
hv.ss_conv["electricity"][y] = 1.0
hv.ss_conv["natural gas"][y] = 1.0

# Options: split fuel reporting + pick Max adoption potential
opts = copy.deepcopy(self.opts_state)
opts.adopt_scn_usr = ["Max adoption potential"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, common elements in multiple tests can be grouped to form a test class method. Not required as an emergency fix, but it is recommended, especially if more tests will be added with similar scaffolding. We currently cannot view ecm_prep_test on GitHub because of how big the file is.

# If there is no switching element of the measure, assign the measure's
# incentives modifications to that of the baseline mseg
if not cost_incentives_meas:
if not mskeys_swtch:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to make variable names more "Scout-specific", for ease of understanding.

Copy link
Collaborator

@jmythms jmythms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

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.

Unit test for #532 v1.2 PR and unit testing loose ends

3 participants