2024-01-03 01:42:21 +00:00
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
"""
|
|
|
|
|
@Project:__init__.py
|
|
|
|
|
@File:pspHAAlphaDecomposition.py Cloude-Pottier分解
|
|
|
|
|
@Function: Cloude-Pottier eigenvector/eigenvalue based decomposition of a 3x3 coherency matrix [T3]
|
|
|
|
|
(Averaging using a sliding window)
|
|
|
|
|
V1.0.1:(1)可选分解特征;(2)bin转tif格式
|
|
|
|
|
@Contact:
|
|
|
|
|
@Author:SHJ
|
|
|
|
|
@Date:2021/9/24 9:06
|
|
|
|
|
@Version:1.0.1
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import subprocess
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("mylog")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PspCloudePottierDecomposition:
|
|
|
|
|
"""
|
|
|
|
|
调用polsarpro4.2.0的Cloude-Pottier极化分解 h_a_alpha_decomposition_T3.exe
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
exeDir,
|
|
|
|
|
inT3Dir,
|
|
|
|
|
outDir,
|
|
|
|
|
exeDecomposeName='h_a_alpha_decomposition_T3.exe'):
|
|
|
|
|
"""
|
|
|
|
|
:param exeDir:exe所在目录
|
|
|
|
|
:param inT3Dir:T3矩阵目录
|
|
|
|
|
:param outDir:输出目录
|
|
|
|
|
"""
|
|
|
|
|
self.__exeName = exeDecomposeName
|
|
|
|
|
self.__exeDir = exeDir
|
|
|
|
|
self.__inT3Dir = inT3Dir
|
|
|
|
|
self.__outDir = outDir
|
|
|
|
|
self.__DecompostFlag = False
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def api_h_a_alpha_decomposition_T3(
|
|
|
|
|
self,
|
|
|
|
|
rectX,
|
|
|
|
|
rectY,
|
|
|
|
|
rectWidth,
|
|
|
|
|
rectHeight,
|
|
|
|
|
Nwin=1):
|
|
|
|
|
"""
|
|
|
|
|
:param rectX:有效区域x
|
|
|
|
|
:param rectY:有效区域y
|
|
|
|
|
:param rectWidth:有效区域宽
|
|
|
|
|
:param rectHeight:有效区域高
|
|
|
|
|
:param Nwin :Size of the (Nwin, Nwin) sliding window used to compute local estimates. (int)
|
|
|
|
|
"""
|
|
|
|
|
if self.__DecompostFlag:
|
|
|
|
|
return True
|
|
|
|
|
if len(self.__exeDir) == 0:
|
|
|
|
|
if not os.path.exists(self.__exeName):
|
|
|
|
|
logger.error(self.__exeName + ' not exists.')
|
|
|
|
|
return False
|
|
|
|
|
exePath = self.__exeName
|
|
|
|
|
else:
|
|
|
|
|
if not os.path.exists(self.__exeDir + '\\' + self.__exeName):
|
|
|
|
|
logger.error(self.__exeName + ' not exists.')
|
|
|
|
|
return False
|
|
|
|
|
exePath = self.__exeDir + '\\' + self.__exeName
|
|
|
|
|
|
|
|
|
|
if not self._checkT3Matrix(self.__inT3Dir):
|
|
|
|
|
logger.error('T3 Matrix check failed.')
|
|
|
|
|
return False
|
|
|
|
|
if not os.path.exists(self.__outDir):
|
|
|
|
|
os.makedirs(self.__outDir)
|
|
|
|
|
|
|
|
|
|
alpbetdelgam = 1
|
|
|
|
|
Lambda = 1
|
|
|
|
|
alpha = 1
|
|
|
|
|
entropy = 1
|
|
|
|
|
anisotropy = 1
|
|
|
|
|
|
2024-03-14 02:22:35 +00:00
|
|
|
|
CombHA = 0
|
|
|
|
|
CombH1mA = 0
|
|
|
|
|
Comb1mHA = 0
|
|
|
|
|
Comb1mH1mA = 0
|
2024-01-03 01:42:21 +00:00
|
|
|
|
|
|
|
|
|
Off_lig = rectX
|
|
|
|
|
Off_col = rectY
|
|
|
|
|
Sub_Nlig = rectWidth
|
|
|
|
|
Sub_Ncol = rectHeight
|
|
|
|
|
|
2024-03-14 02:22:35 +00:00
|
|
|
|
para_list = [exePath, self.__inT3Dir, self.__outDir, Nwin, Off_lig, Off_col, Sub_Nlig, Sub_Ncol, alpbetdelgam,
|
|
|
|
|
Lambda, alpha, entropy, anisotropy, CombHA, CombH1mA, Comb1mHA, Comb1mH1mA]
|
|
|
|
|
cmd = "h_a_alpha_decomposition_T3.exe -id {} -od {} -iodf T3 -nwr 1 -nwc 1 -ofr 0 -ofc 0 -fnr {} " \
|
|
|
|
|
"-fnc {} -fl1 {} -fl2 {} -fl3 {} -fl4 {} -fl5 {} -fl6 {} -fl7 {} -fl8 {} -fl9 {}".format(self.__inT3Dir,
|
|
|
|
|
self.__outDir,
|
|
|
|
|
Sub_Nlig,
|
|
|
|
|
Sub_Ncol,
|
|
|
|
|
alpbetdelgam,
|
|
|
|
|
Lambda,
|
|
|
|
|
alpha,
|
|
|
|
|
entropy,
|
|
|
|
|
anisotropy,
|
|
|
|
|
CombHA,
|
|
|
|
|
CombH1mA,
|
|
|
|
|
Comb1mHA,
|
|
|
|
|
Comb1mH1mA)
|
|
|
|
|
|
|
|
|
|
logger.info('h_a_alpha_decomposition:{}'.format(cmd))
|
|
|
|
|
result = os.system(cmd)
|
|
|
|
|
logger.info('cmd_result:{}'.format(result))
|
|
|
|
|
logger.info('h_a_alpha_decomposition finish!')
|
|
|
|
|
# cmd = " ".join(str(i) for i in para_list)
|
2024-01-03 01:42:21 +00:00
|
|
|
|
config_path = os.path.join(self.__inT3Dir, 'config.txt')
|
|
|
|
|
shutil.copyfile(config_path, os.path.join(self.__outDir, 'config.txt'))
|
2024-03-14 02:22:35 +00:00
|
|
|
|
# result_tuple = subprocess.getstatusoutput(cmd)
|
2024-01-03 01:42:21 +00:00
|
|
|
|
|
2024-03-14 02:22:35 +00:00
|
|
|
|
# if result_tuple[0] != 1 or result_tuple[1].find('error') != -1:
|
|
|
|
|
# raise Exception(result_tuple[1])
|
2024-01-03 01:42:21 +00:00
|
|
|
|
self.__DecompostFlag = True
|
|
|
|
|
return True
|
2024-03-14 02:22:35 +00:00
|
|
|
|
|
2024-01-03 01:42:21 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def _checkT3Matrix(T3Dir):
|
|
|
|
|
# 检测T3矩阵
|
|
|
|
|
if not os.path.exists(T3Dir):
|
|
|
|
|
return False
|
|
|
|
|
file_name_in_out = ['T11.bin', 'T12_real.bin', 'T12_imag.bin',
|
|
|
|
|
'T13_real.bin', 'T13_imag.bin', 'T22.bin',
|
|
|
|
|
'T23_real.bin', 'T23_imag.bin', 'T33.bin']
|
|
|
|
|
for item in file_name_in_out:
|
|
|
|
|
if not os.path.exists(T3Dir + "\\" + item):
|
|
|
|
|
return False
|
|
|
|
|
return True
|