Skip to content

Commit b7cf7cf

Browse files
committed
Pass logger to verboseprint method, style fixes
1 parent c536b2c commit b7cf7cf

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

scout/ecm_prep.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def prep_error(meas_name, handyvars, handyfiles):
142142
# Add ECM to skipped list
143143
handyvars.skipped_ecms.append(meas_name)
144144
# Print error message if in verbose mode
145-
# fmt.verboseprint(opts.verbose, err_msg, "error")
145+
# fmt.verboseprint(opts.verbose, err_msg, "error", logger)
146146
# # Log error message to file (see ./generated)
147147
logger.error(err_msg)
148148

@@ -2204,7 +2204,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
22042204
opts.verbose,
22052205
f"ECM {self.name} missing valid baseline stock/energy data for technology "
22062206
f"'{str(mskeys[-2])}'; removing technology from analysis",
2207-
"warning")
2207+
"warning",
2208+
logger)
22082209
# Add to the overall number of key chains that yield "stock"/
22092210
# "energy" keys (but in this case, are missing data)
22102211
valid_keys += 1
@@ -2736,7 +2737,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
27362737
f"ECM '{self.name}' uses invalid performance units for "
27372738
f"technology '{str(mskeys[-2])}' (requires "
27382739
f"{str(perf_base_units)}); removing technology from analysis",
2739-
"warning")
2740+
"warning",
2741+
logger)
27402742
# Continue to the next microsegment
27412743
continue
27422744
# Handle case where measure units do not equal baseline
@@ -2761,7 +2763,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
27612763
f"{str(perf_base_units)}); base units changed to "
27622764
f"{str(perf_units)} and base values multiplied by "
27632765
f"{str(convert_fact)}",
2764-
"warning")
2766+
"warning",
2767+
logger)
27652768
# Convert base performance values to values in
27662769
# measure performance units
27672770
perf_base = {yr: (perf_base[yr] * convert_fact) for
@@ -2814,7 +2817,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
28142817
"residential heating and cooling end uses (both are divided "
28152818
"by 2 when separately considered across heating and cooling "
28162819
"in the raw EIA data)",
2817-
"warning")
2820+
"warning",
2821+
logger)
28182822
# Adjust residential baseline lighting lifetimes to
28192823
# reflect the fact that input data assume 24 h/day of
28202824
# lighting use, rather than 3 h/day as assumed for
@@ -2884,7 +2888,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
28842888
f"/lifetime data for technology '{str(mskeys[-2])}'; "
28852889
"technology will remain in analysis with cost of zero; "
28862890
"if lifetime data are missing, lifetime is set to 10 years",
2887-
"warning")
2891+
"warning",
2892+
logger)
28882893

28892894
# In all other cases, to avoid removing any msegs,
28902895
# set the baseline cost and performance to the measure
@@ -2928,7 +2933,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
29282933
"technology applies to special lighting case and will "
29292934
"remain in analysis at same cost/performance as ECM; if "
29302935
"lifetime data are missing, lifetime is set to 10 years",
2931-
"warning")
2936+
"warning",
2937+
logger)
29322938
else:
29332939
# Set baseline cost and performance characteristics for any
29342940
# remaining secondary microsegments to that of the measure
@@ -3167,7 +3173,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
31673173
f"ECM '{self.name}' has baseline or measure "
31683174
"performance of zero; baseline and measure "
31693175
"performance set equal",
3170-
"warning")
3176+
"warning",
3177+
logger)
31713178
# Ensure that the adjusted relative savings
31723179
# fraction is not greater than 1 or less
31733180
# than 0 if not originally specified as
@@ -3220,7 +3227,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
32203227
opts.verbose,
32213228
f"ECM '{self.name}' has measure performance of zero; "
32223229
"baseline and measure performance set equal",
3223-
"warning")
3230+
"warning",
3231+
logger)
32243232
rel_perf[yr] = 1
32253233
# Ensure that relative performance is a finite
32263234
# number; if not, set to 1
@@ -3240,7 +3248,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
32403248
opts.verbose,
32413249
f"ECM '{self.name}' has baseline performance of zero; "
32423250
"baseline and measure performance set equal",
3243-
"warning")
3251+
"warning",
3252+
logger)
32443253
rel_perf[yr] = 1
32453254

