Compare commits
	
		
			5 Commits
		
	
	
		
			9d143399ed
			...
			566ebca6cd
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 566ebca6cd | ||
|  | c8c37b756c | ||
|  | 4f1a47d505 | ||
|  | ad9b5e6a19 | ||
|  | 33871fba77 | 
| @@ -39,7 +39,8 @@ class EnergySystem: | ||||
|         total_gen = 0 | ||||
|         for index, row in data.iterrows(): | ||||
|             time = row['time'] | ||||
|             sunlight_intensity = row['sunlight'] | ||||
|             # sunlight_intensity = row['sunlight'] | ||||
|             pv_yield = row['PV yield[kW/kWp]'] | ||||
|             factory_demand = row['demand'] | ||||
|             electricity_price = row['buy'] | ||||
|             sell_price = row['sell'] | ||||
| @@ -55,7 +56,7 @@ class EnergySystem: | ||||
|                 soc = self.ess.storage / self.ess.capacity | ||||
|                 self.hour_stored_2.append(soc) | ||||
|  | ||||
|             generated_pv_power = self.pv.capacity * sunlight_intensity  # 生成的功率,单位 kW | ||||
|             generated_pv_power = self.pv.capacity * pv_yield# 生成的功率,单位 kW | ||||
|             generated_pv_energy = generated_pv_power * time_interval * self.pv.loss  # 生成的能量,单位 kWh | ||||
|             self.generated += generated_pv_energy | ||||
|             # pv生成的能量如果比工厂的需求要大 | ||||
|   | ||||
							
								
								
									
										45235
									
								
								combined_data.csv
									
									
									
									
									
								
							
							
						
						
									
										45235
									
								
								combined_data.csv
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										35041
									
								
								factory_power1.csv
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35041
									
								
								factory_power1.csv
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										48
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								main.py
									
									
									
									
									
								
							| @@ -1,9 +1,5 @@ | ||||
