Skip to content

Commit

Permalink
fixing scale
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyikuang committed Jul 23, 2024
1 parent e4ff8f2 commit 3a0c12b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions postprocessing/comstockpostproc/comstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,15 +1820,16 @@ def add_national_scaling_weights(self, cbecs: CBECS, remove_non_comstock_bldg_ty
# Remove CBECS entries for building types not included in the ComStock run
# comstock_bldg_types = self.data[self.BLDG_TYPE].unique()
assert isinstance(self.data, pl.LazyFrame)
comstock_bldg_types: pl.DataFrame = self.data.select(self.BLDG_TYPE).unique().collect()
comstock_bldg_types: set = set(self.data.select(self.BLDG_TYPE).unique().collect().to_pandas()[self.BLDG_TYPE].tolist())

cbecs.data = cbecs.data.collect().to_pandas()
cbecs.data: pd.DataFrame = cbecs.data.collect().to_pandas()
assert isinstance(cbecs.data, pd.DataFrame)
bldg_types_to_keep = [] #if the bldg types in both CBECS and ComStock, keep them.
for bt in cbecs.data[self.BLDG_TYPE].unique():
if bt in comstock_bldg_types:
bldg_types_to_keep.append(bt)


logger.debug("Building types to keep: ", bldg_types_to_keep)
if remove_non_comstock_bldg_types_from_cbecs:
# Modify CBECS to remove building types not covered by ComStock
cbecs.data = cbecs.data[cbecs.data[self.BLDG_TYPE].isin(bldg_types_to_keep)]
Expand All @@ -1843,8 +1844,9 @@ def add_national_scaling_weights(self, cbecs: CBECS, remove_non_comstock_bldg_ty

# Total sqft of each building type, CBECS
wt_area_col = self.col_name_to_weighted(self.FLR_AREA)
cbecsData[wt_area_col] = cbecsData[wt_area_col].astype(float)
cbecs_bldg_type_sqft = cbecsData[[wt_area_col, self.BLDG_TYPE]].groupby([self.BLDG_TYPE]).sum()

# logger.debug(f"cbecs_bldg_type_sqft: {cbecsData[[wt_area_col, self.BLDG_TYPE]]}")
logger.debug('CBECS floor area by building type')
logger.debug(cbecs_bldg_type_sqft)

Expand All @@ -1858,7 +1860,7 @@ def add_national_scaling_weights(self, cbecs: CBECS, remove_non_comstock_bldg_ty
# Calculate scaling factor for each building type based on floor area (not building/model count)
sf = pd.concat([cbecs_bldg_type_sqft, comstock_bldg_type_sqft], axis = 1)
logger.info("sf wt_area_col shape: ", sf[wt_area_col].shape)
sf[self.BLDG_WEIGHT] = sf[wt_area_col]/sf[self.FLR_AREA]
sf[self.BLDG_WEIGHT] = sf[wt_area_col].astype(float) / sf[self.FLR_AREA].astype(float)
bldg_type_scale_factors = sf[self.BLDG_WEIGHT].to_dict()
if np.nan in bldg_type_scale_factors:
wrn_msg = (f'A NaN value was found in the scaling factors, which means that a building type was missing '
Expand Down
6 changes: 5 additions & 1 deletion postprocessing/test_single_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import comstockpostproc as cspp


logging.basicConfig(level='DEBUG', force=True) # Use DEBUG, INFO, or WARNING
# logging.basicConfig(level='DEBUG', force=True) # Use DEBUG, INFO, or WARNING
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.DEBUG,
datefmt='%Y-%m-%d %H:%M:%S', force=True)
logger = logging.getLogger(__name__)

# @profile
Expand Down

0 comments on commit 3a0c12b

Please sign in to comment.