diff --git a/src/gui/core/worker_thread.py b/src/gui/core/worker_thread.py index 3ac0aab..fc7659b 100644 --- a/src/gui/core/worker_thread.py +++ b/src/gui/core/worker_thread.py @@ -229,6 +229,11 @@ class WorkerThread(QThread): def run(self): """运行 pipeline:子线程内切换 Matplotlib 为 Agg,避免 Qt5Agg 在后台线程绘图导致界面卡死。""" + import os + # GDAL 环境变量保护(放在最前面,防止路径/编码问题) + os.environ['GDAL_FILENAME_IS_UTF8'] = 'YES' + os.environ['SHAPE_ENCODING'] = 'UTF-8' + mpl_prev = None try: import matplotlib diff --git a/src/gui/panels/step7_panel.py b/src/gui/panels/step7_panel.py index c8b13c9..a819201 100644 --- a/src/gui/panels/step7_panel.py +++ b/src/gui/panels/step7_panel.py @@ -150,7 +150,7 @@ class Step7Panel(QWidget): deglint_path = os.path.join(self.work_dir or '', deglint_path).replace('\\', '/') self.deglint_img_file.set_path(deglint_path) - # 2. 填充水域掩膜路径(优先从 pipeline.step_outputs 获取绝对路径) + # 2. 填充水域掩膜路径(优先级:pipeline.step_outputs > step1_panel > 1_water_mask > input-test) water_mask_path = None if pipeline and hasattr(pipeline, 'step_outputs'): step1_outputs = getattr(pipeline, 'step_outputs', {}).get('step1', {}) @@ -162,6 +162,26 @@ class Step7Panel(QWidget): # 回退:从 step1 面板 widget 直接读取 if not water_mask_path and hasattr(main_window, 'step1_panel'): water_mask_path = main_window.step1_panel.output_file.get_path() + # 备选:扫描 1_water_mask 目录下的 .dat 文件 + if not water_mask_path and self.work_dir: + mask_dir = os.path.join(self.work_dir, "1_water_mask") + if os.path.isdir(mask_dir): + dat_files = [f for f in os.listdir(mask_dir) if f.lower().endswith('.dat')] + if dat_files: + water_mask_path = os.path.join(mask_dir, dat_files[0]).replace('\\', '/') + # 备选:扫描 input-test 目录(优先匹配 water_mask_from_shp.dat) + if not water_mask_path and self.work_dir: + input_test_dir = os.path.join(self.work_dir, "input-test") + if os.path.isdir(input_test_dir): + dat_files = [f for f in os.listdir(input_test_dir) if f.lower().endswith('.dat')] + # 优先匹配 water_mask_from_shp.dat + for f in dat_files: + if 'water_mask_from_shp' in f.lower(): + water_mask_path = os.path.join(input_test_dir, f).replace('\\', '/') + break + # 否则取第一个 .dat 文件 + if not water_mask_path and dat_files: + water_mask_path = os.path.join(input_test_dir, dat_files[0]).replace('\\', '/') if water_mask_path: # 若为相对路径,使用 work_dir 合成为绝对路径 diff --git a/src/utils/sampling.py b/src/utils/sampling.py index 87971bf..0030c13 100644 --- a/src/utils/sampling.py +++ b/src/utils/sampling.py @@ -1,10 +1,21 @@ -from src.utils.util import * -import math +# -*- coding: utf-8 -*- +""" +采样点生成模块 - 提供分块采样和光谱数据提取功能 +""" + import os +import math + +# GDAL 环境变量保护(放在最前面,防止路径/编码问题) +os.environ['GDAL_FILENAME_IS_UTF8'] = 'YES' +os.environ['SHAPE_ENCODING'] = 'UTF-8' + import numpy as np from osgeo import gdal, ogr import spectral from scipy import ndimage +from src.utils.util import write_bands + try: from skimage import morphology from skimage.morphology import skeletonize, medial_axis @@ -87,6 +98,12 @@ def get_spectral_sampling_points_chunked(bil_file, water_mask_shp, severe_glint= ogr.UseExceptions() try: + # ---------- 路径归一化 + 存在性检查 ---------- + bil_file = os.path.abspath(bil_file).replace('\\', '/') + print(f"[路径检查] 去耀斑影像: {bil_file}") + if not os.path.exists(bil_file): + raise FileNotFoundError(f"【后端错误】无法在磁盘上找到指定的去耀斑影像: {bil_file}") + # 打开bil文件 dataset_bil = gdal.Open(bil_file) if dataset_bil is None: