-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_load_profiles.py
More file actions
136 lines (113 loc) · 3.74 KB
/
read_load_profiles.py
File metadata and controls
136 lines (113 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Load and visualize normalized load profiles.
All profiles are normalized to 1,000,000 kWh annual consumption
and have hourly timestamps for 2011.
"""
import pandas as pd
import plotly.graph_objects as go
from pathlib import Path
# Paths
BASE_DIR = Path.home() / "Dokumente" / "new_hh_profiles"
OUTPUT_PATH = BASE_DIR / "profile_comparison.html"
# Normalized profile files
PROFILES = {
"PyLPG": BASE_DIR / "pylpg_normalized_1mio.csv",
"Districtgenerator": BASE_DIR / "districtgenerator_normalized_1mio.csv",
"IEE": BASE_DIR / "iee_normalized_1mio.csv",
"SLP H25": BASE_DIR / "slp_normalized_1mio.csv",
}
# Colors
COLORS = {
"PyLPG": "#000080", # Navy
"Districtgenerator": "#228B22", # Forest Green
"IEE": "#FF8C00", # Orange
"SLP H25": "#808080", # Grey
}
def load_profiles():
"""Load all normalized profiles into a single DataFrame."""
print("Loading normalized profiles...")
dfs = {}
for name, path in PROFILES.items():
df = pd.read_csv(path, index_col=0, parse_dates=True)
dfs[name] = df["electricity_kwh"]
print(f" {name}: {len(df)} hours, sum = {df['electricity_kwh'].sum():,.0f} kWh")
combined = pd.DataFrame(dfs)
return combined
def create_figure(df):
"""Create interactive Plotly figure."""
fig = go.Figure()
# Add trace for each profile
for col in df.columns:
fig.add_trace(
go.Scatter(
x=df.index,
y=df[col],
name=col,
line=dict(color=COLORS.get(col, "gray"), width=1.5),
hovertemplate=(
f"<b>{col}</b><br>"
"Zeit: %{x}<br>"
"Leistung: %{y:.2f} kWh<br>"
"<extra></extra>"
),
)
)
# Layout with range selector
fig.update_layout(
title=dict(
text="Vergleich Haushaltslastprofile (normiert auf 1 Mio kWh/a)",
font=dict(size=20),
),
xaxis=dict(
title="Zeit",
rangeselector=dict(
buttons=[
dict(count=1, label="1 Tag", step="day", stepmode="backward"),
dict(count=7, label="1 Woche", step="day", stepmode="backward"),
dict(count=1, label="1 Monat", step="month", stepmode="backward"),
dict(count=3, label="3 Monate", step="month", stepmode="backward"),
dict(step="all", label="Ganzes Jahr"),
],
bgcolor="white",
activecolor="lightblue",
),
rangeslider=dict(visible=True, thickness=0.1),
type="date",
),
yaxis=dict(
title="Elektrische Leistung [kWh]",
autorange=True,
),
legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1,
),
hovermode="x unified",
template="plotly_white",
height=700,
)
return fig
def main():
print("=" * 60)
print("Lastprofilvergleich")
print("=" * 60)
# Load all profiles
df = load_profiles()
print(f"\nCombined DataFrame: {df.shape}")
print(f"Columns: {df.columns.tolist()}")
# Create figure
print("\nCreating figure...")
fig = create_figure(df)
print(f"Number of traces: {len(fig.data)}")
# Save directly with Plotly
print(f"\nSaving to: {OUTPUT_PATH}")
fig.write_html(OUTPUT_PATH, include_plotlyjs=True, full_html=True)
print(f"File size: {OUTPUT_PATH.stat().st_size / 1024:.1f} KB")
print(f"\nÖffnen mit: file://{OUTPUT_PATH}")
if __name__ == "__main__":
main()