-
Notifications
You must be signed in to change notification settings - Fork 32
Add unit tests for incentives and alt rates #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- 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.
jmythms
left a comment
There was a problem hiding this 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:
- 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.incentiveslist. - 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_ratefor 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.""" |
There was a problem hiding this comment.
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.
| # 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"] |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
jmythms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
test_incentivesandtest_alt_ratesto existingMarketUpdatesTestclass withinecm_prep_testmodule. 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.ecm_prep_testa very slight adjustment to theapply_incentivesfunction inecm_prepwas 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.