Skip to content

Commit 2ac15a1

Browse files
authored
Remove summarize_results (#1340)
Will handle summaries differently.
1 parent b2663a2 commit 2ac15a1

File tree

15 files changed

+38
-1060
lines changed

15 files changed

+38
-1060
lines changed

gridpath/auxiliary/import_export_rules.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,70 +31,72 @@ def export_rule_use(instance, quiet):
3131
if unserved_energy_found:
3232
if not quiet:
3333
print("unserved energy found; exporting results")
34-
35-
return unserved_energy_found
36-
37-
38-
def summarize_results_use(
39-
scenario_directory,
40-
weather_iteration,
41-
hydro_iteration,
42-
availability_iteration,
43-
subproblem,
44-
stage,
45-
quiet,
46-
):
47-
if os.path.exists(
48-
os.path.join(
49-
scenario_directory,
50-
weather_iteration,
51-
hydro_iteration,
52-
availability_iteration,
53-
subproblem,
54-
stage,
55-
"results",
56-
"system_load_zone_timepoint.csv",
57-
)
58-
):
59-
return True
6034
else:
6135
if not quiet:
62-
print("skipping results summary")
63-
return False
36+
print("no unserved energy found; skipping results export")
37+
38+
return unserved_energy_found
6439

6540

66-
def import_rule_use(results_directory, quiet):
41+
def sys_lz_tmp_csv_based_rule(results_directory, quiet):
42+
"""
43+
Returns True if the results directory contains a system_load_zone_timepoint.csv file.
44+
"""
6745
if os.path.exists(
6846
os.path.join(results_directory, "system_load_zone_timepoint.csv")
6947
):
7048
import_results = True
7149
if not quiet:
72-
print("unserved energy found -- importing")
50+
print("'system_load_zone_timepoint' found -- processing")
7351
else:
7452
import_results = False
7553
if not quiet:
76-
print("no unserved energy -- skipping")
54+
print("'system_load_zone_timepoint' not found -- skipping")
7755

7856
return import_results
7957

8058

59+
def sys_lz_tmp_csv_based_rule_w_dir_args(
60+
scenario_directory,
61+
weather_iteration,
62+
hydro_iteration,
63+
availability_iteration,
64+
subproblem,
65+
stage,
66+
quiet,
67+
):
68+
results_directory = os.path.join(
69+
scenario_directory,
70+
weather_iteration,
71+
hydro_iteration,
72+
availability_iteration,
73+
subproblem,
74+
stage,
75+
"results",
76+
)
77+
78+
flag = sys_lz_tmp_csv_based_rule(results_directory, quiet)
79+
return flag
80+
81+
82+
# These are high-level rules for whether or not to run each results-side step of
83+
# GridPath_E2E
8184
import_export_rules = {
85+
# Only export results if USE is found; export summaries; summarize
86+
# results and import results only if system_load_zone_timepoint.csv is found
8287
"USE": {
8388
"export": export_rule_use,
8489
"export_summary": True,
85-
"summarize": summarize_results_use,
86-
"import": import_rule_use,
90+
"import": sys_lz_tmp_csv_based_rule,
8791
},
8892
"USE_import_only": {
8993
"export": True,
9094
"export_summary": True,
91-
"summarize": True,
92-
"import": import_rule_use,
95+
"import": sys_lz_tmp_csv_based_rule,
9396
},
9497
"summary_only": {
9598
"export": lambda instance, quiet: False,
9699
"export_summary": lambda instance: True,
97-
"summarize": lambda scenario_directory, weather_iteration, hydro_iteration, availability_iteration, subproblem, stage, quiet,: False,
98100
"import": lambda results_directory, quiet: True,
99101
},
100102
}

gridpath/project/capacity/capacity.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -442,68 +442,3 @@ def export_results(
442442
if column not in getattr(d, PROJECT_PERIOD_DF):
443443
getattr(d, PROJECT_PERIOD_DF)[column] = None
444444
getattr(d, PROJECT_PERIOD_DF).update(optype_df)
445-
446-
447-
def summarize_results(
448-
scenario_directory,
449-
weather_iteration,
450-
hydro_iteration,
451-
availability_iteration,
452-
subproblem,
453-
stage,
454-
skip_quick_summary,
455-
):
456-
"""
457-
:param scenario_directory:
458-
:param subproblem:
459-
:param stage:
460-
:return:
461-
462-
Summarize capacity results
463-
"""
464-
465-
summary_results_file = os.path.join(
466-
scenario_directory,
467-
weather_iteration,
468-
hydro_iteration,
469-
availability_iteration,
470-
subproblem,
471-
stage,
472-
"results",
473-
"summary_results.txt",
474-
)
475-
# Check if the 'technology' exists in projects.tab; if it doesn't, we
476-
# don't have a category to aggregate by, so we'll skip summarizing results
477-
478-
# Open in 'append' mode, so that results already written by other
479-
# modules are not overridden
480-
if not skip_quick_summary:
481-
with open(summary_results_file, "a") as outfile:
482-
outfile.write("\n### CAPACITY RESULTS ###\n")
483-
484-
required_capacity_modules = get_required_subtype_modules(
485-
scenario_directory=scenario_directory,
486-
weather_iteration=weather_iteration,
487-
hydro_iteration=hydro_iteration,
488-
availability_iteration=availability_iteration,
489-
subproblem=subproblem,
490-
stage=stage,
491-
which_type="capacity_type",
492-
)
493-
494-
# Import needed capacity type modules
495-
imported_capacity_modules = load_project_capacity_type_modules(
496-
required_capacity_modules
497-
)
498-
for op_m in required_capacity_modules:
499-
if hasattr(imported_capacity_modules[op_m], "summarize_results"):
500-
imported_capacity_modules[op_m].summarize_results(
501-
scenario_directory,
502-
weather_iteration,
503-
hydro_iteration,
504-
availability_iteration,
505-
subproblem,
506-
stage,
507-
skip_quick_summary,
508-
summary_results_file,
509-
)

gridpath/project/capacity/capacity_types/dr_new.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -472,63 +472,6 @@ def add_to_project_period_results(
472472
return results_columns, captype_df
473473

474474

475-
def summarize_results(
476-
scenario_directory,
477-
weather_iteration,
478-
hydro_iteration,
479-
availability_iteration,
480-
subproblem,
481-
stage,
482-
skip_quick_summary,
483-
summary_results_file,
484-
):
485-
"""
486-
Summarize new DR capacity results.
487-
:param scenario_directory:
488-
:param subproblem:
489-
:param stage:
490-
:param summary_results_file:
491-
:return:
492-
"""
493-
494-
if not skip_quick_summary:
495-
# Get the results CSV as dataframe
496-
capacity_results_agg_df = read_results_file_generic(
497-
scenario_directory=scenario_directory,
498-
weather_iteration=weather_iteration,
499-
hydro_iteration=hydro_iteration,
500-
availability_iteration=availability_iteration,
501-
subproblem=subproblem,
502-
stage=stage,
503-
capacity_type=Path(__file__).stem,
504-
)
505-
506-
# Get all technologies with new build DR power OR energy capacity
507-
new_build_df = pd.DataFrame(
508-
capacity_results_agg_df[
509-
(capacity_results_agg_df["new_build_mw"] > 0)
510-
| (capacity_results_agg_df["new_build_mwh"] > 0)
511-
][["new_build_mw", "new_build_mwh"]]
512-
)
513-
514-
# Get the power and energy units from the units.csv file
515-
power_unit, energy_unit, fuel_unit = get_units(scenario_directory)
516-
517-
# Rename column header
518-
columns = [
519-
"New DR Power Capacity ({})".format(power_unit),
520-
"New DR Energy Capacity ({})".format(energy_unit),
521-
]
522-
523-
write_summary_results_generic(
524-
results_df=new_build_df,
525-
columns=columns,
526-
summary_results_file=summary_results_file,
527-
title="New DR Capacity",
528-
empty_title="No new DR was built.",
529-
)
530-
531-
532475
# Database
533476
###############################################################################
534477

gridpath/project/capacity/capacity_types/energy_new_lin.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -509,59 +509,6 @@ def add_to_project_period_results(
509509
return results_columns, captype_df
510510

511511

512-
def summarize_results(
513-
scenario_directory,
514-
weather_iteration,
515-
hydro_iteration,
516-
availability_iteration,
517-
subproblem,
518-
stage,
519-
skip_quick_summary,
520-
summary_results_file,
521-
):
522-
"""
523-
Summarize new build generation energy results.
524-
:param scenario_directory:
525-
:param subproblem:
526-
:param stage:
527-
:param summary_results_file:
528-
:return:
529-
"""
530-
531-
if not skip_quick_summary:
532-
# Get the results CSV as dataframe
533-
energy_results_agg_df = read_results_file_generic(
534-
scenario_directory=scenario_directory,
535-
weather_iteration=weather_iteration,
536-
hydro_iteration=hydro_iteration,
537-
availability_iteration=availability_iteration,
538-
subproblem=subproblem,
539-
stage=stage,
540-
capacity_type=Path(__file__).stem,
541-
)
542-
543-
# Get all technologies with the new build energy
544-
new_build_df = pd.DataFrame(
545-
energy_results_agg_df[energy_results_agg_df["new_build_energy_mwh"] > 0][
546-
"new_build_energy_mwh"
547-
]
548-
)
549-
550-
# Get the units from the units.csv file
551-
power_unit, energy_unit, fuel_unit = get_units(scenario_directory)
552-
553-
# Rename column header
554-
columns = ["New Energy ({})".format(power_unit)]
555-
556-
write_summary_results_generic(
557-
results_df=new_build_df,
558-
columns=columns,
559-
summary_results_file=summary_results_file,
560-
title="New Energy Procurement",
561-
empty_title="No new energy_new_lin generation was procured.",
562-
)
563-
564-
565512
# Database
566513
###############################################################################
567514

gridpath/project/capacity/capacity_types/fuel_prod_new.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -672,82 +672,6 @@ def add_to_project_period_results(
672672
return results_columns, captype_df
673673

674674

675-
# TODO: add capacity type to the results file, so that we can filter the
676-
# consolidated results file for the summaries
677-
def summarize_results(
678-
scenario_directory,
679-
weather_iteration,
680-
hydro_iteration,
681-
availability_iteration,
682-
subproblem,
683-
stage,
684-
skip_quick_summary,
685-
summary_results_file,
686-
):
687-
"""
688-
Summarize new build storage capacity results.
689-
:param scenario_directory:
690-
:param subproblem:
691-
:param stage:
692-
:param summary_results_file:
693-
:return:
694-
"""
695-
if not skip_quick_summary:
696-
# Get the results CSV as dataframe
697-
capacity_results_agg_df = read_results_file_generic(
698-
scenario_directory=scenario_directory,
699-
weather_iteration=weather_iteration,
700-
hydro_iteration=hydro_iteration,
701-
availability_iteration=availability_iteration,
702-
subproblem=subproblem,
703-
stage=stage,
704-
capacity_type=Path(__file__).stem,
705-
)
706-
707-
# Get all technologies with new build production OR release OR energy capacity
708-
new_build_df = pd.DataFrame(
709-
capacity_results_agg_df[
710-
(capacity_results_agg_df["new_fuel_prod_capacity_fuelunitperhour"] > 0)
711-
| (capacity_results_agg_df["new_fuel_rel_capacity_fuelunitperhour"] > 0)
712-
| (capacity_results_agg_df["new_fuel_stor_capacity_fuelunit"] > 0)
713-
][
714-
[
715-
"new_fuel_prod_capacity_fuelunitperhour",
716-
"new_fuel_rel_capacity_fuelunitperhour",
717-
"new_fuel_stor_capacity_fuelunit",
718-
]
719-
]
720-
)
721-
722-
# Get the units from the units.csv file
723-
power_unit, energy_unit, fuel_unit = get_units(scenario_directory)
724-
725-
# Rename column header
726-
columns = [
727-
"New Fuel Production Capacity ({} per hour)".format(fuel_unit),
728-
"New Fuel Release Capacity ({} per hour)".format(fuel_unit),
729-
"New Fuel Storage Capacity ({})".format(fuel_unit),
730-
]
731-
732-
write_summary_results_generic(
733-
results_df=new_build_df,
734-
columns=columns,
735-
summary_results_file=summary_results_file,
736-
title="New Fuel Production, Release, and Storage Capacity",
737-
empty_title="No new fuel production was built.",
738-
)
739-
740-
with open(summary_results_file, "a") as outfile:
741-
outfile.write(
742-
"\n--> New Fuel Production, Release, and Storage Capacity <--\n"
743-
)
744-
if new_build_df.empty:
745-
outfile.write("No new fuel production was built.\n")
746-
else:
747-
new_build_df.to_string(outfile, float_format="{:,.2f}".format)
748-
outfile.write("\n")
749-
750-
751675
# Database
752676
###############################################################################
753677

0 commit comments

Comments
 (0)