Compare commits
10 Commits
ca10254c52
...
651833b521
Author | SHA1 | Date | |
---|---|---|---|
651833b521 | |||
3bc2478cd9 | |||
b79ffb2416 | |||
c0a7b5beff | |||
ed58e34e7e | |||
88240280ca | |||
09ef44fc21 | |||
f7afee2a64 | |||
90c96a512a | |||
3cc208035a |
62
EnergySystem.py
Normal file
62
EnergySystem.py
Normal file
@ -0,0 +1,62 @@
|
||||
from config import pv_config, ess_config, grid_config
|
||||
import pandas as pd
|
||||
class EnergySystem:
|
||||
def __init__(self, pv_type: pv_config, ess_type: ess_config, grid_type: grid_config):
|
||||
self.pv = pv_type
|
||||
self.ess = ess_type
|
||||
self.grid = grid_type
|
||||
|
||||
# 优先使用PV供电给工厂 - 如果PV输出能满足工厂的需求,则直接供电,多余的电能用来给ESS充电。
|
||||
# PV不足时使用ESS补充 - 如果PV输出不足以满足工厂需求,首先从ESS获取所需电量。
|
||||
# 如果ESS也不足以满足需求,再从电网获取 - 当ESS中的存储电量也不足以补充时,再从电网购买剩余所需电量。
|
||||
def simulate(self, data, time_interval):
|
||||
total_benefit = 0
|
||||
for index, row in data.iterrows():
|
||||
time = row['time']
|
||||
sunlight_intensity = row['sunlight']
|
||||
factory_demand = row['demand']
|
||||
# electricity_price = self.grid.get_price_for_time(time)
|
||||
electricity_price = row['price']
|
||||
|
||||
generated_pv_power = self.pv.capacity * sunlight_intensity # 生成的功率,单位 kW
|
||||
generated_pv_energy = generated_pv_power * time_interval * self.pv.loss # 生成的能量,单位 kWh
|
||||
# pv生成的能量如果比工厂的需求要大
|
||||
if generated_pv_energy >= factory_demand * time_interval:
|
||||
# 剩余的能量(kwh) = pv生成的能量 - 工厂需求的功率 * 时间间隔
|
||||
surplus_energy = generated_pv_energy - factory_demand * time_interval
|
||||
# 要充到ess中的能量 = min(剩余的能量,ess的充电功率*时间间隔(ess在时间间隔内能充进的电量),ess的容量-ess储存的能量(ess中能冲进去的电量))
|
||||
charge_to_ess = min(surplus_energy, self.ess.charge_power * time_interval, self.ess.capacity - self.ess.storage)
|
||||
self.ess.storage += charge_to_ess
|
||||
surplus_after_ess = surplus_energy - charge_to_ess
|
||||
# 如果还有电量盈余,且pv功率大于ess的充电功率+工厂的需求功率则准备卖电
|
||||
if surplus_after_ess > 0 and generated_pv_power > self.ess.charge_power + factory_demand:
|
||||
sold_to_grid = surplus_after_ess
|
||||
sell_income = sold_to_grid * self.grid.sell_price
|
||||
total_benefit += sell_income
|
||||
# 节省的能量 = 工厂需求的能量 * 时间段
|
||||
total_energy = factory_demand * time_interval
|
||||
# pv比工厂的需求小
|
||||
else:
|
||||
# 从ess中需要的电量 = 工厂需要的电量 - pv中的电量
|
||||
needed_from_ess = factory_demand * time_interval - generated_pv_energy
|
||||
# 如果ess中村的电量比需要的多
|
||||
if self.ess.storage >= needed_from_ess:
|
||||
# 取出电量
|
||||
discharging_power = min(self.ess.discharge_power * time_interval, needed_from_ess)
|
||||
self.ess.storage -= discharging_power
|
||||
# 生下来的能量 = pv的能量 + 放出来的能量
|
||||
total_energy = generated_pv_energy + discharging_power
|
||||
else:
|
||||
total_energy = generated_pv_energy + self.ess.storage
|
||||
self.ess.storage = 0
|
||||
needed_from_grid = factory_demand * time_interval - total_energy
|
||||
net_grid = min(self.grid.capacity * time_interval, needed_from_grid) * self.grid.loss
|
||||
# total_energy += net_grid
|
||||
# print(total_energy)
|
||||
# 工厂需求量-总能量
|
||||
# unmet_demand = max(0, factory_demand * time_interval - total_energy)
|
||||
# benefit = (total_energy - unmet_demand) * electricity_price
|
||||
benefit = (total_energy) * electricity_price
|
||||
total_benefit += benefit
|
||||
|
||||
return total_benefit
|
BIN
PV&PowerConsumptionData.xlsx
Normal file
BIN
PV&PowerConsumptionData.xlsx
Normal file
Binary file not shown.
35038
combined_data.csv
Normal file
35038
combined_data.csv
Normal file
File diff suppressed because it is too large
Load Diff
21
config.py
21
config.py
@ -1,23 +1,26 @@
|
||||
import pandas as pd
|
||||
class pv_config:
|
||||
def __init__(self, capacity, cost_per_kW, pv_lifetime, pv_loss):
|
||||
def __init__(self, capacity, cost_per_kW, lifetime, loss):
|
||||
self.capacity = capacity
|
||||
self.cost_per_kW = cost_per_kW
|
||||
self.pv_lifetime = pv_lifetime
|
||||
self.pv_loss = pv_loss
|
||||
self.lifetime = lifetime
|
||||
self.loss = loss
|
||||
class ess_config:
|
||||
def __init__(self, capacity, cost_per_kW, ess_lifetime, ess_loss, charge_power, discharge_power):
|
||||
def __init__(self, capacity, cost_per_kW, lifetime, loss, charge_power, discharge_power):
|
||||
self.capacity = capacity
|
||||
self.cost_per_kW = cost_per_kW
|
||||
self.ess_lifetime = ess_lifetime
|
||||
self.ess_loss = ess_loss
|
||||
self.ess_storage = 0
|
||||
self.lifetime = lifetime
|
||||
self.loss = loss
|
||||
self.storage = 0
|
||||
self.charge_power = charge_power
|
||||
self.discharge_power = discharge_power
|
||||
|
||||
class grid_config:
|
||||
def __init__(self, price_schedule, grid_loss):
|
||||
self.price_schedule = price_schedule
|
||||
def __init__(self, capacity, grid_loss, sell_price):
|
||||
# self.price_schedule = price_schedule
|
||||
self.loss = grid_loss
|
||||
self.sell_price = sell_price
|
||||
self.capacity = capacity
|
||||
|
||||
def get_price_for_time(self, time):
|
||||
hour, minute = map(int, time.split(':'))
|
||||
|
35041
electricity_price_data.csv
Normal file
35041
electricity_price_data.csv
Normal file
File diff suppressed because it is too large
Load Diff
BIN
factory_power.xlsx
Normal file
BIN
factory_power.xlsx
Normal file
Binary file not shown.
56
generatedata.py
Normal file
56
generatedata.py
Normal file
@ -0,0 +1,56 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
# 设置随机种子以重现结果
|
||||
np.random.seed(43)
|
||||
|
||||
def simulate_sunlight(hour, month):
|
||||
# 假设最大日照强度在正午,根据月份调整最大日照强度
|
||||
max_intensity = 1.0 # 夏季最大日照强度
|
||||
if month in [12, 1, 2]: # 冬季
|
||||
max_intensity = 0.6
|
||||
elif month in [3, 4, 10, 11]: # 春秋
|
||||
max_intensity = 0.8
|
||||
|
||||
# 计算日照强度,模拟早晚日照弱,中午日照强
|
||||
intensity = max_intensity * np.sin(np.pi * (hour - 6) / 12)**2 if 6 <= hour <= 18 else 0
|
||||
return intensity
|
||||
|
||||
def simulate_factory_demand(hour, day_of_week):
|
||||
# 周末工厂需求可能减少
|
||||
if day_of_week in [5, 6]: # 周六和周日
|
||||
base_demand = 3000
|
||||
else:
|
||||
base_demand = 6000
|
||||
|
||||
# 日常波动
|
||||
if 8 <= hour <= 20:
|
||||
return base_demand + np.random.randint(100, 200) # 白天需求量大
|
||||
else:
|
||||
return base_demand - np.random.randint(0, 100) # 夜间需求量小
|
||||
|
||||
def generate_data(days=10):
|
||||
records = []
|
||||
month_demand = 0
|
||||
for day in range(days):
|
||||
month = (day % 365) // 30 + 1
|
||||
day_of_week = day % 7
|
||||
day_demand = 0
|
||||
for hour in range(24):
|
||||
for minute in [0, 10, 20, 30, 40, 50]:
|
||||
time = f'{hour:02d}:{minute:02d}'
|
||||
sunlight = simulate_sunlight(hour, month)
|
||||
demand = simulate_factory_demand(hour, day_of_week)
|
||||
day_demand+=demand
|
||||
records.append({'time': time, 'sunlight': sunlight, 'demand': demand})
|
||||
print(f"day:{day}, day_demand: {day_demand}")
|
||||
month_demand += day_demand
|
||||
if day%30 == 0:
|
||||
print(f"month:{month}, month_demand:{month_demand}")
|
||||
month_demand = 0
|
||||
return pd.DataFrame(records)
|
||||
|
||||
# 生成数据
|
||||
data = generate_data(365) # 模拟一年的数据
|
||||
data.to_csv('simulation_data.csv', index=False)
|
||||
print("Data generated and saved to simulation_data.csv.")
|
24
generatepriceschedule.py
Normal file
24
generatepriceschedule.py
Normal file
@ -0,0 +1,24 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def generate_price_schedule():
|
||||
records = []
|
||||
# 假设一天分为三个时段:谷时、平时、峰时
|
||||
times = [('00:00', '06:00', 0.25),
|
||||
('06:00', '18:00', 0.3),
|
||||
('18:00', '24:00', 0.35)]
|
||||
|
||||
# 随机调整每天的电价以增加现实性
|
||||
for time_start, time_end, base_price in times:
|
||||
# 随机浮动5%以内
|
||||
fluctuation = np.random.uniform(-0.005, 0.005)
|
||||
price = round(base_price + fluctuation, 3)
|
||||
records.append({'time_start': time_start, 'time_end': time_end, 'price': price})
|
||||
|
||||
return pd.DataFrame(records)
|
||||
|
||||
# 生成电价计划
|
||||
price_schedule = generate_price_schedule()
|
||||
price_schedule.to_csv('price_schedule.csv', index=False)
|
||||
print("Price schedule generated and saved to price_schedule.csv.")
|
||||
print(price_schedule)
|
604
main.ipynb
Normal file
604
main.ipynb
Normal file
File diff suppressed because one or more lines are too long
72
main.py
72
main.py
@ -1 +1,71 @@
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from EnergySystem import EnergySystem
|
||||
from config import pv_config, grid_config, ess_config
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
data = pd.read_csv('combined_data.csv')
|
||||
time_interval = 15 / 60
|
||||
|
||||
pv_loss = 0.95
|
||||
pv_cost_per_kW = 200
|
||||
pv_base = 50000
|
||||
pv_lifetime = 25
|
||||
|
||||
ess_loss = 0.95
|
||||
ess_cost_per_kW = 300
|
||||
ess_base = 50000
|
||||
ess_lifetime = 25
|
||||
|
||||
grid_loss = 0.95
|
||||
sell_price = 0.4 #kWh
|
||||
grid_capacity = 5000 #kWh
|
||||
|
||||
|
||||
pv_step=10000
|
||||
ess_step=10000
|
||||
|
||||
pv_capacities = np.linspace(50000, 150000, 11)
|
||||
ess_capacities = np.linspace(50000, 150000, 11)
|
||||
results = pd.DataFrame(index=pv_capacities, columns = ess_capacities)
|
||||
for pv_capacity in pv_capacities:
|
||||
print(f"pv_capacity:{pv_capacity}")
|
||||
for ess_capacity in ess_capacities:
|
||||
print(f"ess_capacity:{ess_capacity}")
|
||||
pv = pv_config(capacity=pv_capacity,
|
||||
cost_per_kW=pv_cost_per_kW,
|
||||
lifetime=pv_lifetime,
|
||||
loss=pv_loss)
|
||||
ess = ess_config(capacity=ess_capacity,
|
||||
cost_per_kW=ess_cost_per_kW,
|
||||
lifetime=ess_lifetime,
|
||||
loss=ess_loss,
|
||||
charge_power=ess_capacity,
|
||||
discharge_power=ess_capacity)
|
||||
grid = grid_config(capacity=grid_capacity,
|
||||
grid_loss=grid_loss,
|
||||
sell_price= sell_price)
|
||||
energySystem = EnergySystem(pv_type=pv,
|
||||
ess_type=ess,
|
||||
grid_type= grid)
|
||||
benefit = energySystem.simulate(data, time_interval)
|
||||
results.loc[pv_capacity,ess_capacity] = benefit
|
||||
results = results.astype(float)
|
||||
|
||||
plt.figure(figsize=(10, 8)) # 设置图形大小
|
||||
sns.heatmap(results, annot=True, fmt=".1f", cmap='viridis')
|
||||
plt.title('Benefit Heatmap Based on PV and ESS Capacities')
|
||||
plt.xlabel('ESS Capacity (kWh)')
|
||||
plt.ylabel('PV Capacity (kW)')
|
||||
plt.show()
|
||||
|
||||
# pv = pv_config(capacity=100000,cost_per_kW=200,lifetime=25,loss=0.95)
|
||||
# ess = ess_config(capacity=100000,cost_per_kW=300,lifetime=25,loss=0.95,charge_power=100000,discharge_power=100000)
|
||||
# grid = grid_config(price_schedule=price_schedule, capacity=5000, grid_loss=0.95, sell_price=0.4)
|
||||
# grid = grid_config(capacity=50000, grid_loss=0.95, sell_price=0.4)
|
||||
|
||||
|
||||
# print(benefit)
|
19
old/generate_electricity_price.py
Normal file
19
old/generate_electricity_price.py
Normal file
@ -0,0 +1,19 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
start_date = '2023-01-01'
|
||||
end_date = '2024-01-01'
|
||||
|
||||
# 创建时间索引
|
||||
time_index = pd.date_range(start=start_date, end=end_date, freq='15min')
|
||||
|
||||
# 生成电价数据,假设电价在0.28到0.32欧元/kWh之间波动
|
||||
price_data = np.random.uniform(0.28, 0.32, len(time_index))
|
||||
|
||||
# 创建DataFrame
|
||||
price_df = pd.DataFrame(data={'Time': time_index, 'ElectricityPrice': price_data})
|
||||
|
||||
# 保存到CSV文件
|
||||
price_df.to_csv('electricity_price_data.csv', index=False)
|
||||
|
||||
print("Electricity price data generated and saved.")
|
56
old/generatedata.py
Normal file
56
old/generatedata.py
Normal file
@ -0,0 +1,56 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
# 设置随机种子以重现结果
|
||||
np.random.seed(43)
|
||||
|
||||
def simulate_sunlight(hour, month):
|
||||
# 假设最大日照强度在正午,根据月份调整最大日照强度
|
||||
max_intensity = 1.0 # 夏季最大日照强度
|
||||
if month in [12, 1, 2]: # 冬季
|
||||
max_intensity = 0.6
|
||||
elif month in [3, 4, 10, 11]: # 春秋
|
||||
max_intensity = 0.8
|
||||
|
||||
# 计算日照强度,模拟早晚日照弱,中午日照强
|
||||
intensity = max_intensity * np.sin(np.pi * (hour - 6) / 12)**2 if 6 <= hour <= 18 else 0
|
||||
return intensity
|
||||
|
||||
def simulate_factory_demand(hour, day_of_week):
|
||||
# 周末工厂需求可能减少
|
||||
if day_of_week in [5, 6]: # 周六和周日
|
||||
base_demand = 3000
|
||||
else:
|
||||
base_demand = 6000
|
||||
|
||||
# 日常波动
|
||||
if 8 <= hour <= 20:
|
||||
return base_demand + np.random.randint(100, 200) # 白天需求量大
|
||||
else:
|
||||
return base_demand - np.random.randint(0, 100) # 夜间需求量小
|
||||
|
||||
def generate_data(days=10):
|
||||
records = []
|
||||
month_demand = 0
|
||||
for day in range(days):
|
||||
month = (day % 365) // 30 + 1
|
||||
day_of_week = day % 7
|
||||
day_demand = 0
|
||||
for hour in range(24):
|
||||
for minute in [0, 10, 20, 30, 40, 50]:
|
||||
time = f'{hour:02d}:{minute:02d}'
|
||||
sunlight = simulate_sunlight(hour, month)
|
||||
demand = simulate_factory_demand(hour, day_of_week)
|
||||
day_demand+=demand
|
||||
records.append({'time': time, 'sunlight': sunlight, 'demand': demand})
|
||||
print(f"day:{day}, day_demand: {day_demand}")
|
||||
month_demand += day_demand
|
||||
if day%30 == 0:
|
||||
print(f"month:{month}, month_demand:{month_demand}")
|
||||
month_demand = 0
|
||||
return pd.DataFrame(records)
|
||||
|
||||
# 生成数据
|
||||
data = generate_data(365) # 模拟一年的数据
|
||||
data.to_csv('simulation_data.csv', index=False)
|
||||
print("Data generated and saved to simulation_data.csv.")
|
24
old/generatepriceschedule.py
Normal file
24
old/generatepriceschedule.py
Normal file
@ -0,0 +1,24 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
def generate_price_schedule():
|
||||
records = []
|
||||
# 假设一天分为三个时段:谷时、平时、峰时
|
||||
times = [('00:00', '06:00', 0.25),
|
||||
('06:00', '18:00', 0.3),
|
||||
('18:00', '24:00', 0.35)]
|
||||
|
||||
# 随机调整每天的电价以增加现实性
|
||||
for time_start, time_end, base_price in times:
|
||||
# 随机浮动5%以内
|
||||
fluctuation = np.random.uniform(-0.005, 0.005)
|
||||
price = round(base_price + fluctuation, 3)
|
||||
records.append({'time_start': time_start, 'time_end': time_end, 'price': price})
|
||||
|
||||
return pd.DataFrame(records)
|
||||
|
||||
# 生成电价计划
|
||||
price_schedule = generate_price_schedule()
|
||||
price_schedule.to_csv('price_schedule.csv', index=False)
|
||||
print("Price schedule generated and saved to price_schedule.csv.")
|
||||
print(price_schedule)
|
4
old/price_schedule.csv
Normal file
4
old/price_schedule.csv
Normal file
@ -0,0 +1,4 @@
|
||||
time_start,time_end,price
|
||||
00:00,06:00,0.247
|
||||
06:00,18:00,0.3
|
||||
18:00,24:00,0.349
|
|
52561
old/simulation_data.csv
Normal file
52561
old/simulation_data.csv
Normal file
File diff suppressed because it is too large
Load Diff
52
read_data.py
Normal file
52
read_data.py
Normal file
@ -0,0 +1,52 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import csv
|
||||
|
||||
df_sunlight = pd.read_excel('lightintensity.xlsx', 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_power.xlsx',
|
||||
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)
|
||||
|
||||
df_combined.to_csv('combined_data.csv', index=True, index_label='Time')
|
||||
|
||||
price_data = np.random.uniform(0.3, 0.3, len(times))
|
||||
|
||||
# 创建DataFrame
|
||||
price_df = pd.DataFrame(data={'Time': times, 'ElectricityPrice': price_data})
|
||||
|
||||
price_df.set_index('Time', inplace=True)
|
||||
|
||||
# 保存到CSV文件
|
||||
price_df.to_csv('electricity_price_data.csv', index=True)
|
||||
print(price_df.head())
|
||||
print("Electricity price data generated and saved.")
|
||||
|
||||
df_combined2 = df_combined.join(price_df)
|
||||
print(df_combined2.head())
|
||||
# 保存结果
|
||||
with open('combined_data.csv', 'w', newline='') as file:
|
||||
writer = csv.writer(file)
|
||||
writer.writerow(['time', 'sunlight', 'demand','price'])
|
||||
for index, row in df_combined2.iterrows():
|
||||
time_formatted = index.strftime('%H:%M')
|
||||
writer.writerow([time_formatted, row['SunlightIntensity'], row['FactoryPower'],row['ElectricityPrice']])
|
||||
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.")
|
Loading…
Reference in New Issue
Block a user