import numpy as np import matplotlib.pyplot as plt import pv_input as pv import pandas as pd class Producer: def __init__(self, quantity, profile_type): self.quantity = quantity self.profile_type = profile_type 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() # Vebrauchsprofile aus CSV-Datei in Dataframe einlesen und je nach profile_type die entsprechende Leistungs-Series extrahieren def create_consumption_profile(self): if self.profile_type == 'std': 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 entsprechenden 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 entsprechenden Haushalte multiplizieren def calculate_final_production(self): final_production = self.production_profile.mul(self.quantity) return final_production class Consumer: def __init__(self, quantity, profile_type): self.quantity = quantity self.profile_type = profile_type self.consumption_profile = self.create_consumption_profile() self.final_consumption = self.calculate_final_consumption() # Vebrauchsprofile aus CSV-Datei in Dataframe einlesen und je nach profile_type die entsprechende Leistungs-Series extrahieren def create_consumption_profile(self): if self.profile_type == 'std': 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 entsprechenden Haushalte multiplizieren def calculate_final_consumption(self): final_consumption = self.consumption_profile.mul(self.quantity) return final_consumption class Neighborhood: def __init__(self, producers, consumers): self.producers = producers if isinstance(producers, list) else [producers] self.consumers = consumers if isinstance(consumers, list) else [consumers] # Gesamterzeugung, Gesamtverbrauch und Nettoverbrauch plotten def plot_consumption(self): total_consumption = 0 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 # Rollendes Mittel des netto-Erzeugnisses ausrechnen 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 = pd.date_range(start='2018-12-31', end ='2019-12-31', freq='1h') x = x[:-1] # Plot dimensionieren plt.figure(figsize=(15, 9)) # Barplots anlegen plt.bar(x, total_consumption) plt.bar(x, total_production,color='orange') # Linienplot anlegen #plt.plot(x, net_value,'-',color='darkgreen') plt.plot(x, net_value_mean,'-',color='darkgreen') # Achsenbeschriftungen anlegen plt.xlabel('Kalendertag') plt.ylabel('Leistung (W)') # 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 monthly_ticks = pd.date_range(start='2018-12-31', end ='2019-12-31', freq='1MS') plt.xticks(monthly_ticks) # Legende anlegen plt.legend(['Netto-Leistung', 'Leistung Verbrauch', 'Leistung Erzeugung'], loc='upper right') # X-Labels rotieren plt.xticks(rotation=45) # Grid anlegen plt.axhline(linewidth=1, color='black') plt.grid(color='black', axis='y', linestyle='--', linewidth=0.5) plt.show()