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

Landan t/hvac chart post processing update #191

Open
wants to merge 20 commits 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
350,202 changes: 201 additions & 350,001 deletions national/housing_characteristics/buildstock.csv

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions postprocessing/compare_comstock_to_cbecs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import logging

import comstockpostproc as cspp

logging.basicConfig(level='INFO') # Use DEBUG, INFO, or WARNING
logger = logging.getLogger(__name__)

def main():
# ComStock run
comstock = cspp.ComStock(
s3_base_dir='eulp/euss_com', # If run not on S3, download results_up**.parquet manually
comstock_run_name='lower_sat_stpt_10k_v3', # Name of the run on S3
comstock_run_version='lower_sat_stpt_10k_v3', # Use whatever you want to see in plot and folder names
comstock_year=2018, # Typically don't change this
athena_table_name= None, # Typically same as comstock_run_name or None
truth_data_version='v01', # Typically don't change this
buildstock_csv_name='buildstock.csv', # Download buildstock.csv manually
acceptable_failure_percentage=0.2, # Can increase this when testing and high failure are OK
drop_failed_runs=True, # False if you want to evaluate which runs failed in raw output data
color_hex='#0072B2', # Color used to represent this run in plots
skip_missing_columns=True, # False if you want to ensure you have all data specified for exportb
reload_from_csv=False, # True if CSV already made and want faster reload times
include_upgrades=True, # False if not looking at upgrades
upgrade_ids_to_skip=[] # Use [1, 3] etc. to exclude certain upgrades
)

# CBECS
cbecs = cspp.CBECS(
cbecs_year=2012, # 2012 and 2018 currently available
truth_data_version='v01', # Typically don't change this
color_hex='#009E73', # Color used to represent CBECS in plots
reload_from_csv=False # True if CSV already made and want faster reload times
)

# From Feburary 2024 EUSS Full Run
national_scaling_factors = {
'Hospital': 7.40279973438571,
'SecondarySchool': 7.61402397003761,
'Outpatient': 4.08817512805358,
'LargeHotel': 9.52500448561723,
'FullServiceRestaurant': 7.56685751697572,
'RetailStripmall': 1.87065215852945,
'RetailStandalone': 3.20458438519356,
'PrimarySchool': 9.72943522508755,
'QuickServiceRestaurant': 8.53126424238864,
'SmallOffice': 8.72605822017302,
'SmallHotel': 3.3063363735822,
'MediumOffice': 9.32502232347711,
'LargeOffice': 5.75996046109096,
'Warehouse': 3.23792487389949
}

# Scale ComStock run to CBECS 2018 AND remove non-ComStock buildings from CBECS
comstock.add_national_scaling_weights(cbecs, remove_non_comstock_bldg_types_from_cbecs=True, use_hard_coded_scaling_weights=False, scaling_factors=national_scaling_factors)
comstock.export_to_csv_wide()

# Make a comparison by passing in a list of CBECs and ComStock runs to compare
# upgrade_id can be 'All' or the upgrade number
comp = cspp.ComStockToCBECSComparison(cbecs_list=[cbecs], comstock_list=[comstock], upgrade_id='All',make_comparison_plots=True, make_hvac_plots=True)

comp.export_to_csv_wide()

# Code to execute the script
if __name__ == "__main__":
main()
45 changes: 37 additions & 8 deletions postprocessing/compare_comstock_to_cbecs.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ def main():
# ComStock run
comstock = cspp.ComStock(
s3_base_dir='eulp/euss_com', # If run not on S3, download results_up**.parquet manually
comstock_run_name='baseline_vav_mdp_adjust2', # Name of the run on S3
comstock_run_version='baseline_vav_mdp_adjust2', # Use whatever you want to see in plot and folder names
comstock_run_name='lower_sat_stpt_10k_v3', # Name of the run on S3
comstock_run_version='lower_sat_stpt_10k_v3', # Use whatever you want to see in plot and folder names
comstock_year=2018, # Typically don't change this
athena_table_name='baseline_vav_mdp_adjust2', # Typically same as comstock_run_name or None
athena_table_name='lower_sat_stpt_10k_v3', # Typically same as comstock_run_name or None
truth_data_version='v01', # Typically don't change this
buildstock_csv_name='buildstock.csv', # Download buildstock.csv manually
acceptable_failure_percentage=0.9, # Can increase this when testing and high failure are OK
drop_failed_runs=True, # False if you want to evaluate which runs failed in raw output data
color_hex='#0072B2', # Color used to represent this run in plots
skip_missing_columns=True, # False if you want to ensure you have all data specified for exportb
reload_from_csv=False, # True if CSV already made and want faster reload times
include_upgrades=False, # False if not looking at upgrades
include_upgrades=True, # False if not looking at upgrades
upgrade_ids_to_skip=[] # Use [1, 3] etc. to exclude certain upgrades
)

