Skip to content

Commit 0ddb62c

Browse files
authored
Merge pull request #837 from RWTH-EBC/836-custom-data-input-files
closes #836
2 parents 753af87 + 4c0a654 commit 0ddb62c

File tree

5 files changed

+50
-18
lines changed

5 files changed

+50
-18
lines changed

teaser/data/dataclass.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
import sys
44
import warnings
5+
from typing import Union
6+
from pathlib import Path
57

68
import teaser.logic.utilities as utils
79
import json
@@ -19,13 +21,22 @@ class DataClass(object):
1921
"""Class for JSON data.
2022
2123
This class loads all JSON files with statistic or template data needed
22-
for statistical data enrichment.
24+
for statistical data enrichment. For loading a custom TypeElements JSON files,
25+
use ConstructionData.custom as input.
2326
2427
Parameters
2528
----------
2629
construction_data : ConstructionData
2730
The prefix of this parameter indicates which statistical data about building
2831
elements should be used. Its type is the enum class ConstructionData.
32+
To utilize custom TypeElements via a JSON file via parameter custom_path_type_elements (cf. below)
33+
use ConstructionData.custom.
34+
custom_path_type_elements: str or Path
35+
Custom path to JSON file of TypeElements. Default: None
36+
custom_path_material_templates: str or Path
37+
Custom path to JSON file of MaterialTemplates. Default: None
38+
custom_path_use_conditions: str or Path
39+
Custom path to JSON file of UseConditions. Default: None
2940
3041
Attributes
3142
----------
@@ -47,50 +58,65 @@ class DataClass(object):
4758
4859
"""
4960

50-
def __init__(self, construction_data: ConstructionData) -> object:
61+
def __init__(self,
62+
construction_data: ConstructionData,
63+
custom_path_type_elements: Union[str, Path]=None,
64+
custom_path_material_templates: Union[str, Path]=None,
65+
custom_path_use_conditions: Union[str, Path]=None) -> object:
66+
5167
"""Construct DataClass."""
5268
self.element_bind = None
53-
if construction_data.is_iwu():
69+
if construction_data.is_custom():
70+
if custom_path_type_elements:
71+
self.path_tb = custom_path_type_elements
72+
elif not custom_path_type_elements:
73+
raise KeyError("Provide path to custom type elements JSON file "
74+
"or change ConstructionData to a known construction type")
75+
elif construction_data.is_iwu():
5476
self.path_tb = utils.get_full_path(
5577
"data/input/inputdata/TypeElements_IWU.json"
5678
)
57-
self.load_tb_binding()
5879
elif construction_data.is_tabula_de():
5980
self.path_tb = utils.get_full_path(
6081
os.path.join(
6182
"data", "input", "inputdata", "TypeElements_TABULA_DE.json"
6283
)
6384
)
64-
self.load_tb_binding()
6585
elif construction_data.is_tabula_dk():
6686
self.path_tb = utils.get_full_path(
6787
os.path.join(
6888
"data", "input", "inputdata", "TypeElements_TABULA_DK.json"
6989
)
7090
)
71-
self.load_tb_binding()
7291
elif construction_data.is_kfw():
7392
self.path_tb = utils.get_full_path(
7493
os.path.join(
7594
"data", "input", "inputdata", "TypeElements_KFW.json"
7695
)
7796
)
78-
self.load_tb_binding()
7997
elif construction_data is None:
8098
pass
99+
81100
self.material_bind = None
82-
self.path_mat = utils.get_full_path(
83-
"data/input/inputdata/MaterialTemplates.json"
84-
)
101+
if custom_path_material_templates:
102+
self.path_mat = custom_path_material_templates
103+
else:
104+
self.path_mat = utils.get_full_path(
105+
"data/input/inputdata/MaterialTemplates.json")
106+
85107
self.conditions_bind = None
86-
self.path_uc = utils.get_full_path("data/input/inputdata/UseConditions.json")
108+
if custom_path_use_conditions:
109+
self.path_uc = custom_path_use_conditions
110+
else:
111+
self.path_uc = utils.get_full_path("data/input/inputdata/UseConditions.json")
87112

