Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌤️ 气象等值线智能修正系统

一个基于深度学习的智能气象等值线自动修正工具,能够检测并修复气象数据可视化中的等值线错误。

✨ 核心功能

  • 🔍 智能问题检测:自动识别等值线图中的断线、交叉、锯齿等问题
  • 🛠️ AI智能修正:基于深度学习模型自动修复等值线
  • 📐 物理约束集成:融合气象学物理规则,确保修正结果合理
  • 🎨 多模型支持:U-Net、扩散模型、条件GAN等多种AI架构
  • 🌐 Web可视化:友好的Web界面,实时查看修正效果

📁 项目结构

weather-contour-ai/
├── data/                      # 数据目录
│   ├── raw/                  # 原始气象数据
│   ├── processed/            # 处理后的数据
│   └── synthetic/            # 合成的训练数据
├── notebooks/                # Jupyter笔记本
│   ├── 01_data_exploration.ipynb
│   ├── 02_model_prototyping.ipynb
│   └── 03_experiment_results.ipynb
├── src/                      # 源代码
│   ├── data/                # 数据处理模块
│   ├── models/              # 深度学习模型
│   ├── training/            # 训练脚本
│   ├── evaluation/          # 评估工具
│   └── visualization/       # 可视化工具
├── configs/                  # 配置文件
├── tests/                    # 测试文件
├── scripts/                  # 实用脚本
├── environment.yml          # Conda环境配置
├── requirements.txt         # Pip依赖
└── README.md               # 本文件

🚀 快速开始

1. 环境配置

# 使用conda创建环境
conda env create -f environment.yml
conda activate weather-contour-ai

# 或手动安装
conda create -n weather-contour-ai python=3.10
conda activate weather-contour-ai

# 安装科学计算包
conda install -c conda-forge numpy pandas matplotlib scipy jupyterlab
conda install -c conda-forge xarray netcdf4 cartopy metpy

# 安装深度学习框架
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install diffusers transformers accelerate

# 安装项目依赖
pip install -r requirements.txt

2. 数据准备

# 下载示例数据
python scripts/download_sample_data.py

# 生成合成训练数据
python scripts/generate_synthetic_data.py

3. 训练模型

# 训练U-Net模型
python src/training/train_unet.py --config configs/unet_config.yaml

# 训练扩散模型
python src/training/train_diffusion.py --config configs/diffusion_config.yaml

4. 启动Web应用

# 启动Gradio界面
python src/web/gradio_app.py

# 或启动Streamlit应用
streamlit run src/web/streamlit_app.py

访问 http://localhost:7860 使用交互式界面。

🛠️ 使用方法

命令行使用

from src.correction_system import ContourCorrectionSystem

# 初始化系统
corrector = ContourCorrectionSystem()

# 加载数据
contour_data = load_contour_data("data/raw/example.nc")

# 进行修正
corrected_data = corrector.correct(
    contour_data,
    method="unet",          # 可选择: unet, diffusion, hybrid
    confidence_threshold=0.8
)

# 保存结果
save_corrected_data(corrected_data, "results/corrected_contour.nc")

Python API

import weather_contour_ai as wca

# 快速修正函数
result = wca.fix_contour(
    input_file="input_contour.png",
    meteo_data="weather_data.nc",
    output_file="corrected.png",
    visualize=True
)

# 批量处理
wca.batch_process(
    input_dir="data/raw/",
    output_dir="results/",
    meteo_data_dir="meteo_data/"
)

📊 模型性能

模型 准确率 推理速度 内存占用 适用场景
U-Net 92.3% 快 ⚡ 实时修正
Diffusion 95.7% 慢 🐌 高质量修正
Hybrid 94.1% 中 ⏱️ 平衡场景

📈 实验结果

修复效果对比

问题类型 传统方法 AI修正 提升
断线修复 78.2% 96.5% +18.3%
平滑处理 65.4% 91.2% +25.8%
拓扑纠正 42.1% 88.7% +46.6%
综合修正 61.9% 92.3% +30.4%

🔧 高级配置

自定义训练

# configs/custom_training.yaml
model:
  name: "unet_advanced"
  backbone: "resnet50"
  input_channels: 3
  output_channels: 1
  
training:
  epochs: 200
  batch_size: 16
  learning_rate: 0.001
  loss_function: "dice_focal"
  
data:
  augmentation:
    rotation_range: 30
    zoom_range: [0.8, 1.2]
    horizontal_flip: true

物理约束配置

from src.models.physics_constraints import PhysicsValidator

validator = PhysicsValidator(
    gradient_limit=5.0,      # °C/km
    smoothness_weight=0.3,
    enforce_topology=True,
    station_pinning=True    # 保持测站观测值
)

🧪 测试

# 运行所有测试
pytest tests/ -v

# 运行特定测试
pytest tests/test_contour_correction.py -v

# 生成测试报告
pytest --cov=src --cov-report=html

📝 开发指南

代码规范

# 代码格式化
black src/
isort src/

# 代码检查
flake8 src/
mypy src/

# 使用预提交钩子
pre-commit install

添加新模型

  1. src/models/ 下创建新模型类
  2. 实现 BaseContourModel 接口
  3. src/training/ 中添加训练脚本
  4. configs/ 中添加配置文件
  5. 更新 model_registry.py

贡献流程

  1. Fork 项目
  2. 创建功能分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开 Pull Request

🌐 部署

Docker部署

# 构建镜像
docker build -t contour-correction:latest .

# 运行容器
docker run -p 8501:8501 contour-correction

# 使用docker-compose
docker-compose up -d

云部署

# 部署到Hugging Face Spaces
git push https://huggingface.co/spaces/Repiecer/contour-correction

# 部署到Streamlit Cloud
streamlit deploy src/web/streamlit_app.py

📚 学习资源

🤝 如何贡献

我们欢迎各种贡献!请参阅 CONTRIBUTING.md 了解如何开始。

  1. 报告 Bug
  2. 提出新功能
  3. 提交 Pull Request
  4. 改进文档

📞 联系方式

🙏 致谢

  • 感谢 Hugging Face 提供的优秀模型库
  • 感谢 ECMWF 的气象数据
  • 感谢所有开源社区的贡献者

✨ 提示: 本项目正在积极开发中,欢迎反馈和建议!

About

An AI based experiment for correcting meteorological contour lines

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages