Skip to content

Commit

Permalink
Clean up loadbase (#691)
Browse files Browse the repository at this point in the history
* use dict.get instead of try/except pattern in loadbase

* use logging instead of print-statements
  • Loading branch information
vtnate authored Jan 9, 2025
1 parent cfe112c commit 5cc4310
Showing 1 changed file with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# :copyright (c) URBANopt, Alliance for Sustainable Energy, LLC, and other contributors.
# See also https://github.com/urbanopt/geojson-modelica-translator/blob/develop/LICENSE.md

import logging
from pathlib import Path

from geojson_modelica_translator.model_connectors.model_base import ModelBase
from geojson_modelica_translator.utils import convert_c_to_k

logger = logging.getLogger(__name__)


class LoadBase(ModelBase):
"""Base class of the load connectors."""
Expand Down Expand Up @@ -125,39 +128,26 @@ def add_building(self, urbanopt_building, mapper=None):
f"\nMissing property {ke} for building {self.building_id} in geojson feature file"
)

try:
building_floor_area_m2 = self.ft2_to_m2(urbanopt_building.feature.properties["floor_area"])
except KeyError:
building_floor_area_m2 = 0
building_floor_area_m2 = self.ft2_to_m2(
urbanopt_building.feature.properties.get("floor_area", 0)
)

try:
number_stories_above_ground = urbanopt_building.feature.properties[
"number_of_stories_above_ground"
]
except KeyError:
number_stories_above_ground = number_stories
print(
f"\nAssuming all building levels are above ground for building_id: {self.building_id}"
)
number_stories_above_ground = urbanopt_building.feature.properties.get(
"number_of_stories_above_ground", number_stories
)

try:
floor_height = urbanopt_building.feature.properties["floor_height"]
except KeyError:
floor_height = 3 # Default height in meters from sdk
print(
f"No floor_height found in geojson feature file for building {self.building_id}. "
f"Using default value of {floor_height}."
)
floor_height = urbanopt_building.feature.properties.get("floor_height", 3)

# UO SDK defaults to current year, however TEASER only supports up to Year 2015
# https://github.com/urbanopt/TEASER/blob/master/teaser/data/input/inputdata/TypeBuildingElements.json#L818
# UO SDK defaults to current year.
# TEASER supports buildings built after 2015 since v1.0.1 (https://github.com/RWTH-EBC/TEASER/releases)
# TODO: Consider a different default year now that TEASER supports buildings built after 2015
try:
year_built = urbanopt_building.feature.properties["year_built"]
if urbanopt_building.feature.properties["year_built"] > 2015:
year_built = 2015
except KeyError:
year_built = 2015
print(
logger.debug(
f"No year_built found in geojson feature file for building {self.building_id}. "
f"Using default value of {year_built}."
)
Expand All @@ -173,12 +163,10 @@ def add_building(self, urbanopt_building, mapper=None):
"year_built": year_built,
}
except UnboundLocalError:
print(
logger.warning(
f"Geojson feature file is missing data for building {self.building_id}. "
"This may be caused by referencing a detailed osm in the feature file."
)
else:
continue

else:
raise SystemExit(f"Mapper {mapper} has been used")
Expand Down

0 comments on commit 5cc4310

Please sign in to comment.