更新输入数据解压缩方法

dev
tian jiax 2024-02-21 10:15:05 +08:00
parent dcc953152b
commit e96c4b336c
13 changed files with 124 additions and 80 deletions

View File

@ -45,7 +45,7 @@
<ParaType>File</ParaType>
<DataType>tar.gz</DataType>
<ParaSource>Cal</ParaSource>
<ParaValue>D:\BaiduNetdiskDownload\西北新增CSAR盐碱度\GF3C_KSC_QPSI_008440_E86.2_N44.1_20231113_L1A_AHV_L10000215823.tar.gz</ParaValue>
<ParaValue>D:\BaiduNetdiskDownload\xibei\GF3C_KSC_QPSI_008440_E86.0_N44.7_20231113_L1A_AHV_L10000215825.tar.gz</ParaValue>
<EnModification>True</EnModification>
<EnMultipleChoice>False</EnMultipleChoice>
<Control>File</Control>
@ -92,7 +92,7 @@
<ParaType>File</ParaType>
<DataType>tar.gz</DataType>
<ParaSource>Cal</ParaSource>
<ParaValue>D:\micro\WorkSpace\Ortho\Output\GF3C_KSC_QPSI_008440_E86.2_N44.1_20231113_L1A_AHV_L10000215823-ortho.tar.gz</ParaValue>
<ParaValue>D:\micro\WorkSpace\ortho\Output\GF3C_KSC_QPSI_008440_E86.0_N44.7_20231113_L1A_AHV_L10000215825-ortho.tar.gz</ParaValue>
<MaxValue>DEFAULT</MaxValue>
<MinValue>DEFAULT</MinValue>
<OptionValue>DEFAULT</OptionValue>

View File

