Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/config_readable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ ecm_prep:
are {energy, power, null}. Default null
verbose: (boolean) If true, enable verbose mode. Default False
run:
change_yr_interval: (integer) Change reporting to every N years,
where N is the integer specified in this argument. Default
null
mkt_fracs: (boolean) If true, flag market penetration outputs.
Default False
report_cfs: (boolean) If true, report competition adjustment
Expand All @@ -162,7 +165,7 @@ run:
configuration file (.yml) or the command line path, depending
on where the argument is assigned. If not provided, ./results
will be used. Default null
trim_results: (boolean) If true, reduce results file size. Default
False
trim_vars: (boolean) If true, a reduced set of only essential
variables is reported. Default False
verbose: (boolean) If true, print all warnings to stdout. Default
False
2 changes: 1 addition & 1 deletion inputs/config_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ run:
results_directory: null
verbose: false
mkt_fracs: false
trim_results: false
trim_results: null
report_stk: false
report_cfs: false
69 changes: 45 additions & 24 deletions scout/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5093,6 +5093,33 @@ def out_break_walk_subtr(self, orig_dict, base_val, eff_val, focus_yrs):
return orig_dict


def gen_trim_yrs(yr_interval, yr_range):
"""
Generates a list of years that occur every N years within a given range.

Args:
yr_interval: A user-specified string indicating desired year interval.
yr_range: The full range of years in the projection horizon.

Returns:
A list of integers representing the starting year plus any year after that
which is exactly divisible by the desired interval.
"""
# Set start and end year based on AEO range
start_yr, end_yr = [int(yr_range[0]), int(yr_range[-1])]
# Always include the start year in the final list
years = [start_yr]
# Generate the list of years
for year in range(start_yr + 1, end_yr + 1):
# Year must be exactly divisible by desired year interval
if year % yr_interval == 0:
years.append(year)
# Ensure that the final year of the horizon is in the list
if end_yr not in years:
years.append(end_yr)
return years


def measure_opts_match(option_dicts: list[dict]) -> bool:
"""Checks if a list of measure options have common argument values, excluding those that
do not influence final results
Expand Down Expand Up @@ -5141,31 +5168,25 @@ def main(opts: argparse.NameSpace): # noqa: F821
# Instantiate useful variables object
handyvars = UsefulVars(handyfiles)

# If a user desires trimmed down results, collect information about whether
# they want to restrict to certain years of focus
if opts.trim_results is True:
# Flag trimmed results format
# User desires trimmed down variable reporting
if opts.trim_vars:
trim_out = True
trim_yrs = []
while trim_yrs is not False and ((len(trim_yrs) == 0) or any([
x < int(handyvars.aeo_years[0]) or x > int(handyvars.aeo_years[-1])
for x in trim_yrs])):
# Initialize focus year range input
trim_yrs_init = input(
"Enter years of focus for the outputs, with a space in "
"between each (or hit return to use all years): ")
# Finalize focus year range input; if not provided, assume False
if trim_yrs_init:
trim_yrs = list(map(int, trim_yrs_init.split()))
if any([x < int(handyvars.aeo_years[0]) or
x > int(handyvars.aeo_years[-1]) for x in trim_yrs]):
print('Please try again. Enter focus years between '
+ handyvars.aeo_years[0] + ' and ' +
handyvars.aeo_years[-1])
else:
trim_yrs = False
else:
trim_out, trim_yrs = (False for n in range(2))
trim_out = False
# User desires trimmed down year intervals
if opts.change_yr_interval not in [None, 1]:
# Check length of AEO years
aeo_len = len(handyvars.aeo_years)
# Ensure length of year reporting interval doesnt exceed the full length of time horizon
if opts.change_yr_interval > aeo_len:
opts.change_yr_interval = aeo_len
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the desired behavior here? If selecting years based on if year % yr_interval == 0:, then setting to aeo_len could output 2025 and 2028 (divisible by 26), which is probably not what anyone wants. should you instead output just the first year and the last year? That could be done by not calling gen_trim_yrs if this is true, and instead just setting trim_yrs directly

# Notify user of the change
warnings.warn(
"'trim_yrs' user option exceeds length of time horizon. Resetting to the "
"time horizon length of " + str(aeo_len) + " years")
trim_yrs = gen_trim_yrs(opts.change_yr_interval, handyvars.aeo_years)
else:
trim_yrs = False

# Import measure files
with open(handyfiles.meas_summary_data, 'r') as mjs:
Expand Down Expand Up @@ -5575,7 +5596,7 @@ def round_values(data, precision):

# Do not plot for the case where a user has trimmed down the results
# (not all data required for the plots will be available)
if opts.trim_results is False:
if all([x is False for x in [trim_out, trim_yrs]]):
# Notify user that the output data are being plotted
print("Plotting output data...", end="", flush=True)
# Execute plots
Expand Down
8 changes: 6 additions & 2 deletions scout/supporting_data/config_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,14 @@ properties:
type: boolean
default: false
description: If true, flag market penetration outputs.
trim_results:
change_yr_interval:
type: ["integer", "null"]
default: null
description: Change reporting to every N years, where N is the integer specified in this argument.
trim_vars:
type: boolean
default: false
description: If true, reduce results file size.
description: If true, a reduced set of only essential variables is reported.
report_stk:
type: boolean
default: false
Expand Down
6 changes: 4 additions & 2 deletions tests/arguments_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class TestConfig(unittest.TestCase, Utils):
"results_directory": None,
"verbose": False,
"mkt_fracs": False,
"trim_results": False,
"trim_vars": False,
"change_yr_interval": None,
"report_stk": False,
"report_cfs": False,
},
Expand Down Expand Up @@ -144,7 +145,8 @@ class TestConfig(unittest.TestCase, Utils):
},
"run": {"results_directory": "results/test_dir",
"mkt_fracs": True,
"trim_results": True},
"trim_vars": False,
"change_yr_interval": None},
}

def tearDown(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_files/batch_files/config1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ run:
results_directory: ../../../results/custom_dir_config1
verbose: false
mkt_fracs: false
trim_results: false
trim_vars: false
change_yr_interval: null
report_stk: false
report_cfs: false
3 changes: 2 additions & 1 deletion tests/test_files/batch_files/config2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ecm_prep:
run:
verbose: false
mkt_fracs: false
trim_results: false
trim_vars: false
change_yr_interval: null
report_stk: false
report_cfs: false
3 changes: 2 additions & 1 deletion tests/test_files/batch_files/config3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ecm_prep:
run:
verbose: false
mkt_fracs: false
trim_results: false
trim_vars: false
change_yr_interval: null
report_stk: false
report_cfs: false
3 changes: 2 additions & 1 deletion tests/test_files/valid_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ ecm_prep:
run:
results_directory: ../../results/test_dir
mkt_fracs: true
trim_results: true
trim_vars: false
change_yr_interval: null
Loading