181 lines
6.5 KiB
Python
181 lines
6.5 KiB
Python
from src.Functions_Energy_Model import *
|
|
from src.Functions_General import *
|
|
import subprocess
|
|
import signal
|
|
import time
|
|
import plotly.express as px
|
|
import plotly.graph_objects as go
|
|
import pandas as pd
|
|
|
|
location_ita = input("Inserisci la località in italiano (es. Biella): ") # location in Italian
|
|
capacity = int(input("Inserisci la capacità dell'impianto in kWp (es. 100): ")) # kWp
|
|
tilt_angle = int(input("Inserisci l'angolo di inclinazione in gradi (es. 30): ")) # gradi
|
|
azimuth = int(input("Inserisci l'azimuth in gradi (es. 180): ")) # gradi
|
|
num_years = 1 # anni di simulazione
|
|
derating_factor_percent = 1 # derating factor that reduce the efficiency of the modules in percentage [%]
|
|
|
|
config = yaml.safe_load(open("config.yml", 'r'))
|
|
path_export = str(config['filename_output_csv_gen_pv']) # percorso del file di output
|
|
|
|
# IGNORE THIS
|
|
isJoe = config['joe_fight']
|
|
joePlaying = False
|
|
if(isJoe == True):
|
|
if shutil.which('ffplay') is not None:
|
|
joePlaying = True
|
|
joe = subprocess.Popen(['ffplay', '-fs', 'assets/joefight.mp4'])
|
|
time.sleep(25) # deve arrivare il drop
|
|
else:
|
|
print("ffplay non installato, no joe fight.")
|
|
|
|
# INIZIALIZZAZIONE PARAMETRI PER SIMULAZIONE
|
|
location_eng = location_italian_to_english(location_ita)
|
|
path = "config.yml"
|
|
filename = ""
|
|
key = "project_lifetime_yrs"
|
|
value = num_years
|
|
add_to_file_yml(path, filename, key, value)
|
|
suppress_printing(generate_calendar) # generazione del calendario
|
|
coordinates_dataset = suppress_printing(create_coordinates_dataset, [location_eng]) # crea un dataset con le coordinate di tutte le posizioni
|
|
derating_factor = derating_factor_percent / 100
|
|
|
|
# CALCOLO PRODUTTIVITA'
|
|
result_ac_energies_resampled = suppress_printing(simulate_1_kWp_generators, coordinates_dataset, tilt_angle, azimuth)
|
|
|
|
# SCALING PRODUTTIVITA'
|
|
result_ac_energies_gens = {} # initialization of the output dictionary
|
|
result_ac_energies_gens['gen_pv_' + str(capacity) + '_kWp'] = result_ac_energies_resampled[location_eng] * capacity
|
|
|
|
# DERATING PRODUTTIVITA'
|
|
result_ac_energies_gens_derated = suppress_printing(simulate_gens_derated_productivity, derating_factor, result_ac_energies_gens)
|
|
|
|
# GENERAZIONE DATAFRAME
|
|
result_ac_energies_to_csv_df = suppress_printing(simulate_unstacked_productivity, result_ac_energies_gens_derated) # create two unstacked dataframe (the other functions work with dictionaries)
|
|
|
|
# ESPORTAZIONE RISULTATI IN CSV
|
|
print("Valore massimo:",max(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # print the maximum value of the generated energy
|
|
print("Somma totale:",sum(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # print the total sum of the generated energy
|
|
result_ac_energies_to_csv_df.to_csv(path_export, encoding='utf-8')
|
|
|
|
def generate_grafico_barrette_df(dataframe, graphTitle):
|
|
# Supponendo che la colonna di interesse sia 'gen_pv_100_kWp'
|
|
fig = px.line(
|
|
dataframe,
|
|
x=dataframe.index,
|
|
y='gen_pv_100_kWp',
|
|
title=graphTitle,
|
|
labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data/Ora'}
|
|
)
|
|
fig.show()
|
|
|
|
def generate_grafico_torri_mensile_df(dataframe, graphTitle):
|
|
# Crea il grafico a colonne mensili con colori diversi
|
|
fig = px.bar(
|
|
dataframe,
|
|
x='Mese',
|
|
y='gen_pv_100_kWp',
|
|
color='Mese',
|
|
title='Produttività Fotovoltaica Mensile',
|
|
labels={'gen_pv_100_kWp': 'Energia [kWh]', 'Mese': 'Mese'},
|
|
color_discrete_sequence=px.colors.qualitative.Pastel
|
|
)
|
|
fig.show()
|
|
|
|
def export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hourly):
|
|
"""
|
|
Esporta la produttività fotovoltaica aggregata su base oraria.
|
|
"""
|
|
# Raggruppa per ora e somma la produzione dei 4 quarti d'ora
|
|
df_hourly = result_ac_energies_to_csv_df.resample('H').sum()
|
|
df_hourly.to_csv(path_export_hourly, encoding='utf-8')
|
|
print(f"File CSV orario salvato in: {path_export_hourly}")
|
|
return df_hourly
|
|
|
|
def genera_giornaliero():
|
|
# Carica il file CSV orario
|
|
df = pd.read_csv('files/gen_pv/output_gen_pv_hourly.csv', index_col=0, parse_dates=True)
|
|
|
|
# Raggruppa per giorno e somma la produzione
|
|
df_daily = df.resample('D').sum()
|
|
|
|
# Crea il grafico giornaliero
|
|
fig = px.line(
|
|
df_daily,
|
|
x=df_daily.index,
|
|
y='gen_pv_100_kWp',
|
|
title='Produttività Fotovoltaica Giornaliera',
|
|
labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data'}
|
|
)
|
|
fig.show()
|
|
|
|
# Raggruppa per mese e somma la produzione
|
|
df_monthly = df.resample('M').sum()
|
|
df_monthly['Mese'] = df_monthly.index.strftime('%B %Y') # Nome mese e anno
|
|
|
|
|
|
# Estrai tutte le date disponibili (solo la parte di data, senza ora)
|
|
date_options = df.index.normalize().unique()
|
|
|
|
# Crea una lista di grafici, uno per ogni giorno
|
|
fig = go.Figure()
|
|
|
|
for date in date_options:
|
|
daily_data = df[df.index.normalize() == date]
|
|
fig.add_trace(
|
|
go.Scatter(
|
|
x=daily_data.index,
|
|
y=daily_data['gen_pv_100_kWp'],
|
|
name=str(date.date()),
|
|
visible=False
|
|
)
|
|
)
|
|
|
|
# Rendi visibile solo il primo giorno all'avvio
|
|
fig.data[0].visible = True
|
|
|
|
# Crea i pulsanti per il menu a tendina
|
|
buttons = []
|
|
for i, date in enumerate(date_options):
|
|
visible = [False] * len(date_options)
|
|
visible[i] = True
|
|
buttons.append(
|
|
dict(
|
|
label=str(date.date()),
|
|
method="update",
|
|
args=[{"visible": visible},
|
|
{"title": f"Produttività Fotovoltaica Oraria - {date.date()}"}]
|
|
)
|
|
)
|
|
|
|
fig.update_layout(
|
|
updatemenus=[
|
|
dict(
|
|
active=0,
|
|
buttons=buttons,
|
|
x=0.5,
|
|
xanchor="center",
|
|
y=1.15,
|
|
yanchor="top"
|
|
)
|
|
],
|
|
title=f"Produttività Fotovoltaica Oraria - {date_options[0].date()}",
|
|
xaxis_title="Ora",
|
|
yaxis_title="Energia [kWh]"
|
|
)
|
|
fig.show()
|
|
return df_monthly
|
|
|
|
# Scegli il percorso per il nuovo file orario
|
|
path_export_hourly = path_export.replace('.csv', '_hourly.csv')
|
|
|
|
# Esporta il file orario
|
|
df_hourly = export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hourly)
|
|
|
|
# ES HORA DI ESEGUIRE LE FUNZIONIIIIS
|
|
generate_grafico_barrette_df(result_ac_energies_to_csv_df, "Produttività Fotovoltaica per kWp")
|
|
generate_grafico_barrette_df(df_hourly, "Produttività Fotovoltaica su Base Oraria")
|
|
generate_grafico_torri_mensile_df(genera_giornaliero(), "Produttività Fotovoltaica Mensile")
|
|
|
|
if joePlaying:
|
|
joe.terminate()
|
|
joe.kill() |