22import os
33import sys
44import warnings
5+ from typing import Union
6+ from pathlib import Path
57
68import teaser .logic .utilities as utils
79import 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 :
0 commit comments