113+
self.load_tb_binding()
88114
self.load_uc_binding()
89115
self.load_mat_binding()
90116

91117
def load_tb_binding(self):
92118
"""Load TypeBuildingElement json into binding classes."""
93-
if self.path_tb.endswith("json"):
119+
if str(self.path_tb).endswith("json"):
94120
if os.path.isfile(self.path_tb):
95121
try:
96122
with open(self.path_tb, "r") as f:
@@ -105,7 +131,7 @@ def load_tb_binding(self):
105131

106132
def load_uc_binding(self):
107133
"""Load UseConditions json into binding classes."""
108-
if self.path_uc.endswith("json"):
134+
if str(self.path_uc).endswith("json"):
109135
if os.path.isfile(self.path_uc):
110136
try:
111137
with open(self.path_uc, "r") as f:
@@ -120,7 +146,7 @@ def load_uc_binding(self):
120146

121147
def load_mat_binding(self):
122148
"""Load MaterialTemplates json into binding classes."""
123-
if self.path_mat.endswith("json"):
149+
if str(self.path_mat).endswith("json"):
124150
if os.path.isfile(self.path_mat):
125151
try:
126152
with open(self.path_mat, "r") as f:

teaser/data/input/buildingelement_input_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def load_type_element(element, year, construction, data_class,
2929
Year of construction
3030
3131
construction : str
32-
Construction type, code list ('iwu_heavy', 'iwu_light', 'tabula_de_standard', 'kfw_40', ...)
32+
Construction type defined in data_class, code list (e.g. 'heavy', 'light' or custom)
3333
3434
data_class : DataClass()
3535
DataClass containing the bindings for TypeBuildingElement and

teaser/data/utilities.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class ConstructionData(Enum):
7777
The ConstructionData enumeration combines the former parameters “method” and “construction_type”.
7878
The prefix of each value is used to select the appropriate json file as input data.
7979
The complete value is used to search for the appropriate element within the json file.
80+
To utilize custom TypeElements via a JSON file via parameter custom_path_type_elements (cf. below)
81+
use ConstructionData.custom.
8082
"""
8183
iwu_heavy = "iwu_heavy"
8284
iwu_light = "iwu_light"
@@ -91,6 +93,7 @@ class ConstructionData(Enum):
9193
kfw_70 = "kfw_70"
9294
kfw_85 = "kfw_85"
9395
kfw_100 = "kfw_100"
96+
custom = "custom"
9497

9598
def get_prefix(self):
9699
parts = self.value.split("_", 2)
@@ -112,6 +115,9 @@ def is_tabula_dk(self):
112115
def is_kfw(self):
113116
return self.get_prefix() == "kfw"
114117

118+
def is_custom(self):
119+
return self.value == "custom"
120+
115121
# Dictionary that maps GeometryData enumeration values to their corresponding building classes.
116122
geometries = {
117123
#non residential:

teaser/logic/buildingobjects/buildingphysics/buildingelement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def load_type_element(
296296
Year of construction
297297
298298
construction : str
299-
Construction type, code list ('heavy', 'light')
299+
Construction type defined in data_class, code list (e.g. 'heavy', 'light' or custom)
300300
301301
data_class : DataClass()
302302
DataClass containing the bindings for TypeBuildingElement and

teaser/logic/buildingobjects/buildingphysics/interzonalwall.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ def load_type_element(
180180
Year of construction
181181
182182
construction : str
183-
Construction type, code list ('heavy', 'light')
183+
Construction type defined in data_class, code list (e.g. 'heavy', 'light' or custom)
184184
185185
data_class : DataClass()
186186
DataClass containing the bindings for TypeBuildingElement and
187187
Material (typically this is the data class stored in prj.data,
188188
but the user can individually change that. Default is
189189
self.parent.parent.parent.data (which is data_class in current
190-
project)
190+
project).
191191
192192
element_type : str
193193
Element type to load - only to specify if the json entry for a

0 commit comments

Comments
 (0)