Skip to content

Commit de7b05e

Browse files
committed
Cleanup from rebase, address linter errors
1 parent 5930567 commit de7b05e

File tree

4 files changed

+50
-40
lines changed

4 files changed

+50
-40
lines changed

scout/ecm_prep.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,9 @@ def split_clean_data(meas_prepped_objs, full_dat_out):
359359
if not isinstance(m, MeasurePackage):
360360
del m.markets[adopt_scheme]["mseg_adjust"][
361361
"paired heat/cool mseg adjustments"]
362-
# Add remaining contributing microsegment data to
363-
# competition data dict, if the adoption scenario will be competed
364-
# in the run.py module, then delete from measure
362+
# Add fuel splits and sector shape data, if applicable and the adoption scenario
363+
# will be competed in the run.py module, then delete from measure
365364
if full_dat_out[adopt_scheme]:
366-
comp_data_dict[adopt_scheme] = \
367-
m.markets[adopt_scheme]["mseg_adjust"]
368365
# If applicable, add efficient fuel split data to fuel split
369366
# data dict
370367
if len(m.eff_fs_splt[adopt_scheme].keys()) != 0:
@@ -380,6 +377,9 @@ def split_clean_data(meas_prepped_objs, full_dat_out):
380377
# If adoption scenario will not be competed in the run.py
381378
# module, remove detailed mseg breakouts
382379
del m.markets[adopt_scheme]["mseg_out_break"]
380+
# Add remaining contributing microsegment data to competition data dict, then
381+
# delete from measure
382+
comp_data_dict[adopt_scheme] = m.markets[adopt_scheme]["mseg_adjust"]
383383
del m.markets[adopt_scheme]["mseg_adjust"]
384384
# Delete info. about efficient fuel splits for fuel switch measures
385385
del m.eff_fs_splt
@@ -405,6 +405,12 @@ def split_clean_data(meas_prepped_objs, full_dat_out):
405405
del m.linked_htcl_tover
406406
del m.linked_htcl_tover_anchor_eu
407407
del m.linked_htcl_tover_anchor_tech
408+
# Delete flag for reference case measure, which is used for incentives calculations
409+
del m.ref_case_flag
410+
# If backup fuel fraction data exist (will be dataframe), convert to simple flag
411+
# for JSON write-out and subsequent use in run
412+
if m.backup_fuel_fraction is not None:
413+
m.backup_fuel_fraction = True
408414
# For measure packages, replace 'contributing_ECMs'
409415
# objects list with a list of these measures' names and remove
410416
# unnecessary heating/cooling equip/env overlap data
@@ -4825,9 +4831,9 @@ def use_deflt_res_choice(self, mskeys, consume_warn, opts):
48254831
# technology, print warning message
48264832
if mskeys[4] not in consume_warn:
48274833
consume_warn.append(mskeys[4])
4828-
verboseprint(opts.verbose, "WARNING: ECM '" + self.name + "' missing "
4829-
"valid consumer choice data for segment '" + str(mskeys) +
4830-
"'; using default choice data for refrigeration end use", "warning")
4834+
fmt.verboseprint(opts.verbose, "WARNING: ECM '" + self.name + "' missing "
4835+
"valid consumer choice data for segment '" + str(mskeys) +
4836+
"'; using default choice data for refrigeration end use", "warning")
48314837
choice_params = {
48324838
"b1": {yr: deflt_coefs[0] for yr in self.handyvars.aeo_years},
48334839
"b2": {yr: deflt_coefs[1] for yr in self.handyvars.aeo_years}}
@@ -5185,7 +5191,7 @@ def apply_incentives(
51855191
rpl_vals.append(incent_lev * appl_frac)
51865192
# If units don't match, append incentive value of zero and continue
51875193
elif not suppress_ira and perf_thres_units != units:
5188-
verboseprint(
5194+
fmt.verboseprint(
51895195
opts.verbose,
51905196
"Incentive units of " + perf_thres_units +
51915197
" do not match required units of " + units +
@@ -9774,7 +9780,8 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
97749780
fuel->end use->technology type->structure type).
97759781
adopt_scheme (string): Assumed consumer adoption scenario.
97769782
opts (object): Stores user-specified execution options.
9777-
input_data (list): Stores all segment-specific data that need to be assigned to breakouts.
9783+
input_data (list): Stores all segment-specific data that need to be assigned to
9784+
breakouts.
97789785
gap_adj_frac (float): Fraction to apply to breakout data to represent
97799786
portions of msegs that are not covered by ComStock load shapes (if applicable)
97809787
Returns:
@@ -9826,7 +9833,7 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
98269833
eu[0] in ["Heating (Env.)", "Cooling (Env.)"] and
98279834
mskeys[5] == "demand") or (
98289835
eu[0] not in ["Heating (Equip.)", "Cooling (Equip.)",
9829-
"Heating (Env.)", "Cooling (Env.)"]):
9836+
"Heating (Env.)", "Cooling (Env.)"]):
98309837
out_eu = eu[0]
98319838
elif "lighting gain" in mskeys:
98329839
out_eu = "Lighting"
@@ -9925,7 +9932,7 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
99259932
# Create a shorthand for baseline and efficient stock/energy/carbon/
99269933
# cost data to add to the breakout dict
99279934
base_data = [brk_stock_total, brk_energy_total,
9928-
brk_energy_cost, brk_carb_total]
9935+
brk_energy_cost, brk_carb_total]
99299936
eff_data = [brk_stock_total_meas, brk_energy_total_eff,
99309937
brk_energy_cost_eff, brk_carb_total_eff]
99319938

