前言
本次笔记是对第三届世界科学智能大赛航空安全赛道:航空结冰气象要素预报的个人总结,教学资料来源于datawhale春训营。本次笔记的主要内容是一些概念总结,baseline的理解,以及我个人的思考。(今天还可以报名哦,在文章末尾可以在WX扫码报名,全程免费,好处多多,本人参加好多次了,现身说法一下)
赛题背景
航空安全赛道聚焦AI航空结冰气象要素预测,旨在通过历史再分析数据构建预测模型,实现未来三天云水、云冰、云雨、云雪、比湿、温度等要素的精准预测,助力国产大飞机适航认证和全球航线安全运营,为提升飞行经济性与安全性提供创新技术思路。选手需攻克气象条件时间序列预测的复杂性,云水、云冰等要素时空分布不均匀性,极端冰冻事件预测,模型可解释性等关键科学问题,尝试解决航空结冰导致的飞行安全风险。本赛道基于欧洲中期天气预报中心(ECMWF)的再分析数据ERA5,提供全球范围内的高分辨率气象数据支持。
赛事任务
任务目标
建立气象要素预测模型
输出未来三天逐6小时的云水、云冰、云雨、云雪、比湿、温度等气象要素预测结果
注意事项
不允许使用外部数据(提供的训练数据和常量数据除外)。
不允许使用任何公开的预训练模型。
赛题数据集
比赛数据来自欧洲中期天气预报中心(ECMWF)的再分析数据ERA5,使用了ERA5的子集,包含9个气压层变量,每个变量有13个气压层(50, 100, 150, 200, 250, 300, 400, 500, 600, 700, 850, 925, 1000 hPa),共计117个变量,时间间隔6小时,空间分辨率1度,覆盖全球区域。
评价指标
import torch
import os
from pathlib import Path
def get_output_channels_indices():#通道映射构建器
var_groups = {
'z': 0,
't': 13,
'u': 26,
'v': 39,
'q': 52,
'ciwc': 65,
'clwc': 78,
'crwc': 91,
'cswc': 104
}
output_config = [
('t', 200), ('t', 500), ('t', 700), ('t', 850), ('t', 1000),
('q', 200), ('q', 500), ('q', 700), ('q', 850), ('q', 1000),
('ciwc', 200), ('ciwc', 500), ('ciwc', 700), ('ciwc', 850), ('ciwc',1000),
('clwc', 200), ('clwc', 500), ('clwc', 700), ('clwc', 850), ('clwc',1000),
('crwc', 200), ('crwc', 500), ('crwc', 700), ('crwc', 850), ('crwc',1000),
('cswc', 200), ('cswc', 500), ('cswc', 700), ('cswc', 850), ('cswc',1000)
]
pressure_levels = [50, 100, 150, 200, 250, 300, 400, 500, 600,700, 850, 925, 1000]
indices = []
for var, level in output_config:
level_index = pressure_levels.index(level)
global_index = var_groups[var] + level_index
indices.append(global_index)
return indices
def baseline_prediction(input_tensor):#预测核心逻辑
output_channels_indices = get_output_channels_indices()
# (1,117,181,360)
mean_data = input_tensor.squeeze(0).mean(dim=0)
lat_slice = slice(35, 81) # 55N~10N
lon_slice = slice(70, 141) # 70E~140E
# (117,46,71)
cropped_global = mean_data[:, lat_slice, lon_slice]
# (30,46,71)
output_core = cropped_global[output_channels_indices, :, :]
# 12 (1,12,30,46,71)
output = output_core.unsqueeze(0).unsqueeze(0).expand(1, 12, -1, -1, -1)
return output.half() # float16
#批量处理器
def process_files(input_dir="input", output_dir="output"):
Path(output_dir).mkdir(parents=True, exist_ok=True)
for file_name in os.listdir(input_dir):
if not file_name.endswith(".pt"):
contin
#
input_data = torch.load(input_path)
#
prediction = baseline_prediction(input_data)
#
torch.save(prediction, output_path)
print(f": {file_name}")
except Exception as e:
print(f" {file_name}: {str(e)}")
if __name__ == "__main__":
process_files()
sample = torch.load(Path("output")/"001.pt")
print(f": {sample.shape} ( torch.Size([1, 12, 30, 46, 71]))")
!-zip -r output.zip output/
代码及解析
通道映射构建器详解
get_output_channels_indices()
功能: 建立输出通道与输入数据的对应关系
实现原理:
- 变量组偏移量计算
var_groups = {
'z': 0, # 0-12通道
't': 13, # 13-25通道
'u': 26, # 26-38通道
'v': 39, # 39-51通道
'q': 52, # 52-64通道
'ciwc': 65, # 65-77通道
'clwc': 78, # 78-90通道
'crwc': 91, # 91-103通道
'cswc': 104 # 104-116通道
}
#每个变量有十三个气压层
pressure_levels = [50, 100, 150, 200, 250, 300, 400, 500, 600,700, 850, 925, 1000]
每个气象变量占据13个连续通道(对应13个气压层)
- 输出通道配置
output_config = [
('t', 200), ('t', 500), ('t', 700), ('t', 850), ('t', 1000),
('q', 200), ('q', 500), ('q', 700), ('q', 850), ('q', 1000),
('ciwc', 200), ('ciwc', 500), ('ciwc', 700), ('ciwc', 850), ('ciwc',1000),
('clwc', 200), ('clwc', 500), ('clwc', 700), ('clwc', 850), ('clwc',1000),
('crwc', 200), ('crwc', 500), ('crwc', 700), ('crwc', 850), ('crwc',1000),
('cswc', 200), ('cswc', 500), ('cswc', 700), ('cswc', 850), ('cswc',1000)
]
对应比赛要求的30个输出通道顺序
- 索引计算:
for var, level in output_config:
level_index = pressure_levels.index(level)
#
global_index = var_groups[var] + level_index
#
indices.append(global_index)
对应比赛要求的30个输出通道顺序
预测核心逻辑解析
数据处理流程
- 输入预处理
mean_data = input_tensor.squeeze(0).mean(dim=0)
- 输入形状:(1,2,117,181,360) → (2,117,181,360)
- 计算方式:沿着时间维度取平均 → (117,181,360)
2.空间裁剪
lat_slice = slice(35, 81) # 纬度索引转换
lon_slice = slice(70, 141) # 经度索引转换
3.通道筛选
output_core = cropped_global[output_channels_indices, :, :]
4.时间维度扩展
output = output_core.unsqueeze(0).unsqueeze(0).expand(1,12,-1,-1,-1)
文件处理机制
批量处理器
process_files()
1.目录管理
自动创建多级输出目录
Path(output_dir).mkdir(parents=True, exist_ok=True)
2.文件遍历
筛选 .pt 后缀文件,保持输入输出名一致
for file_name in os.listdir(input_dir):
if not file_name.endswith(".pt"):
continue
3.异常处理
捕获并显示错误信息,保持程序持续运行
try:
... # 处理逻辑
except Exception as e:
print(f"处理失败 {file_name}: {str(e)}")