| #!/usr/bin/env python | ||||
| # coding: utf-8 | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| import os | ||||
| import glob | ||||
| import shutil | ||||
| @@ -28,9 +24,6 @@ folder_path = 'plots' | ||||
| clear_folder_make_ess_pv(folder_path) | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| import matplotlib.pyplot as plt | ||||
| import seaborn as sns | ||||
| import numpy as np | ||||
| @@ -38,10 +31,6 @@ import pandas as pd | ||||
| from EnergySystem import EnergySystem | ||||
| from config import pv_config, grid_config, ess_config | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| import json | ||||
|  | ||||
| print("Version 0.0.5") | ||||
| @@ -49,9 +38,6 @@ print("Version 0.0.5") | ||||
| with open('config.json', 'r') as f: | ||||
|     js_data = json.load(f) | ||||
|  | ||||
|  | ||||
|      | ||||
|  | ||||
| time_interval = js_data["time_interval"]["numerator"] / js_data["time_interval"]["denominator"] | ||||
| print(time_interval) | ||||
|  | ||||
| @@ -132,9 +118,6 @@ plt.savefig('plots/demand.png') | ||||
| plt.close() | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| def draw_results(results, filename, title_benefit, annot_benefit=False, figure_size=(10, 10)): | ||||
|     df=results | ||||
|     df = df.astype(float) | ||||
| @@ -220,10 +203,6 @@ def draw_roi(costs, results, filename, title_roi, days=365, annot_roi=False, fig | ||||
|     plt.ylabel('PV Capacity (MW)') | ||||
|     plt.savefig(filename) | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| def draw_cost(costs, filename, title_cost, annot_cost=False, figure_size=(10, 10)): | ||||
|     df = costs | ||||
|     df = df.astype(int) | ||||
| @@ -255,9 +234,6 @@ def draw_cost(costs, filename, title_cost, annot_cost=False, figure_size=(10, 10 | ||||
|     plt.savefig(filename) | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| def draw_overload(overload_cnt, filename, title_unmet, annot_unmet=False, figure_size=(10, 10), days=365, granularity=15): | ||||
|     df = overload_cnt | ||||
|     print(days, granularity) | ||||
| @@ -305,18 +281,10 @@ def draw_overload(overload_cnt, filename, title_unmet, annot_unmet=False, figure | ||||
|     plt.ylabel('PV Capacity (MW)') | ||||
|     plt.savefig(filename) | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| def cal_profit(es: EnergySystem, saved_money, days): | ||||
|     profit = saved_money - es.ess.get_cost_per_year() / 365 * days - es.pv.get_cost_per_year() / 365 * days | ||||
|     return profit | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| def generate_data(pv_capacity, pv_cost_per_kW, pv_lifetime, pv_loss, ess_capacity, ess_cost_per_kW, ess_lifetime, ess_loss, grid_capacity, grid_loss, sell_price, time_interval, data, days): | ||||
|     pv = pv_config(capacity=pv_capacity,  | ||||
|                     cost_per_kW=pv_cost_per_kW, | ||||
| @@ -341,9 +309,6 @@ def generate_data(pv_capacity, pv_cost_per_kW, pv_lifetime, pv_loss, ess_capacit | ||||
|     return (results, overload_cnt, costs, netto_benefit, gen_energy, energySystem.generated) | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| months_results = [] | ||||
| months_costs = [] | ||||
| months_overload = [] | ||||
| @@ -434,17 +399,11 @@ draw_overload(overload_cnt=annual_overload, | ||||
|                 figure_size=figure_size) | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| def save_data(data, filename): | ||||
|     data.to_csv(filename+'.csv') | ||||
|     data.to_json(filename + '.json') | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| if not os.path.isdir('data'): | ||||
|     os.makedirs('data') | ||||
|  | ||||
| @@ -452,15 +411,8 @@ save_data(annual_result, f'data/{pv_begin}-{pv_end}-{pv_groups}-{ess_begin}-{ess | ||||
| save_data(annual_costs, f'data/{pv_begin}-{pv_end}-{pv_groups}-{ess_begin}-{ess_end}-{ess_groups}-costs') | ||||
| save_data(annual_overload, f'data/{pv_begin}-{pv_end}-{pv_groups}-{ess_begin}-{ess_end}-{ess_groups}-overload_cnt') | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| draw_results(annual_result, 'plots/test.png', 'test', False) | ||||
|  | ||||
|  | ||||
| # In[ ]: | ||||
|  | ||||
|  | ||||
| draw_roi(annual_costs, annual_nettos, 'plots/annual_roi.png',  title_roi, 365, annot_benefit, figure_size) | ||||
|  | ||||
|   | ||||
							
								
								
									
										38
									
								
								read_data.py
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								read_data.py
									
									
									
									
									
								
							| @@ -2,56 +2,38 @@ import pandas as pd | ||||
| import numpy as np | ||||
| import csv | ||||
|  | ||||
| sunlight_file_name = 'lightintensity.xlsx' | ||||
| factory_demand_file_name = 'factory_power1.xlsx' | ||||
| pv_yield_file_name = 'read_data/Serbia.csv' | ||||
| # factory_demand_file_name = 'factory_power1.xlsx' | ||||
| factory_demand_file_name = 'factory_power1.csv' | ||||
| electricity_price_data = 'electricity_price_data.csv' | ||||
| electricity_price_data_sell = 'electricity_price_data_sell.csv' | ||||
|  | ||||
| df_sunlight = pd.read_excel(sunlight_file_name, header=None, names=['SunlightIntensity']) | ||||
|  | ||||
| start_date = '2023-01-01 00:00:00'  # 根据数据的实际开始日期调整 | ||||
| hours = pd.date_range(start=start_date, periods=len(df_sunlight), freq='h') | ||||
| df_sunlight['Time'] = hours | ||||
| df_sunlight.set_index('Time', inplace=True) | ||||
|  | ||||
| df_sunlight_resampled = df_sunlight.resample('15min').interpolate() | ||||
|  | ||||
| df_power = pd.read_excel(factory_demand_file_name,  | ||||
|                          header=None,  | ||||
|                          names=['FactoryPower'],  | ||||
|                          dtype={'FactoryPower': float}) | ||||
| times = pd.date_range(start=start_date, periods=len(df_power), freq='15min') | ||||
| df_power['Time'] = times | ||||
| df_power.set_index('Time',inplace=True) | ||||
| print(df_power.head()) | ||||
|  | ||||
| df_combined = df_sunlight_resampled.join(df_power) | ||||
|  | ||||
| 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) | ||||
|  | ||||
| df_power = pd.read_csv('factory_power1.csv', index_col='Time', usecols=['Time', 'FactoryPower']) | ||||
| df_power.index = pd.to_datetime(df_power.index) | ||||
| df_combined = pv_df.join(df_power) | ||||
|  | ||||
| price_df = pd.read_csv(electricity_price_data, index_col='Time', usecols=['Time', 'ElectricityBuy']) | ||||
| price_df.index = pd.to_datetime(price_df.index) | ||||
| price_df = price_df.reindex(df_combined.index) | ||||
|  | ||||
| print("Electricity price data generated and saved.") | ||||
| df_combined2 = df_combined.join(price_df) | ||||
|  | ||||
| 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) | ||||
|  | ||||
| with open('combined_data.csv', 'w', newline='') as file: | ||||
|     writer = csv.writer(file) | ||||
|     writer.writerow(['time', 'sunlight', 'demand','buy', 'sell']) | ||||
|     writer.writerow(['time', 'PV yield[kW/kWp]', 'demand','buy', 'sell']) | ||||
|     cnt = 0 | ||||
|     for index, row in df_combined3.iterrows(): | ||||
|         time_formatted = index.strftime('%H:%M') | ||||
|         writer.writerow([time_formatted, row['SunlightIntensity'], row['FactoryPower'],row['ElectricityBuy'], row['ElectricitySell']]) | ||||
|         writer.writerow([time_formatted, row['PV yield[kW/kWp]'], row['FactoryPower'],row['ElectricityBuy'], row['ElectricitySell']]) | ||||
|          | ||||
|     print('The file is written to combined_data.csv') | ||||
|  | ||||
| # combined_data.to_csv('updated_simulation_with_prices.csv', index=False) | ||||
|  | ||||
| print("Simulation data with electricity prices has been updated and saved.") | ||||
							
								
								
									
										75
									
								
								read_data/convert_data.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								read_data/convert_data.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,75 @@ | ||||
| #!/usr/bin/env python | ||||
| # coding: utf-8 | ||||
|  | ||||
|  | ||||
| import matplotlib.pyplot as plt | ||||
| import pandas as pd | ||||
| import numpy as np | ||||
| import os | ||||
| import csv | ||||
|  | ||||
| def generate_min_df(mins = 15): | ||||
|     end = 60/mins * 24 | ||||
|     start_date = '2023-01-01' | ||||
|     end_date = '2023-12-31' | ||||
|  | ||||
|     all_dates = pd.date_range(start=start_date, end=end_date, freq='D') | ||||
|     all_times = pd.timedelta_range(start='0 min', end=f'1435 min', freq=f'{mins} min') | ||||
|  | ||||
|     date_times = [pd.Timestamp(date) + time for date in all_dates for time in all_times] | ||||
|  | ||||
|     time_frame = pd.DataFrame({ | ||||
|         'Time': date_times | ||||
|     }) | ||||
|     return time_frame | ||||
|  | ||||
| def save_csv(df, filename, columns): | ||||
|     with open(filename, 'w', newline='') as file: | ||||
|         writer = csv.writer(file) | ||||
|         writer.writerow(['Time', 'PV yield[kW/kWp]']) | ||||
|         for index, row in df.iterrows(): | ||||
|             time_formatted = index.strftime('%H:%M') | ||||
|             writer.writerow([time_formatted, row[columns[1]]]) | ||||
|              | ||||
|         print(f'The file is written to {filename}') | ||||
|  | ||||
| def read_csv(filename): | ||||
|     skip_rows = list(range(1, 17)) | ||||
|     data = pd.read_csv(filename, sep=';', skiprows=skip_rows) | ||||
|     return data | ||||
|  | ||||
| def process(file_name): | ||||
|     df = read_csv(file_name) | ||||
|     city = file_name.split('_')[0] | ||||
|  | ||||
|     remain_column = ['Time','PV energy (AC) minus standby use '] | ||||
|     energy_row_name = remain_column[1] | ||||
|  | ||||
|     df = df[remain_column] | ||||
|     df[energy_row_name] = df[energy_row_name].str.replace(',','.').astype(float) | ||||
|  | ||||
|     sum_energy = df[energy_row_name].sum() | ||||
|     group_size = 15 | ||||
|     df['group_id'] = df.index // group_size | ||||
|  | ||||
|     sums = df.groupby('group_id')[energy_row_name].sum() | ||||
|     sums_df = sums.reset_index(drop=True).to_frame(name = 'Energy') | ||||
|  | ||||
|     time_frame = generate_min_df(15) | ||||
|     sums_df = pd.concat([time_frame, sums_df], axis=1) | ||||
|     sums_df.set_index('Time', inplace=True) | ||||
|     max_value = sums_df['Energy'].max() | ||||
|     sums_df['Energy'] = sums_df['Energy'] / 390. | ||||
|     sums_df['Energy'] = sums_df['Energy'].round(4) | ||||
|     sums_df['Energy'].replace(0.0, -0.0) | ||||
|  | ||||
|     save_csv(sums_df, f'{city}.csv', ['Time', 'Energy']) | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     city_list = ['Riyahd', 'Cambodge', 'Berlin', 'Serbia'] | ||||
|     for city in city_list: | ||||
|         print(f'Processing {city}') | ||||
|         file_name = f'{city}_raw.csv' | ||||
|         process(file_name) | ||||
|         print(f'Processing {city} is done\n') | ||||
|  | ||||
							
								
								
									
										16
									
								
								xlsx2csv.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								xlsx2csv.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| import pandas as pd | ||||
|  | ||||
| excel_file = 'factory_power1.xlsx' | ||||
| sheet_name = 'Sheet1' | ||||
|  | ||||
| df = pd.read_excel(excel_file, sheet_name=sheet_name) | ||||
|  | ||||
| start_date = '2023-01-01' | ||||
| df_power = pd.read_excel(excel_file,  | ||||
|                          header=None,  | ||||
|                          names=['FactoryPower'],  | ||||
|                          dtype={'FactoryPower': float}) | ||||
| times = pd.date_range(start=start_date, periods=len(df_power), freq='15min') | ||||
| df_power['Time'] = times | ||||
| df_power = df_power[['Time', 'FactoryPower']] | ||||
| df_power.to_csv('factory_power1.csv', index=True) | ||||
		Reference in New Issue
	
	Block a user