Lastprofile angepasst, variable Zahl an Producer+Consumer

This commit is contained in:
2025-01-07 21:04:56 +01:00
parent 210a2f9bc3
commit 54657cffd5
3 changed files with 8831 additions and 8805 deletions

File diff suppressed because it is too large Load Diff

19
main.py
View File

@@ -1,16 +1,17 @@
from neighborhood import Producer, Consumer, Neighborhood from neighborhood import Producer, Consumer, Neighborhood
# Anzahl Haushalte ohne PV-Anlagen # Consumer-Instanzen anlegen
num_consumer = 5 standard_consumer = Consumer(quantity=10, profile_type='std')
wp_consumer = Consumer(quantity=0, profile_type='wp')
# Anzahl Haushalte mit PV-Anlagen ea_consumer = Consumer(quantity=0, profile_type='ea')
num_producer = 5
# Instanzen für Erzeuger und Verbraucher anlegen # Producer-Instanz anlegen
producer = Producer(num_producer) standard_producer = Producer(quantity=0, profile_type='std')
consumer = Consumer(num_consumer) wp_producer = Producer(quantity=0, profile_type='wp')
ea_producer = Producer(quantity=0, profile_type='ea')
# Instanz für Nachbarschaft anlegen und Ergebnis plotten # Instanz für Nachbarschaft anlegen und Ergebnis plotten
neighborhood = Neighborhood(producer, consumer) neighborhood = Neighborhood(producers=[standard_producer, wp_producer, ea_producer], consumers=[standard_consumer, wp_consumer, ea_consumer])
neighborhood.plot_consumption() neighborhood.plot_consumption()

View File