@@ -9949,8 +9956,8 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
99499956
brk_fs_energy_cost_eff_remain_base,
99509957
brk_fs_carb_eff_remain_base]
99519958
eff_data_fs_switch = [brk_fs_energy_eff_remain_switch,
9952-
brk_fs_energy_cost_eff_remain_switch,
9953-
brk_fs_carb_eff_remain_switch]
9959+
brk_fs_energy_cost_eff_remain_switch,
9960+
brk_fs_carb_eff_remain_switch]
99549961
# Record the efficient energy that has not yet fuel switched and
99559962
# total efficient energy for the current mseg for later use in
99569963
# packaging and/or competing measures
@@ -10006,7 +10013,7 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
1000610013
"efficient"][out_cz][out_bldg][out_eu][
1000710014
out_fuel_save][yr] += \
1000810015
(eff_data_fs_base[ind][yr] +
10009-
eff_data_fs_switch[(ind-1)][yr])
10016+
eff_data_fs_switch[(ind-1)][yr])
1001010017
# Note that no baseline fuel, baseline technology
1001110018
# consumption (e.g., not in backup service to
1001210019
# measure) remains for captured stock by
@@ -10023,14 +10030,14 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
1002310030
out_fuel_save][yr] += (
1002410031
base_data[ind][yr] -
1002510032
(eff_data_fs_base[ind][yr] +
10026-
eff_data_fs_switch[(ind-1)][yr]))
10033+
eff_data_fs_switch[(ind-1)][yr]))
1002710034
except KeyError:
1002810035
for ind, key in enumerate(breakout_vars):
1002910036
# Baseline; add in baseline data as-is
1003010037
self.markets[adopt_scheme]["mseg_out_break"][key][
1003110038
"baseline"][out_cz][out_bldg][out_eu][
10032-
out_fuel_save] = {yr: base_data[ind][yr] for
10033-
yr in self.handyvars.aeo_years}
10039+
out_fuel_save] = {yr: base_data[ind][yr] for
10040+
yr in self.handyvars.aeo_years}
1003410041
# Efficient and savings; if there is fuel switching, only
1003510042
# the portion of the efficient case results that have not
1003610043
# yet switched (due to stock turnover limitations) remain,
@@ -10059,7 +10066,7 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
1005910066
"efficient"][out_cz][out_bldg][out_eu][
1006010067
out_fuel_save] = {
1006110068
yr: (eff_data_fs_base[ind][yr] +
10062-
eff_data_fs_switch[(ind-1)][yr]) for
10069+
eff_data_fs_switch[(ind-1)][yr]) for
1006310070
yr in self.handyvars.aeo_years}
1006410071
# Note that no baseline fuel, baseline technology
1006510072
# consumption (e.g., not in backup service to
@@ -10101,8 +10108,8 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
1010110108
key]["efficient"][out_cz][out_bldg][
1010210109
out_eu][out_fuel_gain][yr] += \
1010310110
(eff_data[ind][yr] -
10104-
(eff_data_fs_base[ind][yr] +
10105-
eff_data_fs_switch[(ind - 1)][yr]))
10111+
(eff_data_fs_base[ind][yr] +
10112+
eff_data_fs_switch[(ind - 1)][yr]))
1010610113
# All captured efficient energy goes to
1010710114
# switched to fuel, except in the case where
1010810115
# the switched to measure has dual fuel
@@ -10120,7 +10127,7 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
1012010127
out_fuel_gain][yr] -= (
1012110128
eff_data[ind][yr] -
1012210129
(eff_data_fs_base[ind][yr] +
10123-
eff_data_fs_switch[(ind - 1)][yr]))
10130+
eff_data_fs_switch[(ind - 1)][yr]))
1012410131
else:
1012510132
self.markets[adopt_scheme]["mseg_out_break"][
1012610133
key]["efficient"][out_cz][out_bldg][
@@ -10138,8 +10145,8 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
1013810145
# initialized as zero
1013910146
self.markets[adopt_scheme]["mseg_out_break"][key][
1014010147
"baseline"][out_cz][out_bldg][out_eu][
10141-
out_fuel_gain] = {yr: 0 for yr in
10142-
self.handyvars.aeo_years}
10148+
out_fuel_gain] = {yr: 0 for yr in
10149+
self.handyvars.aeo_years}
1014310150
# Efficient and savings; efficient case energy/
1014410151
# emissions/cost that do not remain with the baseline
1014510152
# fuel are added to the switched to fuel and
@@ -10163,8 +10170,8 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
1016310170
"efficient-captured"][
1016410171
out_cz][out_bldg][out_eu][
1016510172
out_fuel_gain] = {
10166-
yr: (capt_e[yr] -
10167-
eff_data_fs_switch[(ind-1)][yr])
10173+
yr: (capt_e[yr] -
10174+
eff_data_fs_switch[(ind-1)][yr])
1016810175
for yr in
1016910176
self.handyvars.aeo_years}
1017010177
self.markets[adopt_scheme][
@@ -10226,7 +10233,7 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts, input_data
1022610233
self.markets[adopt_scheme]["mseg_out_break"][key][
1022710234
"savings"][out_cz][out_bldg][out_eu] = {
1022810235
yr: (base_data[ind][yr] -
10229-
eff_data[ind][yr]) for
10236+
eff_data[ind][yr]) for
1023010237
yr in self.handyvars.aeo_years}
1023110238

