def test_set_tmp(): """ Test the PMV function using the reference table from the ASHRAE 55 2017""" for row in data_test_set: assert (set_tmp(row['tdb'], row['tr'], row['v'], row['rh'], row['met'], row['clo']) - row['set']) < 0.01 assert (set_tmp(tdb=77, tr=77, v=0.328, rh=50, met=1.2, clo=.5, units='IP')) == 77.6 for row in data_test_set_ip: assert (set_tmp(row['tdb'], row['tr'], row['v'], row['rh'], row['met'], row['clo'], units='IP') - row['set']) < 0.11
def transform_view(): # get the uploaded file request_file = request.files["data_file"] # check file if not request_file: return "No file selected" if not allowed_file(request_file.filename): return "The file format is not allowed. Please upload a csv" # read file csv_file = TextIOWrapper(request_file, encoding="utf-8") df = pd.read_csv(csv_file) fields = { "Air temperature": "ta", "MRT": "tr", "Air velocity": "vel", "Relative humidity": "rh", "Metabolic rate": "met", "Clothing level": "clo", } si_unit = any([ True if ("Air temperature" in x) and (x.split(" [")[1] == "C]") else False for x in df.columns ]) df.columns = [ fields[x.split(" [")[0]] if " [" in x else x for x in df.columns ] df["clo_dynamic"] = df.apply( lambda row: clo_dynamic(clo=row["clo"], met=row["met"]), axis=1) results = [] ta = df['ta'].values tr = df['tr'].values vel = df['vel'].values rh = df['rh'].values met = df['met'].values clo = df['clo'].values for ix in range(df.shape[0]): if si_unit: units = "SI" _vr = v_relative(vel[ix], met[ix]) else: units = "IP" _vr = v_relative(vel[ix] / 60 * 0.3048, met[ix]) * 3.28084 try: _set = set_tmp(ta[ix], tr[ix], _vr, rh[ix], met[ix], clo[ix], units=units) except: _set = "" try: _ce = cooling_effect(ta[ix], tr[ix], _vr, rh[ix], met[ix], clo[ix], units=units) except: _ce = "" try: _pmv_ppd = pmv_ppd(ta[ix], tr[ix], _vr, rh[ix], met[ix], clo[ix], standard="ashrae", units=units) _pmv = _pmv_ppd['pmv'] _ppd = _pmv_ppd['ppd'] except: _pmv, _ppd = ["", ""] results.append({ "pmv": _pmv, "ppd": _ppd, "ce": _ce, "vr": _vr, "set": _set }) # split the pmv column in two since currently contains both pmv and ppd values df_ = pd.DataFrame(results) df = pd.concat([df, df_], axis=1, sort=False) df["LEED compliance"] = [True if x < 10 else False for x in df.ppd] resp = make_response(df.to_csv(index=False)) resp.headers["Content-Disposition"] = "attachment; filename=export.csv" resp.headers["Content-Type"] = "text/csv" return resp
def test_set_tmp(): """ Test the PMV function using the reference table from the ASHRAE 55 2017""" for row in data_test_set: assert (abs( set_tmp( tdb=row["tdb"], tr=row["tr"], v=row["v"], rh=row["rh"], met=row["met"], clo=row["clo"], ) - row["set"]) < 0.01) # testing SET equation to calculate cooling effect assert (set_tmp(25, 25, 1.1, 50, 2, 0.5, calculate_ce=True)) == 20.8 assert (set_tmp(25, 25, 1.1, 50, 3, 0.5, calculate_ce=True)) == 21.3 assert (set_tmp(25, 25, 1.1, 50, 1.5, 0.5, calculate_ce=True)) == 20.6 assert (set_tmp(25, 25, 1.1, 50, 1.5, 0.75, calculate_ce=True)) == 23.3 assert (set_tmp(25, 25, 1.1, 50, 1.5, 0.1, calculate_ce=True)) == 15.8 assert (set_tmp(29, 25, 1.1, 50, 1.5, 0.5, calculate_ce=True)) == 23.4 assert (set_tmp(27, 25, 1.1, 50, 1.5, 0.75, calculate_ce=True)) == 24.7 assert (set_tmp(20, 25, 1.1, 50, 1.5, 0.1, calculate_ce=True)) == 11.4 assert (set_tmp(25, 27, 1.1, 50, 1.5, 0.5, calculate_ce=True)) == 21.3 assert (set_tmp(25, 29, 1.1, 50, 1.5, 0.5, calculate_ce=True)) == 21.9 assert (set_tmp(25, 31, 1.1, 50, 1.5, 0.5, calculate_ce=True)) == 22.5 assert (set_tmp(25, 27, 1.3, 50, 1.5, 0.5, calculate_ce=True)) == 20.9 assert (set_tmp(25, 29, 1.5, 50, 1.5, 0.5, calculate_ce=True)) == 21.3 assert (set_tmp(25, 31, 1.7, 50, 1.5, 0.5, calculate_ce=True)) == 21.6 assert (set_tmp( tdb=77, tr=77, v=0.328, rh=50, met=1.2, clo=0.5, units="IP", )) == 75.8 for row in data_test_set_ip: assert (abs( set_tmp( row["tdb"], row["tr"], row["v"], row["rh"], row["met"], row["clo"], units="IP", ) - row["set"]) < 0.11)
"""In this example I am calculating the Standard Effective Temperature (SET) with the pythermalcomfort package""" from pythermalcomfort.models import set_tmp set_value = set_tmp(tdb=25, tr=25, v=0.3, rh=60, met=1.2, clo=0.5) print(f"set_value= {set_value}") set_value = set_tmp(tdb=25, tr=25, v=0.5, rh=60, met=1.2, clo=0.5) print(f"set_value= {set_value}") set_value = set_tmp(tdb=77, tr=77, v=0.6, rh=60, met=1.2, clo=0.5, units="IP") print(f"set_value= {set_value}")