# CBECS
cbecs = cspp.CBECS(
cbecs_year=2018, # 2012 and 2018 currently available
Expand All @@ -35,16 +35,45 @@ def main():
reload_from_csv=False # True if CSV already made and want faster reload times
)

# From Feburary 2024 EUSS Full Run
national_scaling_factors = {
'Hospital': 7.40279973438571,
'SecondarySchool': 7.61402397003761,
'Outpatient': 4.08817512805358,
'LargeHotel': 9.52500448561723,
'FullServiceRestaurant': 7.56685751697572,
'RetailStripmall': 1.87065215852945,
'RetailStandalone': 3.20458438519356,
'PrimarySchool': 9.72943522508755,
'QuickServiceRestaurant': 8.53126424238864,
'SmallOffice': 8.72605822017302,
'SmallHotel': 3.3063363735822,
'MediumOffice': 9.32502232347711,
'LargeOffice': 5.75996046109096,
'Warehouse': 3.23792487389949
}

# Scale ComStock run to CBECS 2018 AND remove non-ComStock buildings from CBECS
comstock.add_national_scaling_weights(cbecs, remove_non_comstock_bldg_types_from_cbecs=True)
comstock.add_national_scaling_weights(cbecs, remove_non_comstock_bldg_types_from_cbecs=True,
use_hard_coded_scaling_weights=False, #Typically use False. True utilizes the scaling factors above for runs that might not be accurately scaled.
scaling_factors=national_scaling_factors)

comstock.export_to_csv_wide()

# Make a comparison by passing in a list of CBECs and ComStock runs to compare
# upgrade_id can be 'All' or the upgrade number
comp = cspp.ComStockToCBECSComparison(cbecs_list=[cbecs], comstock_list=[comstock], upgrade_id='All',make_comparison_plots=True)
# TODO - add a way to call HVAC plots or not. Remove once HVAC.SYS types are available for CBECS 2018
comp = cspp.ComStockToCBECSComparison(cbecs_list=[cbecs],
comstock_list=[comstock],
upgrade_id='All',
make_comparison_plots=True,
make_hvac_plots=False) #Only works with CBECS 2012

# HVAC plots only work for CBECS 2012 TODO - remove this once HVAC.SYS types are available for CBECS 2018


comp.export_to_csv_wide()

# Code to execute the script
if __name__ == "__main__":
main()
54 changes: 54 additions & 0 deletions postprocessing/compare_upgrades.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import logging

import comstockpostproc as cspp


logging.basicConfig(level='INFO') # Use DEBUG, INFO, or WARNING
logger = logging.getLogger(__name__)

def main():
# ComStock run
comstock = cspp.ComStock(
s3_base_dir='eulp/euss_com', # If run not on S3, download results_up**.parquet manually
comstock_run_name='baseline_vav_mdp_adjust5', # Name of the run on S3
comstock_run_version='baseline_vav_mdp_adjust5', # Use whatever you want to see in plot and folder names
comstock_year=2018, # Typically don't change this
athena_table_name=None, # Typically don't change this
truth_data_version='v01', # Typically don't change this
buildstock_csv_name='buildstock.csv', # Download buildstock.csv manually
acceptable_failure_percentage=0.025, # Can increase this when testing and high failure are OK
drop_failed_runs=True, # False if you want to evaluate which runs failed in raw output data
color_hex='#0072B2', # Color used to represent this run in plots
skip_missing_columns=True, # False if you want to ensure you have all data specified for export
reload_from_csv=False, # True if CSV already made and want faster reload times
include_upgrades=True, # False if not looking at upgrades
upgrade_ids_to_skip=[], # Use [1, 3] etc. to exclude certain upgrades
upgrade_ids_for_comparison={} # Use {'<Name you want for comparison run folder>':[0,1,2]}; add as many upgrade IDs as needed, but plots look strange over 5
)

