首页 > 其他分享 >如何在仿真分析,预测中 应用风力发电、光伏发电数据、用电负荷数据集,构建一个全面的时间序列分析和预测系统,包括数据加载、预处理、可视化、时间序列分解以及负荷、光伏和风电功率预测

如何在仿真分析,预测中 应用风力发电、光伏发电数据、用电负荷数据集,构建一个全面的时间序列分析和预测系统,包括数据加载、预处理、可视化、时间序列分解以及负荷、光伏和风电功率预测

时间:2025-01-19 11:33:26浏览次数:3  
标签:plt 预测 负荷 df solar 光伏 path csv data

风力发电、光伏发电数据、用电负荷数据集,用于仿真分析,预测等

在这里插入图片描述

[1]光伏数据,光伏出力
年光伏数据集,包含光伏发电功率、多种类型光照辐射强度数据(DNI,DHI,GHI),附带多种数据,
可用于光伏场景生成与缩减、光伏特性分析、光伏优化调度等。
在这里插入图片描述

[2]光伏预测功率数据2007-2020
光伏预测功率数据,包括预测辐射强度和预测出力,步长15分钟。
在这里插入图片描述
在这里插入图片描述

[3]风电机组和风电场数据2019 1.1-1.15
年风电机组出力数据集,5分钟一个点,可用于风电场景生成与缩减,优化配置。
年地区风电场数据集,步长5分钟。
在这里插入图片描述

负荷数据2016-2018
年负荷数据集,步长15分钟,可用于负荷预测、聚类、仿真分析。

以下内容及代码仅供参考:
好的,您提供了多个不同类型的数据集,这些数据集可以用于仿真分析、预测等多种应用场景。下面我将详细介绍如何应用这些数据集,并提供一些示例代码和步骤来帮助您进行数据分析和建模。

数据集概述

  1. 光伏数据(光伏发电功率、多种类型光照辐射强度数据)

    • 包含:光伏发电功率、DNI(直接法线辐照度)、DHI(漫射水平辐照度)、GHI(全球水平辐照度)
    • 应用场景:光伏场景生成与缩减、光伏特性分析、光伏优化调度
  2. 光伏预测功率数据(2007-2020)

    • 包含:预测辐射强度和预测出力
    • 步长:15分钟
    • 应用场景:光伏功率预测
  3. 风电机组和风电场数据(2019 1.1-1.15)

    • 包含:年风电机组出力数据(步长5分钟)、地区风电场数据(步长5分钟)
    • 应用场景:风电场景生成与缩减、优化配置
  4. 负荷数据(2016-2018)

    • 包含:用电负荷数据
    • 步长:15分钟
    • 应用场景:负荷预测、聚类、仿真分析

环境准备

首先,我们需要安装必要的库。您可以使用以下命令来设置环境:

pip install pandas numpy matplotlib scikit-learn statsmodels pyarrow prophet

数据加载与预处理

我们将使用 pandas 来加载和预处理数据。以下是数据加载和预处理的脚本 data_preprocessing.py:

[<title="Data Preprocessing Script for Wind, Solar, and Load Data">]
import pandas as pd
import os

# Define paths
base_path = 'datasets'
solar_data_path = os.path.join(base_path, 'solar_power_data.csv')
solar_forecast_path = os.path.join(base_path, 'solar_forecast_data.csv')
wind_turbine_path = os.path.join(base_path, 'wind_turbine_data.csv')
load_data_path = os.path.join(base_path, 'load_data.csv')

# Load solar power data
solar_power_df = pd.read_csv(solar_data_path, parse_dates=['timestamp'], index_col='timestamp')
print("Solar Power Data Loaded:")
print(solar_power_df.head())

# Load solar forecast data
solar_forecast_df = pd.read_csv(solar_forecast_path, parse_dates=['timestamp'], index_col='timestamp')
print("\nSolar Forecast Data Loaded:")
print(solar_forecast_df.head())

# Load wind turbine data
wind_turbine_df = pd.read_csv(wind_turbine_path, parse_dates=['timestamp'], index_col='timestamp')
print("\nWind Turbine Data Loaded:")
print(wind_turbine_df.head())

# Load load data
load_data_df = pd.read_csv(load_data_path, parse_dates=['timestamp'], index_col='timestamp')
print("\nLoad Data Loaded:")
print(load_data_df.head())

# Save preprocessed data
preprocessed_base_path = 'preprocessed_datasets'
os.makedirs(preprocessed_base_path, exist_ok=True)

solar_power_df.to_csv(os.path.join(preprocessed_base_path, 'solar_power_data.csv'))
solar_forecast_df.to_csv(os.path.join(preprocessed_base_path, 'solar_forecast_data.csv'))
wind_turbine_df.to_csv(os.path.join(preprocessed_base_path, 'wind_turbine_data.csv'))
load_data_df.to_csv(os.path.join(preprocessed_base_path, 'load_data.csv'))

print("\nPreprocessed data saved to:", preprocessed_base_path)

数据可视化

