simple-pv-simulator/read_data.py

47 lines
1.8 KiB
Python
Raw Permalink Normal View History

2024-05-04 09:59:14 +02:00
import pandas as pd
import numpy as np
import csv
import json
2024-05-04 09:59:14 +02:00
with open('config.json', 'r') as f:
js_data = json.load(f)
pv_yield_file_name = js_data["data_path"]["pv_yield"]
print(pv_yield_file_name)
2024-05-13 16:47:56 +02:00
# factory_demand_file_name = 'factory_power1.xlsx'
factory_demand_file_name = js_data["data_path"]["demand"]
print(factory_demand_file_name)
electricity_price_data = js_data["data_path"]["buy"]
print(electricity_price_data)
electricity_price_data_sell = js_data["data_path"]["sell"]
print(electricity_price_data_sell)
2024-05-07 10:27:45 +02:00
2024-05-13 16:26:24 +02:00
pv_df = pd.read_csv(pv_yield_file_name, index_col='Time', usecols=['Time', 'PV yield[kW/kWp]'])
pv_df.index = pd.to_datetime(pv_df.index)
2024-05-04 09:59:14 +02:00
df_power = pd.read_csv(factory_demand_file_name, index_col='Time', usecols=['Time', 'FactoryPower'])
2024-05-13 16:47:56 +02:00
df_power.index = pd.to_datetime(df_power.index)
2024-05-13 16:26:24 +02:00
df_combined = pv_df.join(df_power)
2024-05-04 09:59:14 +02:00
2024-05-10 17:40:54 +02:00
price_df = pd.read_csv(electricity_price_data, index_col='Time', usecols=['Time', 'ElectricityBuy'])
2024-05-10 17:18:41 +02:00
price_df.index = pd.to_datetime(price_df.index)
price_df = price_df.reindex(df_combined.index)
2024-05-10 17:40:54 +02:00
df_combined2 = df_combined.join(price_df)
2024-05-04 09:59:14 +02:00
2024-05-10 17:40:54 +02:00
sell_df = pd.read_csv(electricity_price_data_sell, index_col='Time', usecols=['Time', 'ElectricitySell'])
sell_df.index = pd.to_datetime(sell_df.index)
sell_df = sell_df.reindex(df_combined.index)
df_combined3 = df_combined2.join(sell_df)
2024-05-10 17:18:41 +02:00
2024-05-04 09:59:14 +02:00
with open('combined_data.csv', 'w', newline='') as file:
writer = csv.writer(file)
2024-05-13 16:26:24 +02:00
writer.writerow(['time', 'PV yield[kW/kWp]', 'demand','buy', 'sell'])
2024-05-07 10:27:45 +02:00
cnt = 0
2024-05-10 17:40:54 +02:00
for index, row in df_combined3.iterrows():
2024-05-04 09:59:14 +02:00
time_formatted = index.strftime('%H:%M')
2024-05-13 16:26:24 +02:00
writer.writerow([time_formatted, row['PV yield[kW/kWp]'], row['FactoryPower'],row['ElectricityBuy'], row['ElectricitySell']])
2024-05-07 10:27:45 +02:00
2024-05-04 09:59:14 +02:00
print('The file is written to combined_data.csv')
print("Simulation data with electricity prices has been updated and saved.")