@ -44,6 +44,7 @@ import scipy.io as scipyio
import copy
import scipy.sparse as ss
import shutil
import sys
import pandas
import uuid
from concurrent.futures._base import as_completed, wait
@ -590,9 +591,7 @@ class RPCModel:
y1 = apply_rfm(self.row_num, self.row_den, lat, lon + EPS, alt)
x2 = apply_rfm(self.col_num, self.col_den, lat + EPS, lon, alt)
y2 = apply_rfm(self.row_num, self.row_den, lat + EPS, lon, alt)
n = 0
while not np.all((x0 - col) ** 2 + (y0 - row) ** 2 < 1e-18):
@ -1058,6 +1057,35 @@ class DEMProcess(object):
time.sleep(3)
#gdal.CloseDir(out_DEM)
return out_DEM
@staticmethod
def image_merged(in_dem_path, out_dem_path):
'''
DEM重采样函数默认坐标系为WGS84
agrs:
in_dem_path: 输入的DEM文件夹路径
meta_file_path: 输入的xml元文件路径
out_dem_path: 输出的DEM文件夹路径
'''
# 读取文件夹中所有的DEM
dem_file_paths = [os.path.join(in_dem_path, dem_name) for dem_name in os.listdir(in_dem_path) if
dem_name.find(".tif") >= 0 and dem_name.find(".tif.") == -1]
spatialreference = osr.SpatialReference()
spatialreference.SetWellKnownGeogCS("WGS84") # 设置地理坐标,单位为度 degree # 设置投影坐标,单位为度 degree
spatialproj = spatialreference.ExportToWkt() # 导出投影结果
# 将DEM拼接成一张大图
mergeFile = gdal.BuildVRT(os.path.join(out_dem_path, "mergedDEM_VRT.tif"), dem_file_paths)
out_DEM = os.path.join(out_dem_path, "mergedDEM.tif")
gdal.Warp(out_DEM,
mergeFile,
format="GTiff",
dstSRS=spatialproj,
dstNodata=-9999,
outputType=gdal.GDT_Byte)
time.sleep(3)
# gdal.CloseDir(out_DEM)
return out_DEM
@staticmethod
def dem_resampled(in_dem_path,out_dem_path,samling_f):
in_dem=gdal.Open(in_dem_path,gdalconst.GA_ReadOnly)
@ -2990,3 +3018,8 @@ class IndirectOrthorectification(Orthorectification):
return None
pass
'''
if __name__ == '__main__':
file_path = r'D:\BaiduNetdiskDownload\6133765_2020LC030\N37_65_2020LC030'
out_path = r'D:\BaiduNetdiskDownload\6133765_2020LC030\out'
DEMProcess.image_merged(file_path, out_path)

View File

@ -20,6 +20,7 @@ from tool.algorithm.xml.AlgXmlHandle import ManageAlgXML, CheckSource # 导入x
from OrthoAlg import IndirectOrthorectification, DEMProcess,rpc_correction,getRCImageRC,get_RPC_lon_lat,getRCImageRC2
from OrthoAlg import ScatteringAlg as alg
from tool.algorithm.algtools.logHandler import LogHandler
from tool.config.ConfigeHandle import Config as cf
import os
import glob
# import gc
@ -31,8 +32,13 @@ import scipy.spatial.transform # 用于解决打包错误
import scipy.spatial.transform.rotation
import scipy.spatial.transform._rotation_groups # 用于解决打包错误
DEBUG = False
EXE_NAME = 'Ortho'
if cf.get('debug') == 'True':
DEBUG = True
else:
DEBUG = False
EXE_NAME = cf.get('exe_name')
productLevel = cf.get('productLEVEL')
tager = '-' + cf.get('tager')
#env_str = os.getcwd()
env_str =os.path.dirname(os.path.abspath(sys.argv[0])) #os.path.split(os.path.realpath(__file__))[0]
os.environ['PROJ_LIB'] = env_str
@ -159,12 +165,12 @@ class OrthoMain:
if CorrectMethod.get('CorrectMethod') == '1' or CorrectMethod.get('CorrectMethod') == 1:
logger.info("CorrectMethod is RPC!")
# self.__out_para=self.__out_para.replace(".tar.gz","_RPC.tar.gz")
self.__out_para=self.__out_para.replace(".tar.gz","-ortho.tar.gz")
self.__out_para=self.__out_para.replace(".tar.gz", tager + ".tar.gz")
elif CorrectMethod.get('CorrectMethod') == '2' or CorrectMethod.get('CorrectMethod') == 2:
logger.info("CorrectMethod is RD!")
# self.__out_para=self.__out_para.replace(".tar.gz","_RD.tar.gz")
self.__out_para=self.__out_para.replace(".tar.gz","-ortho.tar.gz")
self.__out_para=self.__out_para.replace(".tar.gz", tager + ".tar.gz")
else:
raise Exception('No CorrectMethod')
@ -304,11 +310,11 @@ class OrthoMain:
if os.path.exists(dem_path) is False:
os.mkdir(dem_path)
for file_path in para_path_list:
BlockProcess.unzip_file(file_path, dem_path)
BlockProcess.unzip_dem(file_path, dem_path)
# tif_name = os.path.basename(file_path)
# shutil.copy(file_path, os.path.join(dem_path, tif_name))
para_path = os.path.join(self.__workspace_origin_path,para['ParaName'])
processing_paras.update({name: para_path})
processing_paras.update({name: dem_path})
elif para['ParaType'] == 'Value':
if para['DataType'] == 'float':
value = float(para['ParaValue'])
@ -640,7 +646,8 @@ class OrthoMain:
Orthorectification.calInterpolation_bil_Wgs84_rc_sar_sigma(parameter_path, dem_rc,
out_power_path,
lin_tif_path)
tempout_tif_path = os.path.join(self.__workspace_package_path, os.path.basename(lin_tif_path).split('-')[0] + "-ortho.tif")
tempout_tif_path = os.path.join(self.__workspace_package_path, os.path.basename(lin_tif_path).split('-')[0]
+ tager + '.tif')
alg.lin_to_db(lin_tif_path, tempout_tif_path) # 线性值转回DB值
for tiff_name in os.listdir(self.__workspace_package_path):
@ -678,6 +685,7 @@ class OrthoMain:
para_dict.update({"ObservationGeometry_SatelliteAzimuth": Azimuth_incidence})
para_dict.update({"imageinfo_ProductName": '正射校正'})
para_dict.update({"imageinfo_ProductIdentifier": 'Ortho'})
para_dict.update({"imageinfo_ProductLevel": productLevel})
para_dict.update({"ProductProductionInfo_BandSelection": "1,2"})
para_dict.update({"ProductProductionInfo_AuxiliaryDataDescription": "DEM"})
CreateProductXml(para_dict, model_path, meta_xml_path).create_standard_xml()
@ -706,9 +714,6 @@ class OrthoMain:
if __name__ == '__main__':
DEBUG=False
if '-DEBUG' in sys.argv:
DEBUG=True
start = datetime.datetime.now()
try:
if len(sys.argv) < 2:

11
Ortho/config.ini Normal file
View File

@ -0,0 +1,11 @@
# -*- coding: UTF-8 -*-
# 定义config分组
[config]
######1-算法基本参数######
tager = ortho
productLEVEL = 3
# 算法名称。修改临时工作区生成临时文件的名称,日志名称;
exe_name = ortho
# 开启调试模式则不删除临时工作区True:开启调试False:不开启调试
debug = False

View File

@ -192,7 +192,7 @@ class AtmosphericMain:
if os.path.exists(dem_path) is False:
os.mkdir(dem_path)
for file_path in para_path_list:
BlockProcess.unzip_file(file_path, dem_path)
BlockProcess.unzip_dem(file_path, dem_path)
# tif_name = os.path.basename(temp_file_path)
# shutil.copy(file_path, os.path.join(dem_path, tif_name))
para_path = os.path.join(self.__workspace_origin_path, para['ParaName'])

View File

@ -1008,7 +1008,7 @@ class DEMProcess(object):
out_dem_path: 输出的DEM文件夹路径
'''
# 读取文件夹中所有的DEM
dem_file_paths=[os.path.join(in_dem_path,dem_name) for dem_name in os.listdir(in_dem_path) if dem_name.find(".tif")>=0 and dem_name.find(".tif.")==-1]
dem_file_paths=[os.path.join(in_dem_path,dem_name) for dem_name in os.listdir(in_dem_path) if dem_name.find(".tif")>=0 and dem_name.find(".tif.")==-1]
spatialreference=osr.SpatialReference()
spatialreference.SetWellKnownGeogCS("WGS84") # 设置地理坐标,单位为度 degree # 设置投影坐标,单位为度 degree
spatialproj=spatialreference.ExportToWkt() # 导出投影结果

