def get_element(year, element_type, flat_roof=False, location="22", iteration=1, weight=10, verbose=False, force_inx=False, force_ite=False): """get building element.""" if element_type == "wall": element_type_de = "Außenwand" elif element_type == "roof": if flat_roof: element_type_de = "Flachdach" else: element_type_de = "Steildach" else: raise Exception( "element type not implemented yet, expeced 'wall' or 'roof'") found = False while not found: building_components = D[ ([location in a for a in D["Location"]]) & (D["Year"] == year) & (D["Type"] == element_type_de) & ["k.A." not in a for a in D["Uval"]] ] if building_components.shape[0] == 0: year = years[years.index(year) + 1] if verbose: print("could't find a matching component\ with following characteristics:") print("Location: ", location) print("Year: ", year) print("Type: ", element_type_de) print("U-val != k.A.") else: found = True if verbose: print("building components found:") print(building_components.shape) print(building_components) inx = choice([i for i in range(building_components.shape[0])]) Uval_diff = np.Inf uvalues = pd.DataFrame(columns=["masea", "catalogue"]) for ite in range(iteration): if force_ite: ite = force_ite if verbose: print("+"*30) print("iteration: ", ite) print("+"*30) layers = getMasea(building_components, weight=weight, iterations=iteration, component_index=inx, verbose=verbose, force_index=force_inx) Uval_catal_temp = max(building_components.iloc[inx, 6]) layers = layers.drop_duplicates('name') layers = layers[[i != "-" for i in layers.Thickness]] layers = layers.reindex(index=layers.index[::-1]) try: Uval_masea_temp = get_masea_uval(layers, verbose=verbose)[0] except: if verbose: print("can't compute u-val") Uval_masea_temp = np.Inf this_diff = abs(Uval_catal_temp - Uval_masea_temp) if this_diff < Uval_diff: Uval_diff = this_diff Uval_masea = Uval_masea_temp Uval_catal = Uval_catal_temp if force_ite: break index = pd.MultiIndex.from_tuples( [(year, element_type)], names=['year', 'typ']) uvalues = pd.DataFrame({"masea": Uval_masea, "catalogue": Uval_catal}, index=index) return(uvalues)
def get_element(year, element_type, flat_roof=False, location="22", iteration=1, weight=10, verbose=False, force_inx=False, force_ite=False, print_layers=False, retrofit=False): """Function *get_element* retrieves a building component from the catalogue based on: 1. location 2. construction year 3. building component type The parameter *location* is define as a string containing the location code from the regional material catalogue. The parameter *year* is define as an integer between defining the construction year of the building. The *building component type* parameter distinguish between two building components: (a) *wall* and (b) *roof*. the regional material catalogue identifies more component types, these other component types haven't been implemented yet into the source code.""" if element_type == "wall": element_type_de = "Außenwand" elif element_type == "roof": if flat_roof: element_type_de = "Flachdach" else: element_type_de = "Steildach" else: raise Exception( "element type not implemented yet, expeced 'wall' or 'roof'") found = False while not found: building_components = D[ ([location in a for a in D["Location"]]) & (D["Year"] == year) & (D["Type"] == element_type_de) & ["k.A." not in a for a in D["Uval"]]] if building_components.shape[0] == 0: year = years[years.index(year) + 1] if verbose: print( "could't find a matching component\ with following characteristics:") print("Location: ", location) print("Year: ", year) print("Type: ", element_type_de) print("U-val != k.A.") else: found = True inx = choice([i for i in range(building_components.shape[0])]) if verbose or print_layers: print("building components found:") print(building_components.iloc[inx, :]) Uval_diff = np.Inf uvalues = pd.DataFrame(columns=["masea", "catalogue"]) for ite in range(iteration): if force_ite: ite = force_ite if verbose: print("+"*30) print("iteration: ", ite) print("+"*30) layers = getMasea(building_components, weight=weight, iterations=iteration, component_index=inx, verbose=verbose, force_index=force_inx) Uval_catal_temp = max(building_components.iloc[inx, 6]) layers = layers.drop_duplicates('name') layers = layers[[i != "-" for i in layers.Thickness]] layers = layers.reindex(index=layers.index[::-1]) if retrofit: layers = get_retrofit(layers, retrofit, verbose=verbose) try: Uval_masea_temp = get_masea_uval(layers, verbose=verbose)[0] except: if verbose: print("can't compute u-val") Uval_masea_temp = np.Inf this_diff = abs(Uval_catal_temp - Uval_masea_temp) if this_diff < Uval_diff: Uval_diff = this_diff Uval_masea = Uval_masea_temp Uval_catal = Uval_catal_temp layers_out = layers if force_ite: break if print_layers: print(layers_out) index = pd.MultiIndex.from_tuples([(year, element_type)], names=['year', 'typ']) uvalues = pd.DataFrame({"masea": Uval_masea, "catalogue": Uval_catal}, index=index) return(uvalues)