compare_heat_demands.py 3.19 KB
Newer Older
1
2
3
4
5
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt

PROJ_DIR = Path(__file__).parent
6
CITYGML = 'Grombühl_v2'
7
URBI_HEAT_DEMAND = 'totalPrimaryEnergyDemandHeating [kWh/a]'
8
S_DEMAND = 'Simstadt heat demand [MWh / a]' # Inkl Warmwasser?
9
10
11
U_DEMAND = 'Urbi+ heat demand [MWh / a]'
AREA = 'Area [m²]'
TYPE = 'Usage Type'
12
13
14
15
16
SUFFIX = '_Bensfeld'

# Feldberg : 2.493 (Average : 3.0°C, Min : -18°C)
# Original : 2.487 (Average : 7.9°C, Min : -12°C), Würzburg
# Bensfeld : 2.475 (Average : 10.2°C, Min : -10°C)
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46


def get_simstadt_heat_demand():
    heating_csvs = list(PROJ_DIR.glob(f'**/{CITYGML}_DIN18599_HEATING.csv'))
    assert len(heating_csvs) == 1
    hourly_demand = heating_csvs[0]

    simstadt_df = pd.read_csv(hourly_demand, sep=';',
                              skiprows=list(range(19)) + [20],
                              decimal='.')

    simstadt_df = simstadt_df.rename({
                                      'Total Yearly Heat+DHW demand': S_DEMAND,
                                      'PrimaryUsageZoneArea': AREA,
                                      'PrimaryUsageZoneType': TYPE,
                                      }, axis='columns')

    simstadt_df[S_DEMAND] = simstadt_df[S_DEMAND] / 1000  # kWh -> MWh
    simstadt_df = simstadt_df.set_index('GMLId')

    by_type_df = simstadt_df.groupby([TYPE]).sum(numeric_only=True)[[AREA, S_DEMAND]]

    by_type_df['Specific heat demand [kWh / (m².a)]'] = by_type_df[S_DEMAND] / by_type_df[AREA] * 1000

    print(by_type_df.round(1).to_string())

    return simstadt_df


def get_urbi_heat_demand():
Eric Duminil's avatar
Weird.    
Eric Duminil committed
47
    urbi_csvs = list(PROJ_DIR.glob(f'**/{CITYGML}{SUFFIX}.csv'))
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    assert len(urbi_csvs) == 1
    urbi_csv_filename = urbi_csvs[0]
    urbi_results = {}
    with open(urbi_csv_filename) as csv_file:
        cells = next(csv_file).strip().split(';')
        heat_demand_column = cells.index(URBI_HEAT_DEMAND)
        id_column = cells.index('ID')
        for line in csv_file:
            cells = line.strip().split(';')
            urbi_results[cells[id_column]] = round(
                float(cells[heat_demand_column]), 0) / 1000  # MWh

    urbi_df = pd.DataFrame.from_dict(
        urbi_results, orient='index', columns=[U_DEMAND])
    return urbi_df


def compare_results(simstadt_df, urbi_df):
    print(urbi_df)
    simstadt_urbi = simstadt_df.join(urbi_df)[[S_DEMAND, U_DEMAND]]
    simstadt_urbi = simstadt_urbi.dropna()

70
    simstadt_urbi.round(1).to_csv(f'simstadt_vs_urbi_heat_demands_{CITYGML}{SUFFIX}.csv', sep=';', decimal='.')
71
72

    plt.rcParams["figure.figsize"] = (10, 10)
Eric Duminil's avatar
Weird.    
Eric Duminil committed
73
    ax = simstadt_urbi.plot.scatter(x=S_DEMAND, y=U_DEMAND, title=f'Urbi vs SimStadt Heat-demand\n{CITYGML}{SUFFIX}')
74
75
76
    max_heat_demand = simstadt_urbi.max().max()
    ax.plot([0, max_heat_demand], [0, max_heat_demand])
    ax.axis('equal')
Eric Duminil's avatar
Weird.    
Eric Duminil committed
77
    plt.savefig(f'simstadt_vs_urbi_heat_demands_{CITYGML}{SUFFIX}.png', bbox_inches='tight')
78
79
80
81
82
83
84
85
86
87
88
89
90
91

    print("Correlation:")
    print(simstadt_urbi.corr())

    print()
    print(simstadt_urbi.round(1))

    print()
    print("Average Urbi / SimStadt heat demand ratio:")
    print((simstadt_urbi[U_DEMAND] / simstadt_urbi[S_DEMAND]).mean())


if __name__ == '__main__':
    compare_results(get_simstadt_heat_demand(), get_urbi_heat_demand())