139 lines
6.4 KiB
Python
139 lines
6.4 KiB
Python
|
||
from tool.algorithm.image.ImageHandle import ImageHandler
|
||
import numpy as np
|
||
from xml.etree.ElementTree import ElementTree, Element
|
||
|
||
|
||
class header_file_read_angle():
|
||
"""从_incidence.xml文件中读取角度,计算雷达入射角。"""
|
||
def __init__(self):
|
||
pass
|
||
def read_all_angle(self,incidence_file,hight,width):
|
||
"""从_incidence.xml文件中读取角度,存到一个数组中"""
|
||
tree = ElementTree()
|
||
tree.parse(incidence_file) # 影像头文件
|
||
root = tree.getroot()
|
||
element_trees = list(root)
|
||
|
||
all_angle_array=np.zeros((hight,width),dtype=float)
|
||
a=0
|
||
for i in range(0, len(element_trees)):
|
||
if element_trees[i].tag=='incidenceValue':
|
||
a=i
|
||
break
|
||
for j in range(0, width):
|
||
|
||
all_angle_array[:,j]=element_trees[j+a].text
|
||
return all_angle_array
|
||
|
||
def get_orisim_angle(self, ori_sim_file, all_angle_array, header_height, header_width):
|
||
"""根据ori_sim.tif文件记录的行列号去取对应的雷达入射角
|
||
ori_sim_file:正射产品
|
||
all_angle_array:从incidence.xml读取的所有雷达入射角数组
|
||
header_height:轨道参数文件记录的高
|
||
header_width:轨道参数文件记录的宽
|
||
"""
|
||
|
||
height_array = ImageHandler.get_band_array(ori_sim_file, 1)
|
||
width_array = ImageHandler.get_band_array(ori_sim_file, 2)
|
||
|
||
img_height=ImageHandler.get_img_height(ori_sim_file) # 读取影像的高度
|
||
img_width= ImageHandler.get_img_width(ori_sim_file) # 读取影像的宽度
|
||
|
||
angle_array=np.zeros((img_height, img_width),dtype=float) # 存放角度的空矩阵
|
||
for i in range(0,img_height):
|
||
for j in range(0, img_width):
|
||
x=height_array[i,j] # 取出行数值
|
||
y=width_array[i,j] # 取出列数值
|
||
if x>0 and y>0:
|
||
if x<header_height and y<header_width:
|
||
angle_array[i, j]=all_angle_array[int(x), int(y)] # 根据行列号去取对应的雷达入射角
|
||
else:
|
||
angle_array[i, j] =0
|
||
else:
|
||
angle_array[i, j] = 0
|
||
return angle_array
|
||
|
||
# 数据测试模块
|
||
# if __name__=="__main__":
|
||
#
|
||
# # 0、 准备数据
|
||
# Mas_tiff_path = r"C:\Users\Administrator\Desktop\新建文件夹6\MasterSar" # 主影像头文件存放的文件夹路径 已知
|
||
# Aux_tiff_path = r"C:\Users\Administrator\Desktop\新建文件夹6\AuxiliarySar" # 辅影像头文件存放的文件夹路径 已知
|
||
# Mas_ori_sim = r"C:\Users\Administrator\Desktop\新建文件夹6\MasterSar\ori_sim_MasterSar_preprocessed.tif" # 主影像地面p点影像 已知
|
||
# Aux_ori_sim = r"C:\Users\Administrator\Desktop\新建文件夹6\AuxiliarySar\ori_sim_AuxiliarySar_preprocessed.tif" # 辅影像地面p点影像 已知
|
||
#
|
||
# #########
|
||
# # 1.构建主辅影像行列变换模型,生成新的影像(p点坐标):out_new_master_ori_sim
|
||
# out_new_master_ori_sim= r"C:\Users\Administrator\Desktop\新建文件夹6\new_master_ori_sim.tif" # 写入新的地面p点路径
|
||
# r_plsq, c_plsq2=fine_registration().least_sqrt(Mas_ori_sim, Aux_ori_sim)
|
||
# fine_registration().get_new_master_sim(r_plsq, c_plsq2, Mas_ori_sim, out_new_master_ori_sim)
|
||
# # 2.计算卫星的空间位置和p0点的位置
|
||
#
|
||
# Orthorectification_RD_object=Orthorectification_RD() # 使用生成的out_new_master_ori_sim来计算空间位置
|
||
# Mas_p0_array, Mas_sat_array, Mas_lamda= Orthorectification_RD_object.Orthorectification(Mas_tiff_path, Mas_ori_sim)
|
||
# Aux_p0_array, Aux_sat_array, Aux_lamda= Orthorectification_RD_object.Orthorectification(Aux_tiff_path, out_new_master_ori_sim)
|
||
#
|
||
# S1=Mas_sat_array # 主影像卫星位置
|
||
# S2=Aux_sat_array # 辅影像卫星位置
|
||
# P=Mas_p0_array # 主影像计算出的p0
|
||
# # 3.计算垂直基线数组B_vertical、斜距len_S1_P、斜距len_S2_P
|
||
# B_vertical, len_S1_P, len_S2_P=fine_registration().calu_vector_angle(S1, S2, P)
|
||
# print("垂直基线计算完成")
|
||
# ########
|
||
#
|
||
# # 开始计算kz
|
||
# geo = ImageHandler.get_geotransform(Mas_ori_sim)
|
||
# pro = ImageHandler.get_projection(Mas_ori_sim)
|
||
# B_vertical_path=r"C:\Users\Administrator\Desktop\新建文件夹6\B_vertical_path.tif"
|
||
# ImageHandler.write_img(B_vertical_path, pro, geo, B_vertical, no_data='null')
|
||
#
|
||
|
||
# len_S1_P_path=r"C:\Users\Administrator\Desktop\新建文件夹6\len_S1_P_path.tif"
|
||
# ImageHandler.write_img(len_S1_P_path, pro, geo, len_S1_P, no_data='null')
|
||
# len_S2_P_path=r"C:\Users\Administrator\Desktop\新建文件夹6\len_S2_P_path.tif"
|
||
# ImageHandler.write_img(len_S2_P_path, pro, geo, len_S2_P, no_data='null')
|
||
#
|
||
#
|
||
# master_incident_file=r"C:\Users\Administrator\Desktop\新建文件夹6\MasterSar\IncidenceAngle.tif"
|
||
# Mas_lamda=0.055517
|
||
# kz_array=fine_registration().calu_kz(master_incident_file, B_vertical_path,len_S1_P_path, Mas_lamda)
|
||
# kz_array_path=r"C:\Users\Administrator\Desktop\新建文件夹6\kz_array_path.tif"
|
||
# ImageHandler.write_img(len_S2_P_path, pro, geo, kz_array, no_data='null')
|
||
# pass
|
||
|
||
|
||
|
||
# m_incidence_file=r"I:\西藏未正射\西藏\GF3_MYN_QPSI_011437_E98.7_N31.1_20181012_L1A_AHV_L10003514923\GF3_MYN_QPSI_011437_E98.7_N31.1_20181012_L1A_AHV_L10003514923.incidence.xml"
|
||
# m_ori_sim_file =r"D:\MicroWorkspace\L-SAR\VegetationHeight\Input\MasterSar\ori_sim.tif"
|
||
# m_all_angle_array=header_file_read_angle().read_all_angle(m_incidence_file,6000,8062)
|
||
# m_angle_array=header_file_read_angle().get_orisim_angle(m_ori_sim_file, m_all_angle_array)
|
||
#
|
||
#
|
||
# a_incidence_file = r"I:\西藏未正射\西藏\GF3_MYN_QPSI_011437_E98.7_N31.3_20181012_L1A_AHV_L10003514924\GF3_MYN_QPSI_011437_E98.7_N31.3_20181012_L1A_AHV_L10003514924.incidence.xml"
|
||
# a_ori_sim_file =r"D:\MicroWorkspace\L-SAR\VegetationHeight\Input\AuxiliarySar\ori_sim2.tif"
|
||
# a_all_angle_array = header_file_read_angle().read_all_angle(a_incidence_file, 6000, 8062)
|
||
# a_angle_array = header_file_read_angle().get_orisim_angle(a_ori_sim_file, a_all_angle_array)
|
||
#
|
||
# v1=m_angle_array[0:561,0:1262]
|
||
# v2=a_angle_array[0:561,0:1262]
|
||
# v1=v1/180*math.pi
|
||
# v2=v2/180 * math.pi
|
||
#
|
||
# mean = (v1 + v2) / 2
|
||
# chazhi = v1 - v2
|
||
# kz_array = 4 * math.pi * (abs(v2 - v1)) / (np.sin(mean) * 0.055517)
|
||
# pass
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|