32463255
# If looping through a commercial lighting microsegment
@@ -3500,7 +3509,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
35003509
f"ECM '{self.name}' missing valid consumer choice "
35013510
f"data for end use '{str(mskeys[4])}'; using default "
35023511
"choice data for refrigeration end use",
3503-
"warning")
3512+
"warning",
3513+
logger)
35043514
choice_params = {
35053515
"b1": {
35063516
key: self.handyvars.deflt_choice[0] for
@@ -3552,7 +3562,8 @@ def fill_mkts(self, msegs, msegs_cpl, convert_data, tsv_data_init, opts,
35523562
f"ECM '{self.name}' missing valid consumer choice data for "
35533563
f"end use '{str(mskeys[4])}'; using default choice data for "
35543564
"refrigeration end use",
3555-
"warning")
3565+
"warning",
3566+
logger)
35563567
choice_params = {"rate distribution":
35573568
self.handyvars.com_timeprefs[
35583569
"distributions"][
@@ -5273,7 +5284,8 @@ def apply_tsv(self, load_fact, ash_cz_wts, eplus_bldg_wts,
52735284
"check that 8760 hourly savings fractions are available "
52745285
"for all baseline market segments the measure applies to "
52755286
f"in {self.handyfiles.tsv_shape_data}.",
5276-
"warning")
5287+
"warning",
5288+
logger)
52775289

52785290
else:
52795291
# Develop an adjustment from the generic
@@ -5882,7 +5894,7 @@ def convert_costs(self, convert_data, bldg_sect, mskeys, cost_meas,
58825894
user_message += " for building type '" + mskeys[2] + "'"
58835895

58845896
# Print user message
5885-
fmt.verboseprint(verbose, user_message, "info")
5897+
fmt.verboseprint(verbose, user_message, "info", logger)
58865898
# Case where cost conversion has not succeeded
58875899
else:
58885900
raise ValueError(
@@ -6257,7 +6269,8 @@ def partition_microsegment(
62576269
f"No data available to link mseg {str(mskeys)} for measure '{self.name}' "
62586270
f"with {self.linked_htcl_tover_anchor_tech} "
62596271
f"{self.linked_htcl_tover_anchor_eu} turnover rates; unlinking turnover",
6260-
"warning")
6272+
"warning",
6273+
logger)
62616274
# In cases where no secondary heating/cooling microsegment is present,
62626275
# and there are no linked stock turnover rates for primary heating and
62636276
# cooling microsegments, set relevant adjustment variables to None
@@ -9207,7 +9220,7 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts,
92079220
# Create a shorthand for baseline and efficient stock/energy/carbon/
92089221
# cost data to add to the breakout dict
92099222
base_data = [add_stock_total, add_energy_total,
9210-
add_energy_cost, add_carb_total]
9223+
add_energy_cost, add_carb_total]
92119224
eff_data = [add_stock_total_meas, add_energy_total_eff,
92129225
add_energy_cost_eff, add_carb_total_eff]
92139226

@@ -9466,7 +9479,8 @@ def breakout_mseg(self, mskeys, contrib_mseg_key, adopt_scheme, opts,
94669479
opts.verbose,
94679480
f"Baseline market key chain: '{str(mskeys)}' for ECM '{self.name}' does not map to "
94689481
"output breakout categories, thus will not be reflected in output breakout data",
9469-
"warning")
9482+
"warning",
9483+
logger)
94709484

94719485

94729486
class MeasurePackage(Measure):
@@ -11844,14 +11858,6 @@ def prepare_measures(measures, convert_data, msegs, msegs_cpl, handyvars,
1184411858
base_dir, handyvars, handyfiles, opts_dict, **m) for m in measures]
1184511859
logger.info("Measure initialization complete")
1184611860

11847-
print('Initializing measures...', end="", flush=True)
11848-
# Translate user options to a dictionary for further use in Measures
11849-
opts_dict = vars(opts)
11850-
# Initialize Measure() objects based on 'measures_update' list
11851-
meas_update_objs = [Measure(
11852-
base_dir, handyvars, handyfiles, opts_dict, **m) for m in measures]
11853-
print("Complete")
11854-
1185511861
# Fill in EnergyPlus-based performance information for Measure objects
1185611862
# with a 'From EnergyPlus' flag in their 'energy_efficiency' attribute
1185711863

scout/ecm_prep_vars.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,7 @@ def append_keyvals(self, dict1, keyval_list):
14941494

14951495
return keyval_list
14961496

1497+
14971498
class UsefulInputFiles(object):
14981499
"""Class of input file paths to be used by this routine.
14991500

scout/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5365,7 +5365,7 @@ def main(opts: argparse.NameSpace): # noqa: F821
53655365
# Reset measure fuel split attribute to imported values
53665366
m.eff_fs_splt = meas_eff_fs_data
53675367
# Print data import message for each ECM if in verbose mode
5368-
fmt.verboseprint(opts.verbose, f"Imported ECM {m.name} competition data")
5368+
fmt.verboseprint(opts.verbose, f"Imported ECM {m.name} competition data", "info")
53695369

53705370
# Import total absolute heating and cooling energy use data, used in
53715371
# removing overlaps between supply-side and demand-side heating/cooling

scout/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import numpy
3+
import logging
34
from pathlib import Path, PurePath
45

56

@@ -58,15 +59,18 @@ def custom_showwarning(message, category, filename, lineno, file=None, line=None
5859
print(message)
5960

6061
@staticmethod
61-
def verboseprint(verbose, msg, log_type):
62+
def verboseprint(verbose, msg, log_type, logger=None):
6263
"""Print input message when the code is run in verbose mode.
6364
6465
Args:
6566
verbose (boolean): Indicator of verbose mode
6667
msg (string): Message to print to console when in verbose mode
68+
logger: Logger instance to use for logging
6769
"""
6870
if not verbose:
6971
return
72+
if not logger:
73+
logger = logging.getLogger(__name__)
7074

7175
if log_type == "info":
7276
logger.info(msg)

0 commit comments

Comments
 (0)