@@ -1,26 +1,30 @@
# https://stackoverflow.com/questions/63511090/how-can-i-smooth-data-in-python
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pv_input as pv import pv_input as pv
import pandas as pd import pandas as pd
from scipy.signal import savgol_filter
class Producer: class Producer:
def __init__(self, quantity): def __init__(self, quantity, profile_type):
self.quantity = quantity self.quantity = quantity
self.profile_type = profile_type
self.consumption_profile = self.create_consumption_profile() self.consumption_profile = self.create_consumption_profile()
self.production_profile = self.create_production_profile() self.production_profile = self.create_production_profile()
self.final_consumption = self.calculate_final_consumption() self.final_consumption = self.calculate_final_consumption()
self.final_production = self.calculate_final_production() self.final_production = self.calculate_final_production()
# Vebrauchsprofil aus CSV-Datei in Dataframe einlesen und die Leistungs-Series extrahieren # Vebrauchsprofile aus CSV-Datei in Dataframe einlesen und je nach profile_type die entsprechende Leistungs-Series extrahieren
def create_consumption_profile(self): def create_consumption_profile(self):
consumption_profile = pd.read_csv('Lastprofil_final_H0.csv',delimiter=';') if self.profile_type == 'std':
return consumption_profile['Leistung'] consumption_profile = pd.read_csv('Lastprofile_gesamt.csv',delimiter=';')
return consumption_profile['Leistung']*1000
elif self.profile_type == 'wp':
consumption_profile = pd.read_csv('Lastprofile_gesamt.csv',delimiter=';')
return consumption_profile['Leistung_WP']*1000
elif self.profile_type == 'ea':
consumption_profile = pd.read_csv('Lastprofile_gesamt.csv',delimiter=';')
return consumption_profile['Leistung_EA']*1000
# Verbrauchsprofil mit der Anzahl der Haushalte multiplizieren # Verbrauchsprofil mit der Anzahl der entsprechenden Haushalte multiplizieren
def calculate_final_consumption(self): def calculate_final_consumption(self):
final_consumption = self.consumption_profile.mul(self.quantity) final_consumption = self.consumption_profile.mul(self.quantity)
return final_consumption return final_consumption
@@ -32,7 +36,7 @@ class Producer:
production_profile = pd.read_csv('production_profile.csv',delimiter=';') production_profile = pd.read_csv('production_profile.csv',delimiter=';')
return production_profile['Leistung'] return production_profile['Leistung']
# Erzeugungsprofil mit der Anzahl der Haushalte multiplizieren # Erzeugungsprofil mit der Anzahl der entsprechenden Haushalte multiplizieren
def calculate_final_production(self): def calculate_final_production(self):
final_production = self.production_profile.mul(self.quantity) final_production = self.production_profile.mul(self.quantity)
return final_production return final_production
@@ -40,17 +44,26 @@ class Producer:
class Consumer: class Consumer:
def __init__(self, quantity): def __init__(self, quantity, profile_type):
self.quantity = quantity self.quantity = quantity
self.profile_type = profile_type
self.consumption_profile = self.create_consumption_profile() self.consumption_profile = self.create_consumption_profile()
self.final_consumption = self.calculate_final_consumption() self.final_consumption = self.calculate_final_consumption()
# Vebrauchsprofil aus CSV-Datei in Dataframe einlesen und die Leistungs-Series extrahieren, Werte in Watt umrechnen # Vebrauchsprofile aus CSV-Datei in Dataframe einlesen und je nach profile_type die entsprechende Leistungs-Series extrahieren
def create_consumption_profile(self): def create_consumption_profile(self):
consumption_profile = pd.read_csv('Lastprofile_gesamt.csv',delimiter=';') if self.profile_type == 'std':
return consumption_profile['Leistung']*1000 consumption_profile = pd.read_csv('Lastprofile_gesamt.csv',delimiter=';')
return consumption_profile['Leistung']*1000
elif self.profile_type == 'wp':
consumption_profile = pd.read_csv('Lastprofile_gesamt.csv',delimiter=';')
return consumption_profile['Leistung_WP']*1000
elif self.profile_type == 'ea':
consumption_profile = pd.read_csv('Lastprofile_gesamt.csv',delimiter=';')
return consumption_profile['Leistung_EA']*1000
# Verbrauchsprofil mit der Anzahl der Haushalte multiplizieren
# Verbrauchsprofil mit der Anzahl der entsprechenden Haushalte multiplizieren
def calculate_final_consumption(self): def calculate_final_consumption(self):
final_consumption = self.consumption_profile.mul(self.quantity) final_consumption = self.consumption_profile.mul(self.quantity)
return final_consumption return final_consumption
@@ -58,17 +71,28 @@ class Consumer:
class Neighborhood: class Neighborhood:
def __init__(self, producer, consumer): def __init__(self, producers, consumers):
self.producer = producer self.producers = producers if isinstance(producers, list) else [producers]
self.consumer = consumer self.consumers = consumers if isinstance(consumers, list) else [consumers]
# Gesamterzeugung, Gesamtverbrauch und Nettoverbrauch plotten # Gesamterzeugung, Gesamtverbrauch und Nettoverbrauch plotten
def plot_consumption(self): def plot_consumption(self):
total_consumption = -1*(self.consumer.final_consumption + self.producer.final_consumption) total_consumption = 0
total_production = self.producer.final_production total_production = 0
# Verbrauch der Consumer subtrahieren
for consumer in self.consumers:
total_consumption -= consumer.final_consumption
# Zusätzlich Verbrauch der Producer subtrahieren
for producer in self.producers:
total_consumption -= producer.final_consumption
# Produktion der Producer addieren
for producer in self.producers:
total_production += producer.final_production
# Netto-Erzeugnis ausrechnen
net_value = total_consumption + total_production net_value = total_consumption + total_production
net_value_mean = net_value.rolling(168).mean() # Rollendes Mittel des netto-Erzeugnisses ausrechnen
net_value_filtered = net_value.apply(savgol_filter, window_length=168, polyorder=2) net_value_mean = net_value.rolling(24).mean()
# X-Werte anlegen, einen Wert löschen da 8761 Werte vorhanden sind, aber nur 8760 benötigt werden # X-Werte anlegen, einen Wert löschen da 8761 Werte vorhanden sind, aber nur 8760 benötigt werden
x = pd.date_range(start='2018-12-31', end ='2019-12-31', freq='1h') x = pd.date_range(start='2018-12-31', end ='2019-12-31', freq='1h')
@@ -77,33 +101,34 @@ class Neighborhood:
# Plot dimensionieren # Plot dimensionieren
plt.figure(figsize=(15, 9)) plt.figure(figsize=(15, 9))
# Barplot anlegen # Barplots anlegen
plt.bar(x, total_consumption)
plt.bar(x, total_production,color='orange')
#plt.bar(x, total_consumption) # Linienplot anlegen
#plt.bar(x, total_production,color='orange') #plt.plot(x, net_value,'-',color='darkgreen')
#plt.bar(x, net_value,color='forestgreen') plt.plot(x, net_value_mean,'-',color='darkgreen')
# Rollendes Mittel plotten # Achsenbeschriftungen anlegen
#plt.plot(x, net_value_mean,'-',color='forestgreen')
# Titel und Achsenbeschriftungen anlegen
plt.xlabel('Kalendertag') plt.xlabel('Kalendertag')
plt.ylabel('Leistung (W)') plt.ylabel('Leistung (W)')
#plt.title('Nettoleistung Nachbarschaft Standardfalll')
plt.title('Rollendes Mittel (7 Tage) Netto-Leistung Nachbarschaft Standardfall') # Titel anlegen
#plt.title('Netto-leistung Nachbarschaft - Fall XXX')
plt.title('Erzeugung, Verbrauch und Netto-Leistung (Rollendes Mittel 24h) - Fall XXX')
# X-Ticks nur monatlich plotten # X-Ticks nur monatlich plotten
monthly_ticks = pd.date_range(start='2018-12-31', end ='2019-12-31', freq='1MS') monthly_ticks = pd.date_range(start='2018-12-31', end ='2019-12-31', freq='1MS')
plt.xticks(monthly_ticks) plt.xticks(monthly_ticks)
# Legende anlegen # Legende anlegen
#plt.legend(['Verbrauch', 'Erzeugung'], loc='upper right') plt.legend(['Netto-Leistung', 'Leistung Verbrauch', 'Leistung Erzeugung'], loc='upper right')
#plt.legend(['Verbrauch', 'Erzeugung', 'Netto-Wert'], loc='upper right')
# X-Labels rotieren # X-Labels rotieren
plt.xticks(rotation=45) plt.xticks(rotation=45)
# Grid anlegen # Grid anlegen
plt.axhline(linewidth=1, color='black')
plt.grid(color='black', axis='y', linestyle='--', linewidth=0.5) plt.grid(color='black', axis='y', linestyle='--', linewidth=0.5)
plt.show() plt.show()