接下来,我们可以通过可视化来更好地理解数据。以下是数据可视化的脚本 data_visualization.py:

[<title="Data Visualization Script for Wind, Solar, and Load Data">]
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Define paths
preprocessed_base_path = 'preprocessed_datasets'
solar_power_path = os.path.join(preprocessed_base_path, 'solar_power_data.csv')
solar_forecast_path = os.path.join(preprocessed_base_path, 'solar_forecast_data.csv')
wind_turbine_path = os.path.join(preprocessed_base_path, 'wind_turbine_data.csv')
load_data_path = os.path.join(preprocessed_base_path, 'load_data.csv')

# Load preprocessed data
solar_power_df = pd.read_csv(solar_power_path, parse_dates=['timestamp'], index_col='timestamp')
solar_forecast_df = pd.read_csv(solar_forecast_path, parse_dates=['timestamp'], index_col='timestamp')
wind_turbine_df = pd.read_csv(wind_turbine_path, parse_dates=['timestamp'], index_col='timestamp')
load_data_df = pd.read_csv(load_data_path, parse_dates=['timestamp'], index_col='timestamp')

# Plot solar power data
plt.figure(figsize=(14, 7))
plt.plot(solar_power_df.index, solar_power_df['power_output'], label='Power Output', color='orange')
plt.title('Solar Power Output Over Time')
plt.xlabel('Timestamp')
plt.ylabel('Power Output (kW)')
plt.legend()
plt.grid(True)
plt.show()

# Plot solar forecast data
plt.figure(figsize=(14, 7))
plt.plot(solar_forecast_df.index, solar_forecast_df['predicted_radiance'], label='Predicted Radiance', color='blue')
plt.plot(solar_forecast_df.index, solar_forecast_df['predicted_power'], label='Predicted Power', color='green')
plt.title('Solar Forecast Data Over Time')
plt.xlabel('Timestamp')
plt.ylabel('Value')
plt.legend()
plt.grid(True)
plt.show()

# Plot wind turbine data
plt.figure(figsize=(14, 7))
plt.plot(wind_turbine_df.index, wind_turbine_df['turbine_output'], label='Turbine Output', color='purple')
plt.title('Wind Turbine Output Over Time')
plt.xlabel('Timestamp')
plt.ylabel('Power Output (kW)')
plt.legend()
plt.grid(True)
plt.show()

# Plot load data
plt.figure(figsize=(14, 7))
plt.plot(load_data_df.index, load_data_df['load'], label='Electricity Load', color='red')
plt.title('Electricity Load Over Time')
plt.xlabel('Timestamp')
plt.ylabel('Load (kW)')
plt.legend()
plt.grid(True)
plt.show()

时间序列分解

我们可以使用时间序列分解来分析数据的趋势、季节性和残差部分。以下是时间序列分解的脚本 time_series_decomposition.py:

[<title="Time Series Decomposition Script for Wind, Solar, and Load Data">]
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.seasonal import seasonal_decompose

# Define paths
preprocessed_base_path = 'preprocessed_datasets'
solar_power_path = os.path.join(preprocessed_base_path, 'solar_power_data.csv')
solar_forecast_path = os.path.join(preprocessed_base_path, 'solar_forecast_data.csv')
wind_turbine_path = os.path.join(preprocessed_base_path, 'wind_turbine_data.csv')
load_data_path = os.path.join(preprocessed_base_path, 'load_data.csv')

# Load preprocessed data
solar_power_df = pd.read_csv(solar_power_path, parse_dates=['timestamp'], index_col='timestamp')
solar_forecast_df = pd.read_csv(solar_forecast_path, parse_dates=['timestamp'], index_col='timestamp')
wind_turbine_df = pd.read_csv(wind_turbine_path, parse_dates=['timestamp'], index_col='timestamp')
load_data_df = pd.read_csv(load_data_path, parse_dates=['timestamp'], index_col='timestamp')

# Resample data to daily frequency for decomposition
solar_daily = solar_power_df.resample('D').mean()
wind_daily = wind_turbine_df.resample('D').mean()
load_daily = load_data_df.resample('D').mean()

# Perform time series decomposition for solar power
decomposition_solar = seasonal_decompose(solar_daily['power_output'], model='additive', period=365)
fig = decomposition_solar.plot()
fig.suptitle('Solar Power Daily Decomposition')
plt.show()

# Perform time series decomposition for wind turbine
decomposition_wind = seasonal_decompose(wind_daily['turbine_output'], model='additive', period=365)
fig = decomposition_wind.plot()
fig.suptitle('Wind Turbine Daily Decomposition')
plt.show()

# Perform time series decomposition for load
decomposition_load = seasonal_decompose(load_daily['load'], model='additive', period=365)
fig = decomposition_load.plot()
fig.suptitle('Load Daily Decomposition')
plt.show()

负荷预测

我们可以使用Prophet来进行负荷预测。以下是负荷预测的脚本 load_forecasting.py:

[<title="Load Forecasting Script using Prophet">]
import pandas as pd
from fbprophet import Prophet
import matplotlib.pyplot as plt

