From e96c4b336c13baa89811ee083c18d931b8936583 Mon Sep 17 00:00:00 2001 From: tian jiax <446100073@qq.com> Date: Wed, 21 Feb 2024 10:15:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BE=93=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A7=A3=E5=8E=8B=E7=BC=A9=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ortho/Ortho.xml | 4 +- Ortho/OrthoAlg.py | 39 +++++++++++- Ortho/OrthoMain.py | 25 +++++--- Ortho/config.ini | 11 ++++ .../AtmosphericDelayMain.py | 2 +- backScattering/BackScatteringAlg.py | 2 +- backScattering/BackScatteringMain.py | 7 ++- backScattering/config.ini | 5 +- deformation-C-SAR/DeformationMain.py | 2 +- dem-C-SAR/DemMain.py | 2 +- .../SoilSalinityTrain.xml | 4 +- .../SoilSalinityTrainMain.py | 61 +++++++++---------- tool/algorithm/block/blockprocess.py | 40 ++++++------ 13 files changed, 124 insertions(+), 80 deletions(-) create mode 100644 Ortho/config.ini diff --git a/Ortho/Ortho.xml b/Ortho/Ortho.xml index 980098d6..4cdd77db 100644 --- a/Ortho/Ortho.xml +++ b/Ortho/Ortho.xml @@ -45,7 +45,7 @@ File tar.gz Cal - D:\BaiduNetdiskDownload\西北新增CSAR盐碱度\GF3C_KSC_QPSI_008440_E86.2_N44.1_20231113_L1A_AHV_L10000215823.tar.gz + D:\BaiduNetdiskDownload\xibei\GF3C_KSC_QPSI_008440_E86.0_N44.7_20231113_L1A_AHV_L10000215825.tar.gz True False File @@ -92,7 +92,7 @@ File tar.gz Cal - D:\micro\WorkSpace\Ortho\Output\GF3C_KSC_QPSI_008440_E86.2_N44.1_20231113_L1A_AHV_L10000215823-ortho.tar.gz + D:\micro\WorkSpace\ortho\Output\GF3C_KSC_QPSI_008440_E86.0_N44.7_20231113_L1A_AHV_L10000215825-ortho.tar.gz DEFAULT DEFAULT DEFAULT diff --git a/Ortho/OrthoAlg.py b/Ortho/OrthoAlg.py index fd2f2e53..a8f96466 100644 --- a/Ortho/OrthoAlg.py +++ b/Ortho/OrthoAlg.py @@ -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) \ No newline at end of file diff --git a/Ortho/OrthoMain.py b/Ortho/OrthoMain.py index 41e2e71c..44456501 100644 --- a/Ortho/OrthoMain.py +++ b/Ortho/OrthoMain.py @@ -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: diff --git a/Ortho/config.ini b/Ortho/config.ini new file mode 100644 index 00000000..f66a1bac --- /dev/null +++ b/Ortho/config.ini @@ -0,0 +1,11 @@ +# -*- coding: UTF-8 -*- +# 定义config分组 +[config] +######1-算法基本参数###### +tager = ortho +productLEVEL = 3 +# 算法名称。修改临时工作区生成临时文件的名称,日志名称; +exe_name = ortho +# 开启调试模式则不删除临时工作区,True:开启调试,False:不开启调试 +debug = False + diff --git a/atmosphericDelay-C-SAR/AtmosphericDelayMain.py b/atmosphericDelay-C-SAR/AtmosphericDelayMain.py index 0b9bfd26..fbdf3d0a 100644 --- a/atmosphericDelay-C-SAR/AtmosphericDelayMain.py +++ b/atmosphericDelay-C-SAR/AtmosphericDelayMain.py @@ -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']) diff --git a/backScattering/BackScatteringAlg.py b/backScattering/BackScatteringAlg.py index af99fc2a..09bd0d70 100644 --- a/backScattering/BackScatteringAlg.py +++ b/backScattering/BackScatteringAlg.py @@ -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() # 导出投影结果 diff --git a/backScattering/BackScatteringMain.py b/backScattering/BackScatteringMain.py index 40dcb0bd..98f3003b 100644 --- a/backScattering/BackScatteringMain.py +++ b/backScattering/BackScatteringMain.py @@ -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"}) # 设置单位 diff --git a/backScattering/config.ini b/backScattering/config.ini index 3151bf8e..0606e8a6 100644 --- a/backScattering/config.ini +++ b/backScattering/config.ini @@ -2,9 +2,10 @@ # 定义config分组 [config] ######1-算法基本参数###### -tager = -cal +tager = cal +productLEVEL = 3 # 算法名称。修改临时工作区生成临时文件的名称,日志名称; -exe_name = SoilMoisture +exe_name = BackScattering # 开启调试模式则不删除临时工作区,True:开启调试,False:不开启调试 debug = False diff --git a/deformation-C-SAR/DeformationMain.py b/deformation-C-SAR/DeformationMain.py index 3821bc63..4f2f7edb 100644 --- a/deformation-C-SAR/DeformationMain.py +++ b/deformation-C-SAR/DeformationMain.py @@ -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']) diff --git a/dem-C-SAR/DemMain.py b/dem-C-SAR/DemMain.py index 95c8026f..6779a02a 100644 --- a/dem-C-SAR/DemMain.py +++ b/dem-C-SAR/DemMain.py @@ -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']) diff --git a/soilSalinity-Train_predict/SoilSalinityTrain.xml b/soilSalinity-Train_predict/SoilSalinityTrain.xml index 09761e73..7d192108 100644 --- a/soilSalinity-Train_predict/SoilSalinityTrain.xml +++ b/soilSalinity-Train_predict/SoilSalinityTrain.xml @@ -39,7 +39,7 @@ tar.gz Man - 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 DEFAULT DEFAULT @@ -68,7 +68,7 @@ File csv Man - E:\2023xibei\soilSality.csv + D:\BaiduNetdiskDownload\soilsalinity.csv DEFAULT DEFAULT DEFAULT diff --git a/soilSalinity-Train_predict/SoilSalinityTrainMain.py b/soilSalinity-Train_predict/SoilSalinityTrainMain.py index f19e2a9a..6a9bd737 100644 --- a/soilSalinity-Train_predict/SoilSalinityTrainMain.py +++ b/soilSalinity-Train_predict/SoilSalinityTrainMain.py @@ -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') diff --git a/tool/algorithm/block/blockprocess.py b/tool/algorithm/block/blockprocess.py index 32efa1c3..5150610d 100644 --- a/tool/algorithm/block/blockprocess.py +++ b/tool/algorithm/block/blockprocess.py @@ -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):