View File

@ -31,8 +31,9 @@ if cf.get('debug') == 'True':
DEBUG = True
else:
DEBUG = False
EXE_NAME = 'BackScattering'
tager = cf.get('tager')
EXE_NAME = cf.get('exe_name')
tager = r'-' + cf.get('tager')
productLevel = cf.get('productLEVEL')
LogHandler.init_log_handler('run_log\\' + EXE_NAME)
logger = logging.getLogger("mylog")
# env_str = os.path.split(os.path.realpath(__file__))[0]
@ -495,7 +496,7 @@ class ScatteringMain:
para_dict.update({"ObservationGeometry_SatelliteAzimuth": Azimuth_incidence})
para_dict.update({"imageinfo_ProductName": "后向散射系数"})
para_dict.update({"imageinfo_ProductIdentifier": "BackScattering"})
para_dict.update({"imageinfo_ProductLevel": "3"})
para_dict.update({"imageinfo_ProductLevel": productLevel})
para_dict.update({"ProductProductionInfo_BandSelection": "1,2"})
para_dict.update({"ProductProductionInfo_AuxiliaryDataDescription": "DEM"})
para_dict.update({"MetaInfo_UnitDes": "DB"}) # 设置单位

View File

@ -2,9 +2,10 @@
# 定义config分组
[config]
######1-算法基本参数######
tager = -cal
tager = cal
productLEVEL = 3
# 算法名称。修改临时工作区生成临时文件的名称,日志名称;
exe_name = SoilMoisture
exe_name = BackScattering
# 开启调试模式则不删除临时工作区True:开启调试False:不开启调试
debug = False

View File

@ -148,7 +148,7 @@ class DeformationMain:
if os.path.exists(dem_path) is False:
os.mkdir(dem_path)
for file_path in para_path_list:
BlockProcess.unzip_file(file_path, dem_path)
BlockProcess.unzip_dem(file_path, dem_path)
# tif_name = os.path.basename(file_path)
# shutil.copy(file_path, os.path.join(dem_path, tif_name))
para_path = os.path.join(self.__workspace_origin_path, para['ParaName'])

View File

@ -149,7 +149,7 @@ class DemMain:
if os.path.exists(dem_path) is False:
os.mkdir(dem_path)
for file_path in para_path_list:
BlockProcess.unzip_file(file_path, dem_path)
BlockProcess.unzip_dem(file_path, dem_path)
# tif_name = os.path.basename(file_path)
# shutil.copy(file_path, os.path.join(dem_path, tif_name))
para_path = os.path.join(self.__workspace_origin_path, para['ParaName'])

View File

@ -39,7 +39,7 @@
<DataType>tar.gz</DataType>
<ParaSource>Man</ParaSource>
<ParaValue>
E:\2023xibei\GF3C_KSC_QPSI_008440_E86.0_N44.7_20231113_L1A_AHV_L10000215825-ortho.tar.gz
D:\micro\WorkSpace\Ortho\Output\GF3C_KSC_QPSI_008440_E86.0_N44.7_20231113_L1A_AHV_L10000215825-ortho.tar.gz
</ParaValue>
<MaxValue>DEFAULT</MaxValue>
<MinValue>DEFAULT</MinValue>
@ -68,7 +68,7 @@
<ParaType>File</ParaType>
<DataType>csv</DataType>
<ParaSource>Man</ParaSource>
<ParaValue>E:\2023xibei\soilSality.csv</ParaValue>
<ParaValue>D:\BaiduNetdiskDownload\soilsalinity.csv</ParaValue>
<MaxValue>DEFAULT</MaxValue>
<MinValue>DEFAULT</MinValue>
<OptionValue>DEFAULT</OptionValue>

View File