1023210239
# Yield warning if current contributing microsegment cannot

scout/ecm_prep_vars.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22
import argparse
3+
import copy
34
import itertools
45
import numpy
6+
import pandas as pd
57
from datetime import datetime
68
from collections import OrderedDict
79
from scout.utils import JsonIO
@@ -157,7 +159,7 @@ def __init__(self, base_dir, handyfiles, opts):
157159
# Shorthand for current year
158160
self.current_yr = datetime.today().year
159161
# Load metadata including AEO year range
160-
aeo_yrs = Utils.load_json(handyfiles.metadata)
162+
aeo_yrs = JsonIO.load_json(handyfiles.metadata)
161163
# Set minimum modeling year to current year
162164
aeo_min = self.current_yr
163165
# Set maximum modeling year
@@ -258,16 +260,16 @@ def __init__(self, base_dir, handyfiles, opts):
258260
raise ValueError(
259261
f"Error reading in '{handyfiles.cpi_data}': {str(e)}") from None
260262
# Read in commercial equipment capacity factors
261-
self.cap_facts = Utils.load_json(handyfiles.cap_facts)
263+
self.cap_facts = JsonIO.load_json(handyfiles.cap_facts)
262264
# Read in national-level site-source, emissions, and costs data
263-
cost_ss_carb = Utils.load_json(handyfiles.ss_data)
265+
cost_ss_carb = JsonIO.load_json(handyfiles.ss_data)
264266

