# millet **Repository Path**: maergaiyun/millet ## Basic Information - **Project Name**: millet - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-16 - **Last Updated**: 2026-05-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 沁县小米种植范围提取 基于公开遥感数据(Sentinel-2)的沁县小米种植范围提取本科论文项目。 ## 项目概述 - **研究区域**: 山西省长治市沁县 - **目标作物**: 谷子(小米) - **数据来源**: Google Earth Engine 公开数据集 - **方法**: 多时相 Sentinel-2 + 随机森林分类 - **时间范围**: 2025 年生长季(4-10月) ## 技术架构 ``` ┌─────────────────────────────────────────────────────────────┐ │ 数据层 │ ├─────────────────────────────────────────────────────────────┤ │ Sentinel-2 L2A │ Landsat 8/9 │ DEM │ WorldCover │ │ (主数据) │ (辅数据) │ (地形)│ (先验) │ └─────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 特征工程 │ ├─────────────────────────────────────────────────────────────┤ │ 光谱指数: NDVI, EVI, NDRE, GI, SAVI, NDWI │ │ 地形因子: 坡度, 坡向 (含 sin/cos 变换) │ │ 时序特征: 苗期/拔节期/抽穗期/成熟期 多期合成 │ └─────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 分类模型 │ ├─────────────────────────────────────────────────────────────┤ │ 随机森林 (100 树) + 物候特征筛选 + DEM 约束 │ │ 后处理: 碎斑过滤 + 形态学开闭运算 │ └─────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────┐ │ 输出结果 │ ├─────────────────────────────────────────────────────────────┤ │ 分类GeoTIFF │ 面积统计 │ 交互地图 │ 时序曲线 │ └─────────────────────────────────────────────────────────────┘ ``` ## 快速开始 ### 1. 环境安装 ```bash # 方式一:运行安装脚本 chmod +x setup.sh ./setup.sh # 方式二:手动安装 pip install -r requirements.txt ``` ### 2. GEE 认证 ```bash earthengine authenticate ``` ### 3. 运行 ```bash # 快速预览(检验数据可用性) python main.py --mode preview # 完整流程 python main.py --mode full # 指定年份 python main.py --year 2024 ``` ## 项目结构 ``` qinxian-millet/ ├── config.yaml # 项目配置文件 ├── main.py # 主流程入口 ├── gee_utils.py # GEE 初始化 + AOI 获取 ├── gee_preprocessing.py # 影像预处理 + 特征工程 ├── gee_samples.py # 训练样本生成 ├── gee_classification.py # 分类 + 后处理 ├── gee_visualization.py # 可视化出图 ├── requirements.txt # Python 依赖 ├── setup.sh # 安装脚本 ├── README.md # 说明文档 └── outputs/ # 输出目录 ├── classification_map.html ├── ndvi_timeseries_map.html ├── classification_result.png ├── ndvi_timeseries.png └── ... ``` ## 配置说明 修改 `config.yaml` 可调整: | 参数 | 说明 | 默认值 | |------|------|--------| | `PRIMARY_YEAR` | 分析年份 | 2025 | | `SENTINEL2.cloud_threshold` | 云量阈值(%) | 10 | | `SENTINEL2.mosaic_method` | 合成方式 | median | | `RANDOM_FOREST.n_estimators` | 树数量 | 100 | | `POST_PROCESSING.min_area_pixels` | 最小图斑(像素) | 10 | | `OUTPUT.export_resolution` | 输出分辨率(m) | 10 | ## 数据来源 | 数据集 | ID | 用途 | |--------|-----|------| | Sentinel-2 L2A | `COPERNICUS/S2_SR_HARMONIZED` | 主影像 | | Landsat 8 | `LANDSAT/LC08/C02/T1_L2` | 时序补空 | | DEM | `USGS/SRTMGL1_003` | 地形因子 | | WorldCover | `ESA/WorldCover/v100` | 耕地先验 | | 行政边界 | `FAO/GAUL/2015/level2` | AOI | ## 核心模块 ### 1. 数据获取 (`gee_utils.py`) ```python from gee_utils import initialize_gee, get_qinxian_geometry initialize_gee() aoi = get_qinxian_geometry() ``` ### 2. 特征构建 (`gee_preprocessing.py`) ```python from gee_preprocessing import build_multitemporal_features feature_image = build_multitemporal_features(aoi, year=2025) ``` ### 3. 样本生成 (`gee_samples.py`) ```python from gee_samples import generate_training_samples training_samples = generate_training_samples(aoi, feature_image) ``` ### 4. 分类 (`gee_classification.py`) ```python from gee_classification import train_random_forest_gee, apply_post_processing classifier, confusion = train_random_forest_gee(training_samples, feature_bands) classified = apply_post_processing(classified, dem=dem) ``` ## 输出示例 运行完成后生成: 1. **分类结果图** (`outputs/classification_result.png`) 2. **面积统计** (`outputs/area_statistics.png`) 3. **混淆矩阵** (`outputs/confusion_matrix.png`) 4. **特征重要性** (`outputs/feature_importance.png`) 5. **交互地图** (`outputs/classification_map.html`) 6. **GeoTIFF** (Google Drive) ## 注意事项 1. **GEE 配额**: 首次使用需认证,影像导出需要 Google Drive 空间 2. **精度限制**: 无本地真值样本,分类结果为"近似估算" 3. **光谱混淆**: 小米与玉米、谷子存在光谱相似性,误判难以避免 4. **分辨率限制**: 10m 分辨率对山地细碎地块可能偏大 ## 常见问题 ### Q: 运行报错 "EEServiceException" A: 需要运行 `earthengine authenticate` 完成 GEE 认证 ### Q: 影像数量为 0 A: 尝试调高 `SENTINEL2.cloud_threshold`(如改为 20) ### Q: 内存不足 A: 减小研究区范围或降低输出分辨率 ### Q: 训练样本不足 A: 调整 `gee_samples.py` 中的 `n_positive` 和 `n_negative` 参数 ## 参考 - [Sentinel-2 数据产品](https://sentinels.copernicus.eu/sentinel-data-access/sentinel-products/sentinel-2-data-products) - [GEE Python API](https://developers.google.com/earth-engine/tutorials/tutorial/python_01) - [geemap 文档](https://geemap.org/) ## 作者 本科论文项目 - 遥感技术与应用 --- **⚠️ 声明**: 本项目使用公开数据,结果为研究参考,不能替代官方统计或实际测量。