Skip to content
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

Fixes 'reload from csv' function, and a bug in plotting when measure … #256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
5 changes: 3 additions & 2 deletions postprocessing/comstockpostproc/comstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ def __init__(self, s3_base_dir, comstock_run_name, comstock_run_version, comstoc
self.download_data()
pl.enable_string_cache()
if reload_from_csv:
upgrade_pqts = glob.glob(os.path.join(self.output_dir, 'ComStock wide upgrade*.parquet'))
upgrade_pqts = glob.glob(os.path.join(self.output_dir, 'cached_ComStock_wide_upgrade*.parquet'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, we should avoid using \\ in the whole file name...

print(f"DEBUG*****: #{upgrade_pqts} ")
upgrade_pqts.sort()
if len(upgrade_pqts) > 0:
upgrade_dfs = []
for file_path in upgrade_pqts:
bn = os.path.basename(file_path)
up_id = int(bn.replace('ComStock wide upgrade', '').replace('.parquet', ''))
up_id = int(bn.replace('cached_ComStock_wide_upgrade', '').replace('.parquet', ''))
if up_id in self.upgrade_ids_to_skip:
logger.info(f'Skipping reload for upgrade {up_id}')
continue
Expand Down
65 changes: 46 additions & 19 deletions postprocessing/comstockpostproc/plotting_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def plot_energy_by_enduse_and_fuel_type(self, df, column_for_grouping, color_map
# figure name and save
fig_name = f'{title.replace(" ", "_").lower()}_{applicable_scenario}.{self.image_type}'
fig_name_html = f'{title.replace(" ", "_").lower()}_{applicable_scenario}.html'
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
Expand Down Expand Up @@ -265,16 +266,15 @@ def plot_emissions_by_fuel_type(self, df, column_for_grouping, color_map, output
# Adjust spacing between subplots and reduce white space
plt.subplots_adjust(wspace=0.2, hspace=0.2, bottom=0.15)
# figure name and save
title=f"GHG_emissions_{order_map[1]}"
title=f"GHG_emissions"
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
plt.savefig(fig_path, dpi=600, bbox_inches = 'tight')



# plot for GHG emissions by fuel type for baseline and upgrade
def plot_utility_bills_by_fuel_type(self, df, column_for_grouping, color_map, output_dir):

Expand Down Expand Up @@ -403,9 +403,10 @@ def plot_utility_bills_by_fuel_type(self, df, column_for_grouping, color_map, ou
# Adjust spacing between subplots and reduce white space
plt.subplots_adjust(wspace=0.25, hspace=0.2, bottom=0.15)
# figure name and save
title=f"Utility_Bills_{order_map[1]}"
title=f"Utility_Bills"
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_sub_dir = os.path.join(output_dir)
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.join(fig_sub_dir, fig_name)
Expand Down Expand Up @@ -494,7 +495,9 @@ def plot_annual_emissions_comparison(self, df, column_for_grouping, color_map, o
# Save figure
title = title.replace('\n', '')
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_path = os.path.abspath(os.path.join(output_dir, fig_name))
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
plt.savefig(fig_path, bbox_inches = 'tight')
plt.close()

Expand Down Expand Up @@ -587,7 +590,9 @@ def plot_floor_area_and_energy_totals(self, df, column_for_grouping, color_map,
title = title.replace('\n', '')
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace('_total_energy_consumption', '')
fig_path = os.path.abspath(os.path.join(output_dir, fig_name))
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
plt.savefig(fig_path, bbox_inches = 'tight')
plt.close()

Expand Down Expand Up @@ -686,7 +691,9 @@ def plot_eui_boxplots(self, df, column_for_grouping, color_map, output_dir):
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace('boxplot_of_', 'bp_')
fig_name = fig_name.replace('total_energy_consumption_', '')
fig_path = os.path.abspath(os.path.join(output_dir, fig_name))
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
plt.savefig(fig_path, bbox_inches = 'tight')
plt.close()

Expand Down Expand Up @@ -783,14 +790,16 @@ def plot_energy_rate_boxplots(self, df, column_for_grouping, color_map, output_d
title = title.replace('\n', '')
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace('boxplot_of_', 'bp_')
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
# fig_name = fig_name.replace('total_energy_consumption_', '')
fig_path = os.path.abspath(os.path.join(output_dir, fig_name))
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
plt.savefig(fig_path, bbox_inches = 'tight')
plt.close()

def plot_floor_area_and_energy_totals_by_building_type(self, df, column_for_grouping, color_map, output_dir):
# Summarize square footage and energy totals by building type

# Columns to summarize
cols_to_summarize = {
self.col_name_to_weighted(self.FLR_AREA): np.sum,
Expand Down Expand Up @@ -877,6 +886,7 @@ def plot_floor_area_and_energy_totals_by_building_type(self, df, column_for_grou
title = title.replace('\n', '')
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace('_total_energy_consumption', '')
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, bldg_type))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
Expand Down Expand Up @@ -962,6 +972,7 @@ def plot_end_use_totals_by_building_type(self, df, column_for_grouping, color_ma
# Save figure
title = title.replace('\n', '')
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, bldg_type))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
Expand Down Expand Up @@ -1048,6 +1059,7 @@ def plot_eui_histograms_by_building_type(self, df, column_for_grouping, color_ma
title = title.replace('\n', '')
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace('distribution_of_', 'dist_')
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, bldg_type))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
Expand Down Expand Up @@ -1153,6 +1165,7 @@ def plot_eui_boxplots_by_building_type(self, df, column_for_grouping, color_map,
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace('boxplot_of_', 'bp_')
fig_name = fig_name.replace('total_energy_consumption_', '')
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, bldg_type))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
Expand Down Expand Up @@ -1247,7 +1260,8 @@ def plot_measure_savings_distributions_by_building_type(self, df, output_dir):
fig.update_yaxes(mirror=True, showgrid=True, type='category', dtick=1)
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace('_total_energy_consumption', '')
fig_sub_dir = os.path.abspath(os.path.join(output_dir, 'savings_distributions'))
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(os.path.join(output_dir), 'savings_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
Expand Down Expand Up @@ -1339,7 +1353,8 @@ def plot_measure_utility_savings_distributions_by_building_type(self, df, output
fig.update_yaxes(mirror=True, showgrid=True, type='category', dtick=1)
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace(r'_(usd/sqft/year,', '')
fig_sub_dir = os.path.join(output_dir, 'savings_distributions')
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(os.path.join(output_dir), 'savings_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.join(fig_sub_dir, fig_name)
Expand Down Expand Up @@ -1431,7 +1446,8 @@ def plot_measure_utility_savings_distributions_by_climate_zone(self, df, output_
fig.update_yaxes(mirror=True, showgrid=True, type='category', dtick=1)
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace(r'_(usd/sqft/year,', '')
fig_sub_dir = os.path.join(output_dir, 'savings_distributions')
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(os.path.join(output_dir), 'savings_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.join(fig_sub_dir, fig_name)
Expand Down Expand Up @@ -1523,7 +1539,8 @@ def plot_measure_utility_savings_distributions_by_hvac_system(self, df, output_d
fig.update_yaxes(mirror=True, showgrid=True, type='category', dtick=1)
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace(r'_(usd/sqft/year,', '')
fig_sub_dir = os.path.join(output_dir, 'savings_distributions')
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(os.path.join(output_dir), 'savings_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.join(fig_sub_dir, fig_name)
Expand Down Expand Up @@ -1617,7 +1634,8 @@ def plot_measure_savings_distributions_by_climate_zone(self, df, output_dir):
fig.update_xaxes(mirror=True, showgrid=True, zeroline=True, nticks=16, title=group_name)
fig.update_yaxes(mirror=True, showgrid=True, type='category', dtick=1)
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_sub_dir = os.path.abspath(os.path.join(output_dir, 'savings_distributions'))
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(os.path.join(output_dir), 'savings_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
Expand Down Expand Up @@ -1711,7 +1729,8 @@ def plot_measure_savings_distributions_by_hvac_system_type(self, df, output_dir)
fig.update_xaxes(mirror=True, showgrid=True, zeroline=True, nticks=16, title=group_name, automargin=True)
fig.update_yaxes(mirror=True, showgrid=True, nticks=len(li_group), type='category', dtick=1, automargin=True)
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_sub_dir = os.path.abspath(os.path.join(output_dir, 'savings_distributions'))
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(os.path.join(output_dir), 'savings_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
Expand Down Expand Up @@ -1803,7 +1822,9 @@ def plot_measure_savings_distributions_enduse_and_fuel(self, df, output_dir):
fig.update_xaxes(mirror=True, showgrid=True, zeroline=True, nticks=16, title=savings_name)
fig.update_yaxes(mirror=True, showgrid=True, nticks=len(li_pct_svgs_enduse_cols), type='category', dtick=1)
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, 'savings_distributions'))
print(f"fig_sub_dir: #{fig_sub_dir}")
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
Expand Down Expand Up @@ -1898,7 +1919,8 @@ def plot_measure_utility_savings_distributions_by_fuel(self, df, output_dir):
fig.update_yaxes(mirror=True, showgrid=True, nticks=len(li_pct_svgs_fuel_cols), type='category', dtick=1)
fig_name = f'{title.replace(" ", "_").lower()}.{self.image_type}'
fig_name = fig_name.replace(r'_(usd/sqft/year,', '')
fig_sub_dir = os.path.join(output_dir, 'savings_distributions')
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, 'savings_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
fig_path = os.path.join(fig_sub_dir, fig_name)
Expand Down Expand Up @@ -1937,6 +1959,7 @@ def plot_qoi_timing(self, df, column_for_grouping, color_map, output_dir):
margin=dict(l=5, r=5, t=5, b=5),
)
fig_name = f'{title}.{self.image_type}'
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, 'qoi_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
Expand Down Expand Up @@ -1973,6 +1996,7 @@ def plot_qoi_max_use(self, df, column_for_grouping, color_map, output_dir):
margin=dict(l=5, r=5, t=5, b=5),
)
fig_name = f'{title}.{self.image_type}'
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, 'qoi_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
Expand Down Expand Up @@ -2009,6 +2033,7 @@ def plot_qoi_min_use(self, df, column_for_grouping, color_map, output_dir):
margin=dict(l=5, r=5, t=5, b=5),
)
fig_name = f'{title}.{self.image_type}'
output_dir = output_dir.strip()
fig_sub_dir = os.path.abspath(os.path.join(output_dir, 'qoi_distributions'))
if not os.path.exists(fig_sub_dir):
os.makedirs(fig_sub_dir)
Expand Down Expand Up @@ -2116,7 +2141,8 @@ def plot_annual_energy_consumption_for_eia(self, df, color_map, output_dir):
# Save the figure
title = title.replace('\n', '')
fig_name = f'com_eia_{title.replace(" ", "_").lower()}.{self.image_type}'
fig_path = os.path.abspath(os.path.join(output_dir, fig_name))
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
plt.savefig(fig_path, bbox_inches = 'tight')
plt.close()

Expand Down Expand Up @@ -2179,7 +2205,8 @@ def plot_monthly_energy_consumption_for_eia(self, df, color_map, output_dir):
# Save the figure
title = title.replace('\n', '')
fig_name = f'com_eia_{title.replace(" ", "_").lower()}.{self.image_type}'
fig_path = os.path.abspath(os.path.join(output_dir, fig_name))
fig_sub_dir = os.path.abspath(os.path.join(output_dir))
fig_path = os.path.abspath(os.path.join(fig_sub_dir, fig_name))
plt.savefig(fig_path, bbox_inches = 'tight')
plt.close()

Expand Down