refactor: 重构项目目录,添加全套遥感数据处理模块

- 重构项目目录结构,将零散代码整理到src目录下,创建各子包初始化文件
- 包括HLS、GPM、SMAP、MODIS等多源遥感数据的搜索、下载与预处理脚本
- 包括通用工具函数库,包含坐标参数定义、格式转换、影像处理等工具
- 同步更新README.md示例命令路径,修正脚本调用的目录错误
- 新增AGENTS.md文档说明开发环境配置
- 更新.gitignore规则,添加环境变量和构建缓存的忽略配置
This commit is contained in:
谢泓 2026-05-18 19:09:07 +08:00
parent 231d6f1d72
commit 5e96d0e026
23 changed files with 54 additions and 32 deletions

8
.gitignore vendored
View File

@ -26,4 +26,10 @@ data/
*.7z
*.tar*
*.rar
.env*
.sisyphus/
# 环境变量
.env
.env.local
.env.*.local
!.env.example

1
AGENTS.md Normal file
View File

@ -0,0 +1 @@
1、本项目算法部分在开发阶段可以使用 conda 管理 Python 环境,本机环境名为 `openearth`Python 版本为 `3.12`

View File

@ -206,27 +206,27 @@ data/
- 爬取 L30 与 S30 的核心光谱波段:仅按照感兴趣区,瓦片 ID起止时间以及产品名称筛选影像不进行云量筛选影像对影像进行去云掩膜处理
```sh
python .\\HLS_SuPER\\HLS_SuPER.py -roi '112.9834,30.5286,114.32373,31.64448' -tile T49RGQ -dir .\\data\\HLS\\ALL -start 2024-01-01 -end 2024-01-31 -prod both -bands BLUE,GREEN,RED,NIR1,SWIR1,SWIR2,Fmask -scale True
python .\\src\\HLS_SuPER\\HLS_SuPER.py -roi '112.9834,30.5286,114.32373,31.64448' -tile T49RGQ -dir .\\data\\HLS\\ALL -start 2024-01-01 -end 2024-01-10 -prod both -bands BLUE,GREEN,RED,NIR1,SWIR1,SWIR2,Fmask -scale True
```
- 爬取 L30 的所有波段:按照感兴趣区,瓦片 ID起止时间以及产品名称筛选影像过滤云量小于 70% 的影像,对影像进行去云掩膜处理
```sh
python .\\HLS_SuPER\\HLS_SuPER.py -roi '112.9834,30.5286,114.32373,31.64448' -tile T49RGQ -dir .\\data\\HLS\\L30\\subset -start 2024-01-01 -end 2024-01-31 -prod HLSL30 -bands COASTAL-AEROSOL,BLUE,GREEN,RED,NIR1,SWIR1,SWIR2,CIRRUS,TIR1,TIR2,Fmask -cc 70 -scale True
python .\\src\\HLS_SuPER\\HLS_SuPER.py -roi '112.9834,30.5286,114.32373,31.64448' -tile T49RGQ -dir .\\data\\HLS\\L30\\subset -start 2024-01-01 -end 2024-01-31 -prod HLSL30 -bands COASTAL-AEROSOL,BLUE,GREEN,RED,NIR1,SWIR1,SWIR2,CIRRUS,TIR1,TIR2,Fmask -cc 70 -scale True
```
- 仅爬取 L30 的热红外波段:仅按照感兴趣区,瓦片 ID起止时间以及产品名称筛选影像不进行云量筛选影像对影像进行去云掩膜处理
```sh
python .\\HLS_SuPER\\HLS_SuPER.py -roi .\\data\\vectors\\49REL.geojson -tile T49REL -dir .\\data\\HLS\\2024 -start 2024-06-01 -end 2024-09-01 -prod HLSL30 -bands TIR1,TIR2
python .\\src\\HLS_SuPER\\HLS_SuPER.py -roi .\\data\\vectors\\49REL.geojson -tile T49REL -dir .\\data\\HLS\\2024 -start 2024-06-01 -end 2024-09-01 -prod HLSL30 -bands TIR1,TIR2
```
- 【测试用】根据给定的范围文件 `*.geojson`,不进行云量筛选,直接爬取数据
```sh
python .\\HLS_SuPER\\HLS_SuPER.py -roi .\\data\\vectors\\49REL.geojson -tile T49REL -dir .\\data\\HLS\\2024 -start 2024-03-01 -end 2024-11-01 -prod both -bands BLUE,GREEN,RED,NIR1,SWIR1,SWIR2,Fmask
python .\\src\\HLS_SuPER\\HLS_SuPER.py -roi .\\data\\vectors\\49REL.geojson -tile T49REL -dir .\\data\\HLS\\2024 -start 2024-03-01 -end 2024-11-01 -prod both -bands BLUE,GREEN,RED,NIR1,SWIR1,SWIR2,Fmask
```
### 4.2 其他数据
v1.0: 直接运行 `DATA_SuPER/` 目录下所需数据对应的 `*.py` 文件即可.
v1.0: 直接运行 `src/DATA_SuPER/` 目录下所需数据对应的 `*.py` 文件即可.

