内容部分修改
This commit is contained in:
@ -11,6 +11,7 @@ os.environ['GDAL_FILENAME_IS_UTF8'] = 'YES'
|
||||
os.environ['SHAPE_ENCODING'] = 'UTF-8'
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from osgeo import gdal, ogr
|
||||
import spectral
|
||||
from scipy import ndimage
|
||||
@ -354,6 +355,45 @@ def get_spectral_sampling_points_chunked(bil_file, water_mask_shp, severe_glint=
|
||||
if f:
|
||||
f.close()
|
||||
|
||||
# ==============================================================================
|
||||
# 🚀 终极手术植入点:带强行环境净化的特征引擎挂载
|
||||
# ==============================================================================
|
||||
|
||||
# 2. 安全校验路径落盘状态
|
||||
if output_csvpath and os.path.exists(str(output_csvpath)):
|
||||
try:
|
||||
from src.utils.water_index import WaterQualityIndexCalculator
|
||||
|
||||
print("\n[特征引擎挂载] 正在为采样点自动追加 45 个水质指数衍生特征...")
|
||||
|
||||
# 读取基础底座(50列光谱)
|
||||
base_df = pd.read_csv(output_csvpath)
|
||||
|
||||
# 实例化计算器
|
||||
calc = WaterQualityIndexCalculator()
|
||||
|
||||
# 提取有效算法
|
||||
algorithm_methods = [
|
||||
m for m in dir(calc)
|
||||
if not m.startswith('_') and m not in ['find_closest_wavelength', 'calculate_all_indices']
|
||||
]
|
||||
|
||||
# 就地追加 45 列衍生指数
|
||||
for algo_name in algorithm_methods:
|
||||
try:
|
||||
algo_func = getattr(calc, algo_name)
|
||||
base_df[algo_name] = algo_func(base_df)
|
||||
except Exception:
|
||||
base_df[algo_name] = np.nan
|
||||
|
||||
# 覆盖重写最终结果!
|
||||
base_df.to_csv(output_csvpath, index=False, encoding='utf-8-sig')
|
||||
print(f"✓ 特征扩充大功告成!当前文件总维度完美适配模型: {base_df.shape}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"⚠ 警告:追加特征失败,保留原基础光谱。死因: {e}")
|
||||
# ==============================================================================
|
||||
|
||||
return x_out, y_out, np.array(spectral_out)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user