|
|
3 өдөр өмнө | |
|---|---|---|
| .. | ||
| __pycache__ | 4 өдөр өмнө | |
| medium_short_term | 3 өдөр өмнө | |
| ultra_short_term | 2 долоо хоног өмнө | |
| .DS_Store | 4 өдөр өмнө | |
| README.md | 3 өдөр өмнө | |
| main.py | 4 өдөр өмнө | |
| requirements.txt | 4 өдөр өмнө | |
本文档说明 forecast-algorithm 中功率预测算法的运行方式,以及通过 main.py 启动 FastAPI 服务并调用预测接口的方法。
| 类型 | 模型 | 输入长度 | 输出长度 | 时间分辨率 | 预测范围 |
|---|---|---|---|---|---|
| 短期 | GRU / v24 | 288 | 288 | 15 分钟 | 3 天 |
| 中期 | GRU / v24 | 960 | 960 | 15 分钟 | 10 天 |
短期和中期预测分别由以下脚本执行:
medium_short_term/scripts/prediction_short.py
medium_short_term/scripts/prediction_medium.py
预测结果写入 PostgreSQL:
短期:data_short_term_power_forecast_raw
中期:data_medium_term_power_forecast_raw
forecast-algorithm/
├── main.py FastAPI 启动入口
├── medium_short_term/
│ ├── requirements.txt Python 依赖
│ ├── model/ 模型结构
│ ├── scripts/
│ │ ├── ModelLoading.py 模型与归一化器加载
│ │ ├── prediction_short.py 短期预测入口
│ │ └── prediction_medium.py 中期预测入口
│ └── saved_model/ 模型权重目录
│ └── <场站>/<模型>/<序列长度>/<特征版本>/
└── ultra_short_term/ 超短期预测
模型目录示例:
medium_short_term/saved_model/JMJD01/GRU/288/v24/
├── best_model.pth
├── best_tpe_params.json
└── scaler.pkl
| 场站代码 | 场站名称 | 装机容量 | 纬度 | 经度 |
|---|---|---|---|---|
| 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
数据库配置位于:
数据库 112.124.19.19:5432/electricitypostgres/ow9NV!lkf
medium_short_term/scripts/prediction_short.py
medium_short_term/scripts/prediction_medium.py
在项目根目录执行:
cd ~/forecast/forecast-algorithm
python main.py
默认监听:
http://0.0.0.0:8000
本机访问:
http://127.0.0.1:8000
接口:
GET /api/v1/power/short
参数:
| 参数 | 必填 | 说明 |
|---|---|---|
projs |
是 | 场站代码,例如 JMJD01 |
init_time |
是 | 上海时间,格式 YYYY-MM-DD HH:MM:SS |
浏览器访问:
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 |
浏览器访问:
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 条