View File

@ -50,15 +50,16 @@ import earthaccess
import numpy as np
from rioxarray import open_rasterio
sys.path.append(str(Path(".").parent))
# 添加项目根目录到 sys.path确保作为独立脚本运行时也能正确导入
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from utils.common_utils import (
from src.utils.common_utils import (
setup_dask_environment,
setup_logging,
clip_image,
mosaic_images,
)
from HLS_SuPER.HLS_Su import earthdata_search
from src.HLS_SuPER.HLS_Su import earthdata_search
def reorganize_nasadem_urls(dem_results_urls: list):

View File

@ -28,10 +28,11 @@ import logging
import earthaccess
from xarray import open_dataset
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 添加项目根目录到 sys.path确保作为独立脚本运行时也能正确导入
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from utils.common_utils import setup_dask_environment
from HLS_SuPER.HLS_Su import earthdata_search
from src.utils.common_utils import setup_dask_environment
from src.HLS_SuPER.HLS_Su import earthdata_search
def convert(source_nc_path: str, target_tif_path: str) -> None:

View File

@ -21,15 +21,16 @@ import rioxarray as rxr
import dask.distributed
import geopandas as gpd
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 添加项目根目录到 sys.path确保作为独立脚本运行时也能正确导入
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from utils.common_utils import (
from src.utils.common_utils import (
clip_image,
reproject_image,
setup_dask_environment,
setup_logging,
)
from HLS_SuPER.HLS_Su import earthdata_search
from src.HLS_SuPER.HLS_Su import earthdata_search
def open_mcd43a4(file_path):

View File

@ -49,10 +49,11 @@ import numpy as np
import xarray as xr
from rioxarray import open_rasterio
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 添加项目根目录到 sys.path确保作为独立脚本运行时也能正确导入
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from utils.common_utils import setup_dask_environment, clip_image, mosaic_images
from HLS_SuPER.HLS_Su import earthdata_search
from src.utils.common_utils import setup_dask_environment, clip_image, mosaic_images
from src.HLS_SuPER.HLS_Su import earthdata_search
def download_granule(

View File

@ -28,16 +28,17 @@ import h5py
from osgeo import gdal
import xarray as xr
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 添加项目根目录到 sys.path确保作为独立脚本运行时也能正确导入
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from utils.common_params import EASE2_GRID_PARAMS, EPSG
from utils.common_utils import (
from src.utils.common_params import EASE2_GRID_PARAMS, EPSG
from src.utils.common_utils import (
array_to_raster,
load_band_as_arr,
reproject_image,
setup_dask_environment,
)
from HLS_SuPER.HLS_Su import earthdata_search
from src.HLS_SuPER.HLS_Su import earthdata_search
def convert(source_h5_path: str, target_tif_path: str, date: str) -> None:

View File

@ -26,12 +26,13 @@ from datetime import datetime as dt
import dask.distributed
import earthaccess
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 添加项目根目录到 sys.path确保作为独立脚本运行时也能正确导入
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from HLS_PER import create_timeseries_dataset, process_granule
from HLS_Su import format_roi, hls_search
from src.HLS_SuPER.HLS_PER import create_timeseries_dataset, process_granule
from src.HLS_SuPER.HLS_Su import format_roi, hls_search
from utils.common_utils import setup_dask_environment
from src.utils.common_utils import setup_dask_environment
def parse_arguments():

9
src/__init__.py Normal file
View File

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
"""算法源码包
包含所有遥感数据处理算法模块
- HLS_SuPER: HLS 遥感数据处理
- DATA_SuPER: 多源遥感数据处理MODISSMAPDEMSARGPM
- Basemap_SuPER: 底图数据处理
- utils: 通用工具函数
"""

View File

@ -20,11 +20,11 @@ from pathlib import Path
import numpy as np
from osgeo import gdal
# 添加父目录到 sys.path 以导入 utils
BASE_DIR = Path(__file__).parent.parent
# 添加项目根目录到 sys.path确保作为独立脚本运行时也能正确导入
BASE_DIR = Path(__file__).parent.parent.parent
sys.path.append(str(BASE_DIR))
from utils.common_utils import setup_logging
from src.utils.common_utils import setup_logging
gdal.UseExceptions()
# 设置 GDAL 选项以优化性能

View File

@ -13,11 +13,11 @@ from pathlib import Path
from osgeo import gdal
import numpy as np
# 添加父目录到 sys.path 以导入 utils
BASE_DIR = Path(__file__).parent.parent
# 添加项目根目录到 sys.path确保作为独立脚本运行时也能正确导入
BASE_DIR = Path(__file__).parent.parent.parent
sys.path.append(str(BASE_DIR))
from utils.common_utils import setup_logging
from src.utils.common_utils import setup_logging
gdal.UseExceptions()
# 设置 GDAL 选项以优化性能