精简打包之前

This commit is contained in:
2026-02-25 11:50:30 +08:00
parent af56c94efe
commit 729b283f29
25 changed files with 8615 additions and 50 deletions

View File

@ -39,6 +39,24 @@ except ImportError:
print("WARNING: 未安装tqdm库,将不显示进度条。如需进度条,请运行: pip install tqdm")
def _safe_print(msg):
"""
安全打印函数,保证任何情况下不因打印而失败
避免 Windows 控制台编码问题导致的 OSError
"""
try:
print(msg)
except Exception:
try:
# 回退方案:移除非ASCII字符后打印
safe_msg = str(msg).encode('ascii', 'ignore').decode('ascii', 'ignore')
sys.stdout.write(safe_msg + '\n')
sys.stdout.flush()
except Exception:
# 最终回退:静默失败,不影响程序运行
pass
def create_height_bins(heights, bin_size=2.0):
"""
将高度数据按指定间隔分档
@ -101,7 +119,7 @@ def load_excel_data(file_path):
pd.DataFrame: 读取的数据
"""
try:
print(f"正在读取Excel文件: {Path(file_path).name}")
_safe_print(f"正在读取Excel文件: {Path(file_path).name}")
# 读取Excel文件
df = pd.read_excel(file_path)
@ -111,7 +129,7 @@ def load_excel_data(file_path):
return df
except Exception as e:
print(f" 文件读取失败: {Path(file_path).name}")
_safe_print(f" 文件读取失败: {Path(file_path).name}")
print(f" 错误详情: {e}")
sys.exit(1)
@ -555,7 +573,7 @@ def adjust_altitude(df):
Returns:
pd.DataFrame: 添加调整后高度字段的DataFrame
"""
print("📏 创建调整后的高度字段...")
print(" 创建调整后的高度字段...")
if 'fAltitudeFused' in df.columns:
min_altitude = df['fAltitudeFused'].min()
@ -729,7 +747,7 @@ def process_excel_file(file_path, config_path=None):
file_path: Excel文件路径
config_path: 配置文件路径,用于读取gases配置
"""
print(f" === 开始处理文件: {Path(file_path).name} ===\n")
_safe_print(f" === 开始处理文件: {Path(file_path).name} ===\n")
# 1. 读取数据
df = load_excel_data(file_path)
@ -771,7 +789,7 @@ def process_excel_file(file_path, config_path=None):
df.to_csv(output_path, index=False, encoding='utf-8-sig')
print(f"\n 处理完成!")
print(f" 输出文件: {output_path}")
_safe_print(f" 输出文件: {output_path}")
print(f" 最终数据: {df.shape[0]:,} 行 × {df.shape[1]} 列")
print(f" 最终字段: {', '.join(df.columns)}")
@ -807,7 +825,7 @@ def process_file(input_file, output_file=None, config_file=None):
if output_file:
output_path = Path(output_file)
df.to_csv(output_path, index=False, encoding='utf-8-sig')
print(f"额外保存到: {output_path}")
_safe_print(f"额外保存到: {output_path}")
return df
@ -972,7 +990,7 @@ def main(input_file=None, output_file=None, interactive=False):
if output_file:
output_path = Path(output_file)
df.to_csv(output_path, index=False, encoding='utf-8-sig')
print(f"额外保存到: {output_path}")
_safe_print(f"额外保存到: {output_path}")
return df