@ -231,39 +231,34 @@ class SalinityMain:
pls = PLSRegression()
pls.fit(X_train_in, Y_train_in)
PLSRegression(copy=True, max_iter=1000, n_components=5, scale=True, tol=1e-06)
print("---- Train --------------------------------------------")
Y_train_pred_in = pls.predict(X_train_in)
print('Y_train_pred-----------------------------------------')
print(Y_train_pred_in.reshape(-1))
print('Y_train_pred-----------------------------------------')
print('Y_train----------------------------------------------')
print(Y_train_in.reshape(-1))
print('Y_train----------------------------------------------')
slope, intercept, r_value, p_value, std_err = linregress(Y_train_pred_in.reshape(-1), Y_train_in.reshape(-1))
R2 = r_value ** 2
print("训练 使用scipy库a", slope, "b", intercept, "r", r_value, "r-squared", R2)
print("-----------------------------------------------------")
print("---- Test --------------------------------------------")
Y_train_pred_out = pls.predict(X_train_out)
print('Y_train_pred-----------------------------------------')
print(Y_train_pred_out.reshape(-1))
print('Y_train_pred-----------------------------------------')
print('Y_train----------------------------------------------')
print(Y_train_out.reshape(-1))
print('Y_train----------------------------------------------')
slope, intercept, r_value, p_value, std_err = linregress(Y_train_pred_out.reshape(-1), Y_train_out.reshape(-1))
R2 = r_value ** 2
print("测试 使用scipy库a", slope, "b", intercept, "r", r_value, "r-squared", R2)
print("-----------------------------------------------------")
#
# print("---- Train --------------------------------------------")
# Y_train_pred_in = pls.predict(X_train_in)
# print('Y_train_pred-----------------------------------------')
# print(Y_train_pred_in.reshape(-1))
# print('Y_train_pred-----------------------------------------')
#
# print('Y_train----------------------------------------------')
# print(Y_train_in.reshape(-1))
# print('Y_train----------------------------------------------')
# slope, intercept, r_value, p_value, std_err = linregress(Y_train_pred_in.reshape(-1), Y_train_in.reshape(-1))
# R2 = r_value ** 2
# print("训练 使用scipy库a", slope, "b", intercept, "r", r_value, "r-squared", R2)
# print("-----------------------------------------------------")
#
# print("---- Test --------------------------------------------")
# Y_train_pred_out = pls.predict(X_train_out)
# print('Y_train_pred-----------------------------------------')
# print(Y_train_pred_out.reshape(-1))
# print('Y_train_pred-----------------------------------------')
#
# print('Y_train----------------------------------------------')
# print(Y_train_out.reshape(-1))
# print('Y_train----------------------------------------------')
# slope, intercept, r_value, p_value, std_err = linregress(Y_train_pred_out.reshape(-1), Y_train_out.reshape(-1))
# R2 = r_value ** 2
# print("测试 使用scipy库a", slope, "b", intercept, "r", r_value, "r-squared", R2)
# print("-----------------------------------------------------")
SrcImageName = os.path.split(self.__input_paras["AHV"]['ParaValue'])[1].split('.tar.gz')[0]
model_path = os.path.join(self.__product_dic, SrcImageName + tar + '.pkl')

View File

@ -70,33 +70,31 @@ class BlockProcess:
def unzip_file(zip_file_path, out_path): # ):
# 获取压缩文件所在的目录
# extract_folder = os.path.dirname(zip_file_path)
if zip_file_path.endswith("dem.zip"):
out_path_merg = os.path.join(out_path)
# os.mkdir(out_path_merg)
para_value_list = zip_file_path.split(";")
for n in para_value_list:
with zipfile.ZipFile(n, 'r') as zip_ref:
# 解压到和压缩文件同名的文件夹中
zip_ref.extractall(out_path_merg)
basename = os.path.splitext(os.path.basename(zip_file_path))[0]
extract_folder = os.path.join(out_path, basename)
return out_path
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
# 解压到和压缩文件同名的文件夹中
zip_ref.extractall(extract_folder)
else:
basename = os.path.splitext(os.path.basename(zip_file_path))[0]
extract_folder = os.path.join(out_path, basename)
files = list(glob.glob(os.path.join(extract_folder, '*')))
for file in files:
if basename in os.path.basename(file):
if not file.endswith(".xml"):
unzipped_folder_path = file
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
return unzipped_folder_path
@staticmethod
def unzip_dem(zip_file_path, out_path):
para_value_list = zip_file_path.split(";")
for n in para_value_list:
with zipfile.ZipFile(n, 'r') as zip_ref:
# 解压到和压缩文件同名的文件夹中
zip_ref.extractall(extract_folder)
zip_ref.extractall(out_path)
files = list(glob.glob(os.path.join(extract_folder, '*')))
for file in files:
if basename in os.path.basename(file):
if not file.endswith(".xml"):
unzipped_folder_path = file
return unzipped_folder_path
return out_path
@staticmethod
def get_same_img(img_dir, img_name):