265267
# Set base-case emissions/cost data to use in assessing reductions for
266268
# non-fuel switching microsegments under a high grid decarbonization
267269
# case, if desired by the user
268270
if handyfiles.ss_data_nonfs is not None:
269271
# Read in national-level site-source, emissions, and costs data
270-
cost_ss_carb_nonfs = Utils.load_json(handyfiles.ss_data_nonfs)
272+
cost_ss_carb_nonfs = JsonIO.load_json(handyfiles.ss_data_nonfs)
271273
else:
272274
cost_ss_carb_nonfs = None
273275
# Set national site to source conversion factors
@@ -294,13 +296,13 @@ def __init__(self, base_dir, handyfiles, opts):
294296
# data) or not (use national data)
295297
if self.regions in ["EMM", "State"]:
296298
# Read in EMM- or state-specific emissions factors and price data
297-
cost_ss_carb_altreg = Utils.load_json(handyfiles.ss_data_altreg)
299+
cost_ss_carb_altreg = JsonIO.load_json(handyfiles.ss_data_altreg)
298300
# Set base-case emissions/cost data to use in assessing reductions
299301
# for non-fuel switching microsegments under a high grid
300302
# decarbonization case, if desired by the user
301303
if handyfiles.ss_data_altreg_nonfs is not None:
302304
# Read in EMM- or state-specific emissions factors and price data
303-
cost_ss_carb_altreg_nonfs = Utils.load_json(handyfiles.ss_data_altreg_nonfs)
305+
cost_ss_carb_altreg_nonfs = JsonIO.load_json(handyfiles.ss_data_altreg_nonfs)
304306
else:
305307
cost_ss_carb_altreg_nonfs = None
306308
# Initialize CO2 intensities based on electricity intensities by
@@ -468,7 +470,7 @@ def __init__(self, base_dir, handyfiles, opts):
468470
for key in self.aeo_years}}}
469471
# Load external data on conversion rates for HP measures
470472
if opts.exog_hp_rates is not False:
471-
self.hp_rates = Utils.load_json(handyfiles.hp_convert_rates)
473+
self.hp_rates = JsonIO.load_json(handyfiles.hp_convert_rates)
472474

473475
# Set a priori assumptions about which non-elec-HP heating/cooling
474476
# technologies in commercial buildings are part of an RTU config.
@@ -552,7 +554,7 @@ def __init__(self, base_dir, handyfiles, opts):
552554
# Load external refrigerant and supply chain methane leakage data
553555
# to assess fugitive emissions sources
554556
if opts.fugitive_emissions is not False:
555-
self.fug_emissions = Utils.load_json(handyfiles.fug_emissions_dat)
557+
self.fug_emissions = JsonIO.load_json(handyfiles.fug_emissions_dat)
556558
else:
557559
self.fug_emissions = None
558560

scout/run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5994,10 +5994,11 @@ def process_codes_bps(self, opts, adopt_scheme, msegs, handyvars, trim_yrs,
59945994
"stock", "energy", "carbon", "cost"]}
59955995
except ValueError:
59965996
fmt.verboseprint(opts.verbose,
5997-
("No measures flagged as basis for setting relative efficiency of "
5998-
"electric equipment for current region and building type. Setting "
5999-
"relative efficiency of conversion to 1 across end uses and proceeding.",
6000-
"warning"))
5997+
("No measures flagged as basis for setting relative "
5998+
"efficiency of electric equipment for current region and "
5999+
"building type. Setting relative efficiency of conversion "
6000+
"to 1 across end uses and proceeding."),
6001+
"warning")
60016002
# Adjust onsite reduction frac. times apply frac. to account for overlaps
60026003
onsite_frac_already_in_place, onsite_times_apply_fracs = self.stack_impacts(
60036004
code_std_flag, reg, bldg, regu_type, onsite_frac_already_in_place,

tests/ecm_prep_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124031,7 +124031,7 @@ def test_ecm_field_updates(self):
124031124031
opts = copy.deepcopy(self.opts_aia)
124032124032
opts.ecm_field_updates = {"climate_zone": ["AIA_CZ1", "AIA_CZ2"],
124033124033
"another_field": "another_val"}
124034-
measures_out_aia = ecm_prep.prepare_measures(
124034+
measures_out_aia = ECMPrep.prepare_measures(
124035124035
self.aia_measures, self.convert_data,
124036124036
self.sample_mseg_in_aia,
124037124037
self.sample_cpl_in_aia, self.handyvars_aia,

0 commit comments

Comments
 (0)