# CBECS
cbecs = cspp.CBECS(
cbecs_year=2018, # 2012 and 2018 currently available
truth_data_version='v01', # Typically don't change this
color_hex='#009E73', # Color used to represent CBECS in plots
reload_from_csv=False # True if CSV already made and want faster reload times
)

# Scale ComStock run to CBECS 2018 AND remove non-ComStock buildings from CBECS
# This is how weights in the models are set to represent national energy consumption
comstock.add_national_scaling_weights(cbecs, remove_non_comstock_bldg_types_from_cbecs=True)

# Export CBECS and ComStock data to wide and long formats for Tableau and to skip processing later
cbecs.export_to_csv_wide() # May comment this out after run once
comstock.export_to_csv_wide() # May comment this out after run once
# comstock.export_to_csv_long() # Long format useful for stacking end uses and fuels

# Create measure run comparisons; only use if run has measures
comparison = cspp.ComStockMeasureComparison(comstock, make_comparison_plots=True)

# Code to execute the script
if __name__=="__main__":
main()
6 changes: 3 additions & 3 deletions postprocessing/compare_upgrades.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ logger = logging.getLogger(__name__)
def main():
# ComStock run
comstock = cspp.ComStock(
s3_base_dir='eulp/comstock_fy22', # If run not on S3, download results_up**.parquet manually
comstock_run_name='os_340_transition_10k_3', # Name of the run on S3
comstock_run_version='os_340_transition_10k_3', # Use whatever you want to see in plot and folder names
s3_base_dir='eulp/euss_comm', # If run not on S3, download results_up**.parquet manually
comstock_run_name='baseline_vav_mdp_v4', # Name of the run on S3
comstock_run_version='baseline_vav_mdp_v4', # Use whatever you want to see in plot and folder names
comstock_year=2018, # Typically don't change this
athena_table_name=None, # Typically don't change this
truth_data_version='v01', # Typically don't change this
Expand Down
31 changes: 29 additions & 2 deletions postprocessing/comstockpostproc/cbecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def __init__(self, cbecs_year, truth_data_version, color_hex=NamingMixin.COLOR_C
self.add_energy_rate_columns()
# Calculate weighted area and energy consumption columns
self.add_weighted_area_and_energy_columns()
#TODO remove if statement and add HVAC systems types once they are avialable in CBECS 2018 data
if cbecs_year == 2012:
# Add comstock primary hvac system type
self.add_primary_system_type_column()

logger.debug('\nCBECS columns after adding all data')
for c in self.data.columns:
Expand All @@ -96,7 +100,7 @@ def download_data(self):
if not os.path.exists(file_path):
s3_file_path = f'truth_data/{self.truth_data_version}/EIA/CBECS/{file_name}'
self.read_delimited_truth_data_file_from_S3(s3_file_path, ',')


def load_data(self):
# Load raw microdata and codebook and decode numeric keys to strings using codebook
Expand Down Expand Up @@ -470,9 +474,32 @@ def add_weighted_area_and_energy_columns(self):
new_col_dict[new_col] = self.data[col] * self.data[self.BLDG_WEIGHT] * conv_fact
self.data = pd.concat([self.data, pd.DataFrame(new_col_dict)], axis=1)

def add_primary_system_type_column(self):
# CBECS HVAC Data
file_name = f'cbecs_{self.year}_w_cstock_hvac_v3.csv'
file_path = os.path.join(self.truth_data_dir, file_name)

# Check if file exists
if not os.path.exists(file_path):
print(f"File {file_name} does not exist. Skipping...")
return

# Read CSV file into a DataFrame
hvac_df = pd.read_csv(file_path)

# Select 'PUBID' and 'cstock_sys_type' columns
hvac_df = hvac_df[['PUBID', 'cstock_sys_type']]

# Rename 'PUBID' to 'bldg_id'
hvac_df = hvac_df.rename(columns={'PUBID': 'bldg_id'})
hvac_df = hvac_df.rename(columns={'cstock_sys_type':'in.hvac_system_type'})

# Merge HVAC data with existing data
self.data = pd.merge(self.data, hvac_df, on='bldg_id', how='left')

def export_to_csv_wide(self):
# Exports comstock data to CSV in wide format

file_name = f'CBECS wide.csv'
file_path = os.path.join(self.output_dir, file_name)
self.data.to_csv(file_path, index=False)
self.data.to_csv(file_path, index=False)
Loading