# Define paths
preprocessed_base_path = 'preprocessed_datasets'
load_data_path = os.path.join(preprocessed_base_path, 'load_data.csv')

# Load preprocessed data
load_data_df = pd.read_csv(load_data_path, parse_dates=['timestamp'], index_col='timestamp')

# Prepare data for Prophet
df_prophet = load_data_df.reset_index().rename(columns={'timestamp': 'ds', 'load': 'y'})

# Initialize and fit the model
model = Prophet(daily_seasonality=False, weekly_seasonality=True, yearly_seasonality=True)
model.fit(df_prophet)

# Make future predictions
future = model.make_future_dataframe(periods=30*24*4, freq='15min')  # Predict for the next month
forecast = model.predict(future)

# Plot the forecast
fig = model.plot(forecast)
plt.title('Load Forecast Using Prophet')
plt.xlabel('Date')
plt.ylabel('Load (kW)')
plt.show()

# Plot components
fig_components = model.plot_components(forecast)
plt.show()

光伏功率预测

我们可以使用Prophet来进行光伏功率预测。以下是光伏功率预测的脚本 solar_power_forecasting.py:

[<title="Solar Power Forecasting Script using Prophet">]
import pandas as pd
from fbprophet import Prophet
import matplotlib.pyplot as plt

# Define paths
preprocessed_base_path = 'preprocessed_datasets'
solar_power_path = os.path.join(preprocessed_base_path, 'solar_power_data.csv')

# Load preprocessed data
solar_power_df = pd.read_csv(solar_power_path, parse_dates=['timestamp'], index_col='timestamp')

# Prepare data for Prophet
df_prophet = solar_power_df.reset_index().rename(columns={'timestamp': 'ds', 'power_output': 'y'})

# Initialize and fit the model
model = Prophet(daily_seasonality=False, weekly_seasonality=True, yearly_seasonality=True)
model.fit(df_prophet)

# Make future predictions
future = model.make_future_dataframe(periods=30*24*4, freq='15min')  # Predict for the next month
forecast = model.predict(future)

# Plot the forecast
fig = model.plot(forecast)
plt.title('Solar Power Forecast Using Prophet')
plt.xlabel('Date')
plt.ylabel('Power Output (kW)')
plt.show()

# Plot components
fig_components = model.plot_components(forecast)
plt.show()

风电功率预测

我们可以使用Prophet来进行风电功率预测。以下是风电功率预测的脚本 wind_power_forecasting.py:

[<title="Wind Power Forecasting Script using Prophet">]
import pandas as pd
from fbprophet import Prophet
import matplotlib.pyplot as plt

# Define paths
preprocessed_base_path = 'preprocessed_datasets'
wind_turbine_path = os.path.join(preprocessed_base_path, 'wind_turbine_data.csv')

# Load preprocessed data
wind_turbine_df = pd.read_csv(wind_turbine_path, parse_dates=['timestamp'], index_col='timestamp')

# Prepare data for Prophet
df_prophet = wind_turbine_df.reset_index().rename(columns={'timestamp': 'ds', 'turbine_output': 'y'})

# Initialize and fit the model
model = Prophet(daily_seasonality=False, weekly_seasonality=True, yearly_seasonality=True)
model.fit(df_prophet)

# Make future predictions
future = model.make_future_dataframe(periods=30*24*12, freq='5min')  # Predict for the next month
forecast = model.predict(future)

# Plot the forecast
fig = model.plot(forecast)
plt.title('Wind Power Forecast Using Prophet')
plt.xlabel('Date')
plt.ylabel('Power Output (kW)')
plt.show()

# Plot components
fig_components = model.plot_components(forecast)
plt.show()

使用说明

  1. 配置路径

    • 确保 datasets 目录结构正确,并且包含所有CSV文件。
    • 确保所有文件名和路径与脚本中的路径一致。
  2. 运行脚本

    • 在终端中运行 data_preprocessing.py 脚本来加载和预处理数据。
    • 在终端中运行 data_visualization.py 来可视化数据。
    • 在终端中运行 time_series_decomposition.py 来进行时间序列分解。
    • 在终端中运行 load_forecasting.py 来进行负荷预测。
    • 在终端中运行 solar_power_forecasting.py 来进行光伏功率预测。
    • 在终端中运行 wind_power_forecasting.py 来进行风电功率预测。
  3. 注意事项

    • 确保所有必要的工具箱已安装,特别是 pandas, matplotlib, seaborn, statsmodels, 和 prophet
    • 根据需要调整参数,如 periodsfreq

示例

假设您的数据文件夹结构如下:

datasets/
├── solar_power_data.csv
├── solar_forecast_data.csv
├── wind_turbine_data.csv
└── load_data.csv

并且每个CSV文件包含相应的列(例如,timestamp, power_output, predicted_radiance, predicted_power, turbine_output, load)。运行上述脚本后,您可以查看各种图表和预测结果。

标签:plt,预测,负荷,df,solar,光伏,path,csv,data
From: https://blog.csdn.net/2401_86822270/article/details/145104694

相关文章