550 lines
26 KiB
Python
550 lines
26 KiB
Python
"""
|
||
@Project :microproduct
|
||
@File :OnePlantHeightAlg.PY
|
||
@Function :极化干涉数据处理
|
||
@Author :LMM
|
||
@Date :2021/10/19 14:39
|
||
@Version :1.0.0
|
||
"""
|
||
from tool.algorithm.image.ImageHandle import ImageHandler
|
||
from AHVToPolSarPro import AHVToPolSarProS2
|
||
import logging
|
||
import numpy as np
|
||
import gc
|
||
import os
|
||
import shutil
|
||
import subprocess
|
||
|
||
logger = logging.getLogger("mylog")
|
||
ImageHandler = ImageHandler()
|
||
|
||
|
||
class PlantHeightAlg:
|
||
|
||
"""
|
||
使用polsarpro工具箱进行数据处理:
|
||
boxcar滤波
|
||
"""
|
||
def __init__(self):
|
||
pass
|
||
|
||
def flat_earth_removal(self, master_in_dir, slave_in_dir, flat_earth_removal_master_slave_path,
|
||
flat_earth_file, master_out_dir, slave_out_dir, *args):
|
||
"""
|
||
去地平
|
||
:param :master_in_dir 主影像文件夹
|
||
:param :slave_in_dir 辅影像文件夹
|
||
:param:flat_earth_removal_master_slave_path 去地平exe
|
||
:param :flat_earth_file 去地平文件
|
||
:param :master_out_dir 主影像输出文件夹
|
||
:param :slave_out_dir 辅影像输出文件夹
|
||
*args=*(1, realrad)
|
||
"""
|
||
if not os.path.exists(master_out_dir):
|
||
os.makedirs(master_out_dir)
|
||
if not os.path.exists(slave_out_dir):
|
||
os.makedirs(slave_out_dir)
|
||
self.api_flat_earth_removal(master_in_dir, slave_in_dir, flat_earth_removal_master_slave_path,
|
||
flat_earth_file, master_out_dir, slave_out_dir, *args)
|
||
pass
|
||
|
||
@staticmethod
|
||
def api_flat_earth_removal(master_in_dir, slave_in_dir, flat_earth_removal_master_slave_path,
|
||
flat_earth_file, master_out_dir, slave_out_dir, *args):
|
||
"""
|
||
flat_earth_removal_MasterSlave.exe
|
||
:return: 2 个 s2
|
||
"""
|
||
if not os.path.exists(flat_earth_removal_master_slave_path): # exe是否存在
|
||
raise Exception(flat_earth_removal_master_slave_path + ' is not exists!')
|
||
|
||
config_path_02 = os.path.join(slave_in_dir, 'config.txt')
|
||
|
||
conjugate_flag = int(args[0])
|
||
flat_earth_format = "realrad"
|
||
flat_earth_ieee = int(args[1]) # ? 0还是1
|
||
para_list = [flat_earth_removal_master_slave_path, slave_in_dir, slave_out_dir,
|
||
flat_earth_file, str(conjugate_flag), str(flat_earth_format), str(flat_earth_ieee)]
|
||
cmd = ' '.join(para_list)
|
||
|
||
result_tuple = subprocess.getstatusoutput(cmd)
|
||
if result_tuple[0] != 1 or result_tuple[1].find('error') != -1 or result_tuple[1].find('Could not open') != -1:
|
||
raise Exception(result_tuple[1])
|
||
|
||
shutil.copyfile(config_path_02, os.path.join(slave_out_dir, 'config.txt'))
|
||
|
||
# def flat_earth_removal(self, master_in_dir, slave_in_dir, flat_earth_removal_master_slave_path,
|
||
# flat_earth_file, master_out_dir, slave_out_dir, *args):
|
||
# """
|
||
# 去地平
|
||
# :param :master_in_dir 主影像文件夹
|
||
# :param :slave_in_dir 辅影像文件夹
|
||
# :param:flat_earth_removal_master_slave_path 去地平exe
|
||
# :param :flat_earth_file 去地平文件
|
||
# :param :master_out_dir 主影像输出文件夹
|
||
# :param :slave_out_dir 辅影像输出文件夹
|
||
# *args=*(1, realrad)
|
||
# """
|
||
# if not os.path.exists(master_out_dir):
|
||
# os.makedirs(master_out_dir)
|
||
# if not os.path.exists(slave_out_dir):
|
||
# os.makedirs(slave_out_dir)
|
||
# self.api_flat_earth_removal(master_in_dir, slave_in_dir, flat_earth_removal_master_slave_path,
|
||
# flat_earth_file, master_out_dir, slave_out_dir, *args)
|
||
# pass
|
||
#
|
||
# @staticmethod
|
||
# def api_flat_earth_removal(master_in_dir, slave_in_dir, flat_earth_removal_master_slave_path,
|
||
# flat_earth_file, master_out_dir, slave_out_dir, *args):
|
||
# """
|
||
# flat_earth_removal_MasterSlave.exe
|
||
# :return: 2 个 s2
|
||
# """
|
||
# if not os.path.exists(flat_earth_removal_master_slave_path): # exe是否存在
|
||
# raise Exception(flat_earth_removal_master_slave_path + ' is not exists!')
|
||
#
|
||
# config_path = os.path.join(master_in_dir, 'config.txt')
|
||
# config_path_02 = os.path.join(slave_in_dir, 'config.txt')
|
||
#
|
||
# conjugate_flag = int(args[0])
|
||
# flat_earth_format = "realrad" # ?
|
||
# flat_earth_ieee = int(args[1])
|
||
# para_list = [flat_earth_removal_master_slave_path, master_in_dir, slave_in_dir, master_out_dir, slave_out_dir,
|
||
# flat_earth_file, str(conjugate_flag), str(flat_earth_format), str(flat_earth_ieee)]
|
||
# cmd = ' '.join(para_list)
|
||
#
|
||
# result_tuple = subprocess.getstatusoutput(cmd)
|
||
# if result_tuple[0] != 1 or result_tuple[1].find('error') != -1 or result_tuple[1].find('Could not open') != -1:
|
||
# raise Exception(result_tuple[1])
|
||
# shutil.copyfile(config_path, os.path.join(master_out_dir, 'config.txt'))
|
||
# shutil.copyfile(config_path_02, os.path.join(slave_out_dir, 'config.txt'))
|
||
|
||
def s2_to_t6(self, master_s2_in_dir, slave_s2_in_dir, data_convert_s2_t6_path, t6_out_dir):
|
||
"""
|
||
S2->T6矩阵
|
||
:param master_s2_in_dir :输入主影像的S2文件夹
|
||
:param slave_s2_in_dir :输入辅影像的S2的文件夹
|
||
:param data_convert_s2_t6_path: data_convert_s2_t6.exe路径
|
||
:param t6_out_dir : 输出二进制T6矩阵的目录
|
||
"""
|
||
if not os.path.exists(t6_out_dir):
|
||
os.makedirs(t6_out_dir)
|
||
self.api_s2_to_t6(master_s2_in_dir, slave_s2_in_dir, data_convert_s2_t6_path, t6_out_dir)
|
||
pass
|
||
|
||
@staticmethod
|
||
def api_s2_to_t6(master_s2_in_dir, slave_s2_in_dir, data_convert_s2_t6_path, t6_out_dir):
|
||
"""
|
||
:data_convert_s2_t6.exe
|
||
:param :t6_array
|
||
:return: 滤波的矩阵
|
||
"""
|
||
if not os.path.exists(data_convert_s2_t6_path): # exe是否存在
|
||
raise Exception(data_convert_s2_t6_path + ' is not exists!')
|
||
|
||
offsetRow = 0
|
||
offsetCol = 0
|
||
|
||
config_path = os.path.join(master_s2_in_dir, 'config.txt')
|
||
config = open(config_path, 'r').read().split('\n', -1)
|
||
|
||
nligfin = int(config[1]) # FinalNlig
|
||
ncolfin = int(config[4]) # FinalNcol
|
||
|
||
ncol = int(int(config[4])) # 输入参数 ncol不确定/2
|
||
nlook_col = 1 # 缩放倍数,设置为1,输出原图大小2
|
||
nlook_lig = 1 # 缩放倍数,设置为1,输出原图大小6
|
||
# nlook_col = 2 # 缩放倍数,设置为1,输出原图大小2 # 改1
|
||
# nlook_lig = 6 # 缩放倍数,设置为1,输出原图大小6 行
|
||
|
||
para_list = [data_convert_s2_t6_path, master_s2_in_dir, slave_s2_in_dir, t6_out_dir, str(ncol),
|
||
str(offsetRow), str(offsetCol), str(nligfin), str(ncolfin), str(nlook_col), str(nlook_lig)]
|
||
|
||
cmd = ' '.join(para_list)
|
||
|
||
result_tuple = subprocess.getstatusoutput(cmd) # 参数选择
|
||
|
||
if result_tuple[0] != 1 or result_tuple[1].find('error') != -1 or result_tuple[1].find('Could not open') != -1:
|
||
raise Exception(result_tuple[1])
|
||
|
||
t11_bin = os.path.join(t6_out_dir, 'T11.bin')
|
||
arrayt11 = AHVToPolSarProS2().read_none_complex_bin_to_array(t11_bin)
|
||
rows, cols=arrayt11.shape
|
||
h1 = 'Nrow'
|
||
h2 = str(rows)
|
||
h3 = '---------'
|
||
h4 = 'Ncol'
|
||
h5 = str(cols)
|
||
h6 = '---------'
|
||
h7 = 'PolarCase'
|
||
h8 = 'monostatic' # 修改1 0315
|
||
# h8 = 'bistatic'
|
||
h9 = '---------'
|
||
h10 = 'PolarType'
|
||
h11 = 'full'
|
||
h = [h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11]
|
||
|
||
out_config_path = os.path.join(t6_out_dir, 'config.txt')
|
||
doc = open(out_config_path, 'w')
|
||
for i in range(0, 11):
|
||
print(h[i], end='', file=doc)
|
||
print('\n', end='', file=doc)
|
||
doc.close()
|
||
# shutil.copyfile(config_path, os.path.join(t6_out_dir, 'config.txt'))
|
||
|
||
def polsar_boxcar_filter(self, t6_out_dir, boxcar_filter_tool_path, t6_in_dir, *args):
|
||
"""
|
||
对porsarpro格式T6矩阵做boxcar滤波
|
||
:param t6_out_dir : 输出二进制T6矩阵的目录
|
||
:param boxcar_filter_tool_path: boxcar_filter_T6.exe路径
|
||
:param t6_in_dir
|
||
"""
|
||
if not os.path.exists(t6_out_dir):
|
||
os.makedirs(t6_out_dir)
|
||
self.api_boxcar_filter(t6_out_dir, boxcar_filter_tool_path, t6_in_dir, *args)
|
||
|
||
pass
|
||
|
||
@staticmethod
|
||
def api_boxcar_filter(data_out_dir, boxcar_filter_tool_path, t6_in_dir, *args):
|
||
"""
|
||
:func 利用Boxcar方法对T6矩阵进行滤波处理
|
||
:return: 滤波的矩阵
|
||
"""
|
||
|
||
if not os.path.exists(boxcar_filter_tool_path):
|
||
raise Exception(boxcar_filter_tool_path + ' is not exists!')
|
||
n_look = int(args[0])
|
||
n_win_filter = int(args[1]) # Filter window width 21 7
|
||
off_lig = int(args[2])
|
||
off_col = int(args[3])
|
||
|
||
config_path = os.path.join(t6_in_dir, 'config.txt')
|
||
config = open(config_path, 'r').read().split('\n', -1)
|
||
|
||
sub_nlig = int(config[1]) # ?
|
||
sub_ncol = int(config[4]) # ?
|
||
|
||
para_list = [boxcar_filter_tool_path, t6_in_dir, data_out_dir, str(n_look),
|
||
str(n_win_filter), str(off_lig), str(off_col), str(sub_nlig), str(sub_ncol)]
|
||
cmd = ' '.join(para_list)
|
||
print(cmd)
|
||
result_tuple = subprocess.getstatusoutput(cmd)
|
||
if result_tuple[0] != 1 or result_tuple[1].find('error') != -1 or result_tuple[1].find('Could not open') != -1:
|
||
raise Exception(result_tuple[1])
|
||
shutil.copyfile(config_path, os.path.join(data_out_dir, 'config.txt'))
|
||
|
||
def polsar_lee_filter(self, t6_out_dir, boxcar_filter_tool_path, t6_in_dir, *args):
|
||
"""
|
||
对porsarpro格式T6矩阵做boxcar滤波
|
||
:param t6_out_dir : 输出二进制T6矩阵的目录
|
||
:param boxcar_filter_tool_path: boxcar_filter_T6.exe路径
|
||
:param t6_in_dir
|
||
"""
|
||
if not os.path.exists(t6_out_dir):
|
||
os.makedirs(t6_out_dir)
|
||
self.api_lee_filter(t6_out_dir, boxcar_filter_tool_path, t6_in_dir, *args)
|
||
|
||
pass
|
||
|
||
@staticmethod
|
||
def api_lee_filter(data_out_dir, boxcar_filter_tool_path, t6_in_dir, *args):
|
||
"""
|
||
:func 利用Boxcar方法对T6矩阵进行滤波处理
|
||
:return: 滤波的矩阵
|
||
"""
|
||
|
||
if not os.path.exists(boxcar_filter_tool_path):
|
||
raise Exception(boxcar_filter_tool_path + ' is not exists!')
|
||
n_look = int(args[0])
|
||
n_win_filter = int(args[1]) # Filter window width 3,3
|
||
off_lig = int(args[2])
|
||
off_col = int(args[3])
|
||
|
||
config_path = os.path.join(t6_in_dir, 'config.txt')
|
||
config = open(config_path, 'r').read().split('\n', -1)
|
||
|
||
sub_nlig = int(config[1]) # ?
|
||
sub_ncol = int(config[4]) # ?
|
||
|
||
para_list = [boxcar_filter_tool_path, t6_in_dir, data_out_dir, str(n_look),
|
||
str(n_win_filter), str(off_lig), str(off_col), str(sub_nlig), str(sub_ncol)]
|
||
cmd = ' '.join(para_list)
|
||
|
||
result_tuple = subprocess.getstatusoutput(cmd)
|
||
if result_tuple[0] != 1 or result_tuple[1].find('error') != -1 or result_tuple[1].find('Could not open') != -1:
|
||
raise Exception(result_tuple[1])
|
||
shutil.copyfile(config_path, os.path.join(data_out_dir, 'config.txt'))
|
||
|
||
def complex_coherence_estimation_T6(self, t6_in_dir, coherence_estimation_path,
|
||
out_dir, *args):
|
||
"""
|
||
计算复相干系数
|
||
:param t6_in_dir : T6矩阵输入文件夹
|
||
:param coherence_estimation_path: 插件路径
|
||
:param out_dir: 输出复相干系数文件夹
|
||
:param * args:7个参数(7, 7, 7, 7)
|
||
"""
|
||
if not os.path.exists(out_dir):
|
||
os.makedirs(out_dir)
|
||
self.api_complex_coherence_estimation_T6(t6_in_dir, coherence_estimation_path,
|
||
out_dir, *args)
|
||
pass
|
||
|
||
@staticmethod
|
||
def api_complex_coherence_estimation_T6(t6_in_dir, coherence_estimation_path, out_dir, *args):
|
||
"""
|
||
调用api计算复相干系数
|
||
return :输出复相干文件路径
|
||
"""
|
||
if not os.path.exists(coherence_estimation_path):
|
||
raise Exception(coherence_estimation_path + ' is not exists!')
|
||
n_win_lig = int(args[0])
|
||
n_win_col = int(args[1])
|
||
n_filt_lig = int(args[2])
|
||
n_filt_Col = int(args[3])
|
||
|
||
off_lig = 0
|
||
off_col = 0
|
||
|
||
config_path = os.path.join(t6_in_dir, 'config.txt')
|
||
config = open(config_path, 'r').read().split('\n', -1)
|
||
sub_nlig = int(config[1]) # ?
|
||
sub_ncol = int(config[4])
|
||
|
||
# coh_avg_flag = int(args[6])
|
||
coh_avg_flag = 1 # 将1 改为 0
|
||
|
||
# 计算"HH", "VV", "HHmVV", "HHpVV"
|
||
# set_type = ["HH", "HV", "VV", "HHmVV", "HHpVV","RR","LL","LR"]
|
||
set_type= ["HHmVV","HV"]
|
||
for i in set_type:
|
||
out_type = i
|
||
|
||
para_list_01 = [coherence_estimation_path, t6_in_dir, out_dir, str(out_type),
|
||
str(n_win_lig), str(n_win_col), str(n_filt_lig), str(n_filt_Col), str(off_lig),
|
||
str(off_col), str(sub_nlig), str(sub_ncol), str(coh_avg_flag)]
|
||
cmd_01 = ' '.join(para_list_01)
|
||
|
||
result_tuple_01 = subprocess.getstatusoutput(cmd_01)
|
||
if result_tuple_01[0] != 1 or result_tuple_01[1].find('error') != -1 or result_tuple_01[1].find('Could not open') != -1:
|
||
raise Exception(result_tuple_01[1])
|
||
# shutil.copyfile(config_path, os.path.join(out_dir, 'config.txt'))
|
||
|
||
# 计算opt01\opt02
|
||
# coh_avg_flag = 1
|
||
# para_list_02 = [coherence_opt_estimation_path, t6_in_dir, out_dir, str(n_win_lig),
|
||
# str(n_win_col), str(n_filt_lig), str(n_filt_Col), str(off_lig),
|
||
# str(off_col), str(sub_nlig), str(sub_ncol), str(coh_avg_flag)]
|
||
# cmd_02 = ' '.join(para_list_02)
|
||
#
|
||
# result_tuple_02 = subprocess.getstatusoutput(cmd_02)
|
||
# if result_tuple_02[0] != 1 or result_tuple_02[1].find('error') != -1 or result_tuple_02[1].find('Could not open') != -1:
|
||
# raise Exception(result_tuple_02[1])
|
||
|
||
def height_estimation_RVOG(self, data_in_dir, height_estimation_RVOG_path, file_gamma_high_file,
|
||
file_gamma_low_file, data_out_dir, kz_file_path, *args):
|
||
"""
|
||
对porsarpro格式T6矩阵做RVOG计算
|
||
:param data_in_dir : 输入T6矩阵文件夹
|
||
:param height_estimation_RVOG_path: rvog.exe路径
|
||
:param file_gamma_high_file
|
||
:param file_gamma_low_file
|
||
:param data_out_dir :输出产品文件夹
|
||
:param kz_file_path :kz文件夹
|
||
:param * args:参数()
|
||
"""
|
||
if not os.path.exists(data_out_dir):
|
||
os.makedirs(data_out_dir)
|
||
self.api_height_estimation_RVOG(data_in_dir, height_estimation_RVOG_path, file_gamma_high_file,
|
||
file_gamma_low_file, data_out_dir, kz_file_path, *args)
|
||
|
||
@staticmethod
|
||
def api_height_estimation_RVOG(data_in_dir, height_estimation_RVOG_path, file_gamma_high_file,
|
||
file_gamma_low_file, data_out_dir, kz_file_path, *args):
|
||
"""
|
||
:func 利用Boxcar方法对T6矩阵进行滤波处理 (5, 0.5)
|
||
file_gamma_high: "HV"
|
||
file_gamma_low: "HH-VV"
|
||
:return: 滤波的矩阵
|
||
"""
|
||
|
||
if not os.path.exists(height_estimation_RVOG_path):
|
||
raise Exception(height_estimation_RVOG_path + ' is not exists!')
|
||
|
||
nwin = int(args[0])
|
||
coeff = float(args[1]) # extinction_coefficient
|
||
off_lig = 0 # offset_lig --Lines and rows offset values 偏移量0
|
||
off_col = 0 # offset_col --Lines and rows offset values 偏移量0
|
||
|
||
config_path = os.path.join(data_in_dir, 'config.txt')
|
||
config = open(config_path, 'r').read().split('\n', -1)
|
||
Ncol = int(config[4]) # Ncol --Initial image nb of lines and rows
|
||
sub_nlig = int(config[1]) # sub_nlig --Sub-image nb of lines and rows
|
||
sub_ncol = int(config[4]) # sub_ncol --Sub-image nb of lines and rows
|
||
|
||
para_list = [height_estimation_RVOG_path, data_in_dir, data_out_dir, file_gamma_high_file,
|
||
file_gamma_low_file, kz_file_path, str(nwin), str(coeff), str(Ncol),
|
||
str(off_lig), str(off_col), str(sub_nlig), str(sub_ncol)]
|
||
|
||
# para_list = [height_estimation_RVOG_path, data_in_dir, data_out_dir, kz_file_path, file_gamma_high_file,
|
||
# file_gamma_low_file, str(coeff), str(Ncol), str(nwin), str(nwin),
|
||
# str(off_lig), str(off_col), str(sub_nlig), str(sub_ncol)
|
||
# ,str(0),str(0),str(0),str(0),str(0),str(0),str(0),str(0),str(0),str(0),str(0),str(0),str(0),str(0),str(0)]
|
||
|
||
cmd = ' '.join(para_list)
|
||
print(cmd)
|
||
result_tuple = subprocess.getstatusoutput(cmd)
|
||
if result_tuple[0] != 1 or result_tuple[1].find('error') != -1 or result_tuple[1].find('Could not open') != -1:
|
||
raise Exception(result_tuple[1],cmd)
|
||
shutil.copyfile(config_path, os.path.join(data_out_dir, 'config.txt'))
|
||
|
||
|
||
class ROIAlg:
|
||
def __init__(self, ):
|
||
pass
|
||
|
||
@staticmethod
|
||
def trans_tif2mask(out_mask_path, in_tif_path, threshold_min, threshold_max=None):
|
||
"""
|
||
:param out_mask_path:mask输出路径
|
||
:param in_tif_path:输入路径
|
||
:param threshold_min:最小阈值
|
||
:param threshold_max:最大阈值
|
||
:return: True or False
|
||
"""
|
||
image_handler = ImageHandler
|
||
proj = image_handler.get_projection(in_tif_path)
|
||
geotrans = image_handler.get_geotransform(in_tif_path)
|
||
array = image_handler.get_band_array(in_tif_path, 1)
|
||
if threshold_max == None and np.isnan(threshold_min) == True :
|
||
nan = np.isnan(array)
|
||
mask = (nan.astype(int) == 0).astype(int)
|
||
image_handler.write_img(out_mask_path, proj, geotrans, mask)
|
||
elif threshold_max == None and threshold_min== -9999:
|
||
mask = (((array< -9998) & (array > -9999.9)).astype(int) == 0).astype(int)
|
||
image_handler.write_img(out_mask_path, proj, geotrans, mask)
|
||
else:
|
||
if threshold_min < threshold_max:
|
||
mask = ((array > threshold_min) & (array < threshold_max)).astype(int)
|
||
image_handler.write_img(out_mask_path, proj, geotrans, mask)
|
||
elif threshold_min > threshold_max:
|
||
mask = ((array < threshold_min) & (array > threshold_max)).astype(int)
|
||
image_handler.write_img(out_mask_path, proj, geotrans, mask)
|
||
elif threshold_max == threshold_min:
|
||
mask = ((array == threshold_min).astype(int) == 0).astype(int)
|
||
image_handler.write_img(out_mask_path, proj, geotrans, mask)
|
||
|
||
logger.info("trans_tif2mask success, path: %s", out_mask_path)
|
||
return True
|
||
|
||
@staticmethod
|
||
def combine_mask(out_mask_path, in_main_mask_path, in_sub_mask_path):
|
||
"""
|
||
:param out_mask_path:输出路径
|
||
:param in_main_mask_path:主mask路径,输出影像采用主mask的地理信息
|
||
:param in_sub_mask_path:副mask路径
|
||
"""
|
||
proj = ImageHandler.get_projection(in_main_mask_path)
|
||
geotrans = ImageHandler.get_geotransform(in_main_mask_path)
|
||
main_array = ImageHandler.get_band_array(in_main_mask_path, 1)
|
||
sub_array = ImageHandler.get_band_array(in_sub_mask_path, 1)
|
||
main_array = main_array * sub_array
|
||
del sub_array
|
||
gc.collect()
|
||
ImageHandler.write_img(out_mask_path, proj, geotrans, main_array)
|
||
logger.info("combine_mask success, path: %s", out_mask_path)
|
||
return True
|
||
|
||
@staticmethod
|
||
def cal_roi(out_tif_path, in_tif_path, mask_path, background_value=1):
|
||
"""
|
||
:param out_tif_path:ROI的影像
|
||
:param in_tif_path:计算ROI的影像
|
||
:param mask_path:掩模
|
||
:param background_value:无效区域设置的背景值
|
||
:return: True or False
|
||
"""
|
||
proj = ImageHandler.get_projection(in_tif_path)
|
||
geotrans = ImageHandler.get_geotransform(in_tif_path)
|
||
tif_array = ImageHandler.get_data(in_tif_path)
|
||
mask_array = ImageHandler.get_band_array(mask_path, 1)
|
||
tif_array = tif_array * mask_array
|
||
del mask_array
|
||
gc.collect()
|
||
tif_array[np.where(tif_array == 0)] = background_value
|
||
tif_array[np.where(tif_array <=-9998)] = background_value
|
||
ImageHandler.write_img(out_tif_path, proj, geotrans, tif_array)
|
||
logger.info("cal_roi success, path: %s", out_tif_path)
|
||
return True
|
||
|
||
|
||
# if __name__ == '__main__':
|
||
|
||
# 1、 s2->flat_earth_removal->s2 去地平 finish 缺少phi文件
|
||
# master_in_dir = r'D:\MicroWorkspace\PlantHeight\Output\master_slc'
|
||
# slave_in_dir = r'D:\MicroWorkspace\PlantHeight\Output\slave_slc'
|
||
# flat_earth_removal_masterslave_path = r'D:\11111\CODE\microproduct\onestar\vegetationHeight\\' \
|
||
# r'flat_earth_removal_MasterSlave.exe'
|
||
# flat_earth_file = r'D:\MicroWorkspace\PlantHeight\Output\phi\phi.bin'
|
||
# master_out_dir = r'D:\MicroWorkspace\PlantHeight\Output\falt_earth_remove\master_out'
|
||
# slave_out_dir = r'D:\MicroWorkspace\PlantHeight\Output\falt_earth_remove\slave_out'
|
||
# PlantHeightAlg().flat_earth_removal(master_in_dir, slave_in_dir, flat_earth_removal_masterslave_path,
|
||
# flat_earth_file, master_out_dir, slave_out_dir, *(1, 0))
|
||
|
||
# 2、 s2+s2->t6 s2转t6 finish
|
||
# master_s2_in_dir = r'D:\MicroWorkspace\PlantHeight\Output\master_slc'
|
||
# slave_s2_in_dir = r'D:\MicroWorkspace\PlantHeight\Output\slave_slc'
|
||
# data_convert_s2_t6_path = r'D:\11111\CODE\microproduct\onestar\vegetationHeight\\data_convert_MLK_S2_T6.exe'
|
||
# t6_out_dir = r'D:\MicroWorkspace\PlantHeight\Output\get_t6'
|
||
# PlantHeightAlg().s2_to_t6(master_s2_in_dir, slave_s2_in_dir, data_convert_s2_t6_path, t6_out_dir)
|
||
# print('done')
|
||
|
||
# 3、 T6->boxcar_filter->T6 boxcar滤波 finish
|
||
# boxcar_filter_tool_path = r'D:\11111\CODE\microproduct\onestar\vegetationHeight\\boxcar_filter_T6.exe'
|
||
# s2_in_dir = 'D:\MicroWorkspace\PlantHeight\Output\\get_t6'
|
||
# t6_out_dir = 'D:\MicroWorkspace\PlantHeight\Output\\out_t6'
|
||
# PlantHeightAlg().polsar_boxcar_filter(t6_out_dir, boxcar_filter_tool_path, s2_in_dir, *(1, 21, 0, 0))
|
||
# print('done')
|
||
|
||
# 4、 T6->coherence_estimation->T6 计算复相干 finish
|
||
# T6->coherence_opt_estimation->T6 计算复相干 finish
|
||
# coherence_estimation_path = r'/complex_coherence_estimation_T6.exe'
|
||
# coherence_opt_estimation_path = r"/complex_coherence_opt_estimation_T6.exe"
|
||
# t6_in_dir = r'D:\MicroWorkspace\PlantHeight\Output\boxcar_out'
|
||
# out_dir = r'D:\MicroWorkspace\PlantHeight\Output\coherence_estimation_out'
|
||
# PlantHeightAlg().complex_coherence_estimation_T6(t6_in_dir, coherence_estimation_path,
|
||
# coherence_opt_estimation_path, out_dir, * (7, 7, 7, 7, 0, 0, 1))
|
||
# print('done')
|
||
|
||
# 5、 (未跑通)s2+s2->BaselineEstimation->T6 基线估算
|
||
# alos_calc_baseline_path = r'D:\11111\CODE\microproduct\onestar\vegetationHeight\alos_calc_baseline.exe'
|
||
# master_s2_in_dir = r'D:\MicroWorkspace\PlantHeight\base\master_slc'
|
||
# slave_s2_in_dir = r'D:\MicroWorkspace\PlantHeight\base\slave_slc'
|
||
# out_dir = r'D:\MicroWorkspace\PlantHeight\base\out_dir'
|
||
# out_txt_dir = r'D:\MicroWorkspace\PlantHeight\base\out_txt_dir'
|
||
# PlantHeightAlg().alos_calc_baseline_estimation(master_s2_in_dir, slave_s2_in_dir, alos_calc_baseline_path,
|
||
# out_dir, out_txt_dir, * (0, 0, 0))
|
||
# print('done')
|
||
|
||
# 5、 T6->RVOG->产品 RVOG模型 finish
|
||
# height_estimation_inversion_RVOG_path = r'D:\11111\CODE\microproduct\onestar\vegetationHeight\height_estimation_inversion_procedure_RVOG.exe'
|
||
# data_in_dir = r'D:\MicroWorkspace\PlantHeight\base\master_slc'
|
||
# file_gamma_high_file = r"C:\Users\Administrator\Desktop\forest_height_dual\master_slc_slave_slc_FER_BOX\T6\cmplx_coh_HV.bin"
|
||
# file_gamma_low_file = r"C:\Users\Administrator\Desktop\forest_height_dual\master_slc_slave_slc_FER_BOX\T6\cmplx_coh_HHmVV.bin"
|
||
# data_out_dir = r'C:\Users\Administrator\Desktop\forest_height_dual\x'
|
||
# kz_file_path = r'C:\Users\Administrator\Desktop\forest_height_dual\box_cof\kz.bin'
|
||
# PlantHeightAlg().height_estimation_RVOG(data_in_dir, height_estimation_inversion_RVOG_path, file_gamma_high_file, file_gamma_low_file, data_out_dir, kz_file_path, *(5, 0.5, 1, 0, 0))
|
||
# print('done')
|
||
|
||
# 5、 T6->RVOG->产品 RVOG模型 finish
|
||
# height_estimation_inversion_RVOG_path = r'D:\11111\CODE\microproduct\onestar\vegetationHeight\height_estimation_inversion_procedure_RVOG.exe'
|
||
# data_in_dir = r'D:\MicroWorkspace\PlantHeight\Temporary\preprocessed\master_slave_t6_box\\'
|
||
# file_gamma_high_file = r"D:\MicroWorkspace\PlantHeight\Temporary\preprocessed\master_slave_t6_box\cmplx_coh_HV.bin"
|
||
# file_gamma_low_file = r"D:\MicroWorkspace\PlantHeight\Temporary\preprocessed\master_slave_t6_box\cmplx_coh_HHmVV.bin"
|
||
# data_out_dir = r'D:\MicroWorkspace\PlantHeight\新建文件夹'
|
||
# kz_file_path = r'D:\MicroWorkspace\PlantHeight\Temporary\kz_phi\kz.bin'
|
||
# PlantHeightAlg().height_estimation_RVOG(data_in_dir, height_estimation_inversion_RVOG_path, file_gamma_high_file,
|
||
# file_gamma_low_file, data_out_dir, kz_file_path, *(1, 0.5, 1, 0, 0))
|
||
# print('done')
|