import numpy as np import matplotlib.pyplot as plt import pv_input as pv import pandas as pd class Producer: def __init__(self, quantity): self.quantity = quantity self.consumption_profile = self.create_consumption_profile() self.production_profile = self.create_production_profile() self.final_consumption = self.calculate_final_consumption() self.final_production = self.calculate_final_production() # Vebrauchsprofil aus CSV-Datei in Dataframe einlesen und die Leistungs-Series extrahieren def create_consumption_profile(self): consumption_profile = pd.read_csv('Lastprofil_final_H0.csv',delimiter=';') return consumption_profile['Leistung'] # Verbrauchsprofil mit der Anzahl der Haushalte multiplizieren def calculate_final_consumption(self): final_consumption = self.consumption_profile.mul(self.quantity) return final_consumption # Erzegungsprofil über PV_Input.py erstelln, in .csv schreiben und von dort dann die Leistungs-Series extrahieren def create_production_profile(self): production_profile = pv.create_production_profile() production_profile.to_csv('production_profile.csv', sep=';',header=['Leistung']) production_profile = pd.read_csv('production_profile.csv',delimiter=';') return production_profile['Leistung'] # Erzeugungsprofil mit der Anzahl der Haushalte multiplizieren def calculate_final_production(self): final_production = self.production_profile.mul(self.quantity) return final_production class Consumer: def __init__(self, quantity): self.quantity = quantity self.consumption_profile = self.create_consumption_profile() self.final_consumption = self.calculate_final_consumption() # Vebrauchsprofil aus CSV-Datei in Dataframe einlesen und die Leistungs-Series extrahieren, Werte in Watt umrechnen und mit 4 multiplizieren, da Originalwerte 15-minütlich waren def create_consumption_profile(self): consumption_profile = pd.read_csv('Lastprofil_final_H0.csv',delimiter=';') return consumption_profile['Leistung']*1000*4 # Verbrauchsprofil mit der Anzahl der Haushalte multiplizieren def calculate_final_consumption(self): final_consumption = self.consumption_profile.mul(self.quantity) return final_consumption class Neighborhood: def __init__(self, producer, consumer): self.producer = producer self.consumer = consumer # Gesamterzeugung, Gesamtverbrauch und Nettoverbrauch plotten def plot_consumption(self): total_consumption = -1*(self.consumer.final_consumption + self.producer.final_consumption) total_production = self.producer.final_production net_value = total_consumption + total_production # 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 = x[:-1] # Plot dimensionieren plt.figure(figsize=(10, 6)) # y-Werte den x-Werten zuordnen plt.bar(x, total_consumption) plt.bar(x, total_production) plt.bar(x, net_value) #plt.plot(x, net_value, '-') # Titel und Achsenbeschriftungen anlegen plt.xlabel('Stunde') plt.ylabel('Strom (kWh)') plt.title('Produktion/Verbrauch Nachbarschaft') # X-Ticks nur monatlich plotten monthly_ticks = pd.date_range(start='2018-12-31', end ='2019-12-31', freq='1MS') plt.xticks(monthly_ticks) # Legende anlegen plt.legend(['Verbrauch', 'Produktion', 'Netto-Wert'], loc='upper right') # X-Labels rotieren plt.xticks(rotation=45) # Grid anlegen plt.grid(color='black', axis='y', linestyle='--', linewidth=0.5) plt.show()