2024-05-17 06:19:22 +00:00
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
"""
|
|
|
|
|
@Project :microproduct
|
|
|
|
|
@File :ScatteringAuxData.py
|
|
|
|
|
@Function :后向散射
|
|
|
|
|
@Author :SHJ
|
|
|
|
|
@Contact:
|
|
|
|
|
@Date :2022/6/29
|
|
|
|
|
@Version :1.0.0
|
|
|
|
|
修改历史:
|
|
|
|
|
[修改序列] [修改日期] [修改者] [修改内容]
|
|
|
|
|
1 2022-6-29 石海军 1.兼容GF3元文件和正射校正元文件提取信息
|
|
|
|
|
"""
|
2024-10-30 03:19:00 +00:00
|
|
|
|
import json
|
2024-05-17 06:19:22 +00:00
|
|
|
|
import logging
|
|
|
|
|
from xml.etree.ElementTree import ElementTree
|
|
|
|
|
import math
|
2024-10-30 03:19:00 +00:00
|
|
|
|
|
|
|
|
|
import xmltodict
|
|
|
|
|
|
2024-05-17 06:19:22 +00:00
|
|
|
|
logger = logging.getLogger("mylog")
|
|
|
|
|
|
|
|
|
|
class GF3L1AMetaData:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pass
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_QualifyValue(meta_file_path, polarization):
|
|
|
|
|
tree = ElementTree()
|
|
|
|
|
tree.parse(meta_file_path)
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
QualifyValue = float(root.find('imageinfo').find('QualifyValue').find(polarization).text)
|
|
|
|
|
return QualifyValue
|
|
|
|
|
|
2024-10-30 03:19:00 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def get_SubQualifyValue(meta_file_path, polarization, pol_id):
|
|
|
|
|
try:
|
|
|
|
|
with open(meta_file_path, 'r', encoding='utf-8') as fp:
|
|
|
|
|
HeaderFile_dom_str = fp.read()
|
|
|
|
|
HeaderFile_dom = xmltodict.parse(HeaderFile_dom_str) # 将XML转成json文本
|
|
|
|
|
HeaderFile_dom_json = json.loads(json.dumps(HeaderFile_dom))
|
|
|
|
|
QualifyValue = float(HeaderFile_dom_json['product']['imageinfo']['QualifyValue'][pol_id][polarization])
|
|
|
|
|
return QualifyValue
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise('get QualifyValue failed')
|
|
|
|
|
|
2024-05-17 06:19:22 +00:00
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_Kdb(meta_file_path, polarization):
|
|
|
|
|
tree = ElementTree()
|
|
|
|
|
tree.parse(meta_file_path)
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
Kdb = float(root.find('processinfo').find('CalibrationConst').find(polarization).text) if root.find('processinfo').find('CalibrationConst').find(polarization).text!="NULL" else 0
|
|
|
|
|
return Kdb
|
|
|
|
|
|
|
|
|
|
class OrthoMetaData:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pass
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_QualifyValue(meta_file_path, polarization):
|
|
|
|
|
tree = ElementTree()
|
|
|
|
|
tree.parse(meta_file_path)
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
QualifyValue = float(root.find('l1aInfo').find('imageinfo').find('QualifyValue').find(polarization).text)
|
|
|
|
|
return QualifyValue
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_Kdb(meta_file_path, polarization):
|
|
|
|
|
tree = ElementTree()
|
|
|
|
|
tree.parse(meta_file_path)
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
Kdb = float(root.find('l1aInfo').find('processinfo').find('CalibrationConst').find(polarization).text)
|
|
|
|
|
return Kdb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_RadarCenterFrequency(meta_file_path):
|
|
|
|
|
# 获取微波中心频率
|
|
|
|
|
tree = ElementTree()
|
|
|
|
|
tree.parse(meta_file_path)
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
RadarCenterFrequency = float(root.find('sensor').find('RadarCenterFrequency').text)
|
|
|
|
|
return RadarCenterFrequency
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_lamda(meta_file_path):
|
|
|
|
|
# 获取微波波长,单位:m
|
|
|
|
|
tree = ElementTree()
|
|
|
|
|
tree.parse(meta_file_path)
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
lamda = float(root.find('sensor').find('lamda').text)
|
|
|
|
|
return lamda
|
|
|
|
|
|
|
|
|
|
class MetaDataHandler:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_QualifyValue(meta_file_path, polarization):
|
|
|
|
|
try:
|
|
|
|
|
QualifyValue = OrthoMetaData.get_QualifyValue(meta_file_path, polarization)
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.warning('OrthoMetaData.get_QualifyValue() error!')
|
|
|
|
|
QualifyValue = GF3L1AMetaData.get_QualifyValue(meta_file_path, polarization)
|
|
|
|
|
logger.info('GF3L1AMetaData.get_QualifyValue() success!')
|
|
|
|
|
return QualifyValue
|
|
|
|
|
|
2024-10-30 03:19:00 +00:00
|
|
|
|
def get_SubQualifyValue(meta_file_path, polarization, pol_id):
|
|
|
|
|
try:
|
|
|
|
|
QualifyValue = OrthoMetaData.get_QualifyValue(meta_file_path, polarization)
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.warning('OrthoMetaData.get_QualifyValue() error!')
|
|
|
|
|
QualifyValue = GF3L1AMetaData.get_SubQualifyValue(meta_file_path, polarization, pol_id)
|
|
|
|
|
logger.info('GF3L1AMetaData.get_QualifyValue() success!')
|
|
|
|
|
return QualifyValue
|
|
|
|
|
|
2024-05-17 06:19:22 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def get_Kdb(meta_file_path, polarization):
|
|
|
|
|
try:
|
|
|
|
|
Kdb = OrthoMetaData.get_Kdb(meta_file_path, polarization)
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.warning('OrthoMetaData.get_Kdb() error!')
|
|
|
|
|
Kdb = GF3L1AMetaData.get_Kdb(meta_file_path, polarization)
|
|
|
|
|
logger.info('GF3L1AMetaData.get_Kdb() success!')
|
|
|
|
|
return Kdb
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_RadarCenterFrequency(meta_file_path):
|
|
|
|
|
# 获取微波中心频率,单位GHz
|
|
|
|
|
RadarCenterFrequency = OrthoMetaData.get_RadarCenterFrequency(meta_file_path)
|
|
|
|
|
return RadarCenterFrequency
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_lamda(meta_file_path):
|
|
|
|
|
# 获取微波波长,单位:m
|
|
|
|
|
lamda = OrthoMetaData.get_lamda(meta_file_path)
|
|
|
|
|
return lamda
|
|
|
|
|
|
|
|
|
|
class Calibration:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_Calibration_coefficient(meta_file_path, polarization):
|
|
|
|
|
calibration = [0, 0, 0, 0]
|
|
|
|
|
for i in polarization:
|
|
|
|
|
if i == 'HH':
|
|
|
|
|
quality = MetaDataHandler.get_QualifyValue(meta_file_path, i)
|
|
|
|
|
kdb = MetaDataHandler.get_Kdb(meta_file_path, i)
|
|
|
|
|
data_value = ((quality/32767)**2) * (10**((kdb/10)*-1))
|
|
|
|
|
calibration[0] = math.sqrt(data_value)
|
|
|
|
|
if i == 'HV':
|
|
|
|
|
quality = MetaDataHandler.get_QualifyValue(meta_file_path, i)
|
|
|
|
|
kdb = MetaDataHandler.get_Kdb(meta_file_path, i)
|
|
|
|
|
data_value = ((quality/32767)**2) * (10**((kdb/10)*-1))
|
|
|
|
|
calibration[1] = math.sqrt(data_value)
|
|
|
|
|
if i == 'VH':
|
|
|
|
|
quality = MetaDataHandler.get_QualifyValue(meta_file_path, i)
|
|
|
|
|
kdb = MetaDataHandler.get_Kdb(meta_file_path, i)
|
|
|
|
|
data_value = ((quality/32767)**2) * (10**((kdb/10)*-1))
|
|
|
|
|
calibration[2] = math.sqrt(data_value)
|
|
|
|
|
if i == 'VV':
|
|
|
|
|
quality = MetaDataHandler.get_QualifyValue(meta_file_path, i)
|
|
|
|
|
kdb = MetaDataHandler.get_Kdb(meta_file_path, i)
|
|
|
|
|
data_value = ((quality/32767)**2) * (10**((kdb/10)*-1))
|
|
|
|
|
calibration[3] = math.sqrt(data_value)
|
|
|
|
|
return calibration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if __name__ == '__main__':
|
|
|
|
|
# A = ScatteringAuxData()
|
|
|
|
|
# dir = 'G:\MicroWorkspace\C-SAR\AuxSAR\GF3_KAS_FSII_020008_E113.2_N23.1_20200528_L1A_HHHV_L10004829485_geo/'
|
|
|
|
|
# path = dir + 'GF3_KAS_FSII_020008_E113.2_N23.1_20200528_L1A_HHHV_L10004829485.meta.xml'
|
|
|
|
|
# path1 = dir + 'OrthoProduct.meta.xml'
|
|
|
|
|
# t1 = A.get_QualifyValue(path, 'HH')
|
|
|
|
|
# t2 = A.get_Kdb(path, 'HH')
|
|
|
|
|
# t3 = A.get_RadarCenterFrequency(path)
|
|
|
|
|
# t4 = A.get_lamda(path)
|
|
|
|
|
# pass
|