|
|
23 godzin temu | |
|---|---|---|
| .. | ||
| __pycache__ | 23 godzin temu | |
| assets | 23 godzin temu | |
| config | 23 godzin temu | |
| medium_short_term | 23 godzin temu | |
| templates | 23 godzin temu | |
| ultra_short_term | 2 tygodni temu | |
| .DS_Store | 23 godzin temu | |
| README.md | 23 godzin temu | |
| main.py | 23 godzin temu | |
| requirements.txt | 3 dni temu | |
本文档说明
forecast-algorithm中功率预测算法的运行方式,以及通过main.py启动 FastAPI 服务并调用预测接口的方法。

| 类型 | 模型 | 输入长度 | 输出长度 | 时间分辨率 | 预测范围 |
|---|---|---|---|---|---|
| 超短期 | / | / | / | / | / |
| 短期 | GRU / v24 | 288 | 288 | 15 分钟 | 3 天 |
| 中期 | GRU / v24 | 960 | 960 | 15 分钟 | 10 天 |
预测结果写入 PostgreSQL:
超短期:/
短期:data_short_term_power_forecast_raw
中期:data_medium_term_power_forecast_raw
forecast-algorithm/
├── main.py FastAPI 启动入口,提供预测 API 和首页
├── README.md 项目与 API 使用说明
├── requirements.txt 项目通用 Python 依赖
├── config/
│ └── config.yaml 数据库、模型路径和 FastAPI 配置
├── templates/
│ └── api_home.html API 单页使用说明首页
├── assets/
│ └── API_home_page.png API 首页预览图
│
├── medium_short_term/ 短期和中期功率预测
│ ├── README.md 短期/中期预测说明
│ ├── requirements.txt 模型运行依赖
│ ├── base/
│ │ └── base_model.py 模型基类
│ ├── layers/
│ │ └── layers.py 公共网络层
│ ├── model/ 模型结构
│ │ ├── GRU.py
│ │ ├── DLinear.py
│ │ ├── TSMixer.py
│ │ ├── TCN.py
│ │ ├── Mamba.py
│ │ ├── CNN_LSTM.py
│ │ ├── TransformerEn.py
│ │ └── lightbgm.py
│ ├── scripts/
│ │ ├── ModelLoading.py 模型与归一化器加载
│ │ ├── pipeline.py 训练数据处理管线
│ │ ├── prediction_short.py 短期预测入口
│ │ ├── prediction_medium.py 中期预测入口
│ │ └── run.sh 批量预测脚本
│ ├── utils/
│ │ ├── metrics_utils.py 评估指标
│ │ ├── processed.py 数据预处理
│ │ ├── train_utils.py 训练工具
│ │ └── weather_utils.py 气象数据处理
│ ├── test/
│ │ └── prediction_test.py 预测测试脚本
│ └── saved_model/ 模型权重目录
│ └── <场站>/
│ └── <模型>/
│ └── <序列长度>/
│ └── <特征版本>/
│ ├── best_model.pth
│ ├── best_tpe_params.json
│ └── scaler.pkl
│
└── ultra_short_term/ 超短期光伏功率预测
├── README.md 超短期预测说明
├── requirements.txt 超短期预测依赖
├── run.py 超短期预测入口
├── run.sh 运行脚本
├── install.sh 安装脚本
├── ultra_short_pv.py 超短期预测主逻辑
├── pv_inputs.py 输入数据构造
├── pv_io.py 输入输出处理
├── config.json 超短期默认配置
├── deployment_config.json 部署配置
├── input_schema.json 输入数据格式定义
├── SHA256SUMS.json 模型文件校验信息
├── configs/
│ └── sites.yaml 场站配置
├── pv_forecast/
│ ├── __init__.py
│ ├── ec_latest.py 最新 EC 气象数据
│ ├── features.py 特征处理
│ └── mspf_pv/ 光伏预测模型目录
├── models/
│ ├── mspf_pv/ 超短期模型
│ └── mspf_pv_e10a/ 备选模型
├── examples/
│ └── call_model.py 模型调用示例
├── docs/
│ ├── 超短期光伏预测部署文档.docx
│ └── 输入输出与接入说明.md
├── test_data/
│ ├── JMJD01_input.npz
│ ├── JMJD01_reference.npz
│ ├── YUWEI_input.npz
│ ├── YUWEI_reference.npz
│ ├── ZHONGXIN_input.npz
│ └── ZHONGXIN_reference.npz
├── tests/
│ └── test_forecast.py
├── test.sh 测试运行脚本
├── test_deployment.py 部署测试
└── output/ 超短期预测输出与测试日志
| 场站代码 | 场站名称 | 装机容量 | 纬度 | 经度 |
|---|---|---|---|---|
| JMJD01 | 江门光伏场 | 4050 kW | 22.555907 | 113.135232 |
| YUWEI | 北流煜炜光伏场 | 3000 kW | 22.615142 | 110.305066 |
| ZHONGXIN | 清远忠信光伏场 | 2250 kW | 23.542156 | 112.996233 |
| ... |
安装依赖:
# python 3.10
# 1.pytorch 2.6.0+cu124 这里根据客户需求,推理时安装CPU版本也可以的。
# 支持centos / windows
# centos 必须conda安装 conda install pandas,pillow,greenlet
conda create -n oulipower python=3.10 -y
conda activate oulipower
# 2.安装基础环境
python -m pip install -r requirements.txt
# 3.安装CPU版本的Pytorch
#pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cpu
# 3.安装GPU版本的Pytorch
pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu124
python -m pip install fastapi uvicorn psycopg2-binary
python -m pip install -r medium_short_term/requirements.txt
目前是测试数据库,手动导入数据库环境变量
export PGHOST="112.124.19.19"
export PGPORT="5432"
export PGDATABASE="electricity"
export PGUSER="postgres"
export PGPOSSWORD="ow9NV!lkf"
修改配置文件config/config.yaml
FastAPI: # 关于fast api的配置
host: "0.0.0.0"
port: 8000
model: # 关于超短期,短期,中期模型权重和模型脚本路径配置
# 项目路径('/Users/hm/Desktop/forecast/forecast-algorithm')+算法路径('medium_short_term/scripts/prediction_short.py')
short_algorithm_file: '/Users/hm/Desktop/forecast/forecast-algorithm/medium_short_term/scripts/prediction_short.py'
medium_algorithm_file: '/Users/hm/Desktop/forecast/forecast-algorithm/medium_short_term/scripts/prediction_medium.py'
# 项目路径('/Users/hm/Desktop/forecast/forecast-algorithm')+权重路径('medium_short_term/saved_model')
saved_model_root: "/Users/hm/Desktop/forecast/forecast-algorithm/medium_short_term/saved_model"
在forecast-algorithm目录执行:
python main.py
默认监听:
http://0.0.0.0:8000
本机访问:
http://127.0.0.1:8000
访问http://127.0.0.1:8000展示API主页信息

接口:
GET /api/v1/power/short
参数:
| 参数 | 必填 | 说明 |
|---|---|---|
projs |
是 | 场站代码,例如 JMJD01 |
init_time |
是 | 上海时间,格式 YYYY-MM-DD HH:MM:SS |
浏览器访问事例:
预报2026-11-25:08:00:00(北京时间),短期功率预报,结果写入数据库
http://127.0.0.1:8000/api/v1/power/short?projs=JMJD01&init_time=2026-11-25%2008:00:00
短期预测写入数据库:
public.data_short_term_power_forecast_raw
写入记录数:
288 条
接口:
GET /api/v1/power/medium
参数:
| 参数 | 必填 | 说明 |
|---|---|---|
projs |
是 | 场站代码,例如 JMJD01 |
init_time |
是 | 上海时间,格式 YYYY-MM-DD HH:MM:SS |
浏览器访问事例:
预报2026-11-25:08:00:00(北京时间),中期功率预报,结果写入数据库
http://127.0.0.1:8000/api/v1/power/medium?projs=JMJD01&init_time=2026-11-25%2008:00:00
中期预测写入数据库:
public.data_medium_term_power_forecast_raw
写入记录数:
960 条