First commit after changed file framework
这个提交包含在:
+207
@@ -0,0 +1,207 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import warnings
|
||||
warnings.filterwarnings('ignore')
|
||||
import argparse, json
|
||||
from common import NoIndent, MyEncoder
|
||||
|
||||
def _argparse():
|
||||
parser = argparse.ArgumentParser(description='tl realtime client')
|
||||
parser.add_argument('-a', '--argfile', action='store', dest='argfile', required=True, help='name of arguments file')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
parser = _argparse()
|
||||
argfile = parser.argfile
|
||||
if argfile[-5:] != '.json':
|
||||
print('输入的参数文件名有误')
|
||||
return
|
||||
with open(argfile,'r') as jsonFile:
|
||||
paramData = json.load(jsonFile)
|
||||
if ("freq" not in paramData) or ("sourceDepth" not in paramData) or\
|
||||
("receiveDepth" not in paramData) or ("modelType" not in paramData) or\
|
||||
("bathyfile" not in paramData) or ("sspfile" not in paramData) or\
|
||||
("z_min" not in paramData) or ("z_max" not in paramData) or\
|
||||
("cp_min" not in paramData) or ("cp_max" not in paramData) or\
|
||||
("cs_min" not in paramData) or ("cs_max" not in paramData) or\
|
||||
("rho_min" not in paramData) or ("rho_max" not in paramData) or\
|
||||
("ap_min" not in paramData) or ("ap_max" not in paramData) or\
|
||||
("as_min" not in paramData) or ("as_max" not in paramData) or\
|
||||
("Cb_p" not in paramData) or ("Cb_s" not in paramData) or\
|
||||
("Rhob" not in paramData) or ("Ab_p" not in paramData) or\
|
||||
("Ab_s" not in paramData) or ("png" not in paramData) or\
|
||||
("outParam" not in paramData):
|
||||
print(f'{argfile}中的参数有误,请核实!')
|
||||
return
|
||||
freq = float(paramData["freq"])
|
||||
sourceDepth = float(paramData["sourceDepth"])
|
||||
receiveDepth = float(paramData["receiveDepth"])
|
||||
modelType = paramData["modelType"]
|
||||
btyfile = paramData["bathyfile"]
|
||||
sspfile = paramData["sspfile"]
|
||||
z_min = float(paramData["z_min"])
|
||||
z_max = float(paramData["z_max"])
|
||||
cp_min = float(paramData["cp_min"])
|
||||
cp_max = float(paramData["cp_max"])
|
||||
cs_min = float(paramData["cs_min"])
|
||||
cs_max = float(paramData["cs_max"])
|
||||
rho_min = float(paramData["rho_min"])
|
||||
rho_max = float(paramData["rho_max"])
|
||||
ap_min = float(paramData["ap_min"])
|
||||
ap_max = float(paramData["ap_max"])
|
||||
as_min = float(paramData["as_min"])
|
||||
as_max = float(paramData["as_max"])
|
||||
Cb_p = float(paramData["Cb_p"])
|
||||
Cb_s = float(paramData["Cb_s"])
|
||||
Rhob = float(paramData["Rhob"])
|
||||
Ab_p = float(paramData["Ab_p"])
|
||||
Ab_s = float(paramData["Ab_s"])
|
||||
png = paramData["png"]
|
||||
outParam = paramData["outParam"]
|
||||
|
||||
from scipy.interpolate import Akima1DInterpolator
|
||||
import numpy as np
|
||||
from pyat.AcousticPara import BathyM, Base, Sed, SSP_
|
||||
from pyat.tlcore import call_Bellhop, call_krakenc, call_ram
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
bathym, ssp, sed, base = [], [], [], []
|
||||
with open(btyfile, 'r') as f:
|
||||
lines = f.readlines()
|
||||
if len(lines) < 1:
|
||||
print(f'{btyfile}中的参数有误,请核实!')
|
||||
return
|
||||
# 读取数据
|
||||
data = np.loadtxt(btyfile, skiprows=1, usecols=(0, 1))
|
||||
bathym = BathyM(data[:, 0], data[:, 1])
|
||||
|
||||
profile_num = 0
|
||||
with open(sspfile, 'r') as f:
|
||||
try:
|
||||
line = f.readline()
|
||||
profile_num = int((line.split())[0])
|
||||
while line:
|
||||
line = f.readline()
|
||||
if '距离' in line:
|
||||
ranges, depths, vels = [], [], []
|
||||
line = f.readline()
|
||||
while line and ('分隔符' not in line):
|
||||
ranges.append(1)
|
||||
depths.append(float((line.split())[0]))
|
||||
vels.append(float((line.split())[1]))
|
||||
line = f.readline()
|
||||
ssp.append(SSP_(ranges, depths, vels))
|
||||
except Exception as err:
|
||||
print(f'{sspfile}中的参数有误,请核实!')
|
||||
print(err)
|
||||
return
|
||||
|
||||
"""akima 0829"""
|
||||
z_ssp = np.array([])
|
||||
for i in range(len(ssp)):
|
||||
z_ssp = np.append(z_ssp, ssp[i].z)
|
||||
z_ssp = np.unique(z_ssp)
|
||||
z_ssp = np.sort(z_ssp)
|
||||
|
||||
for i in range(len(ssp)):
|
||||
dep = ssp[i].z
|
||||
vel = ssp[i].c
|
||||
# 对剖面进行垂向插值处理
|
||||
depInterp = z_ssp[z_ssp<=ssp[i].z[-1]]
|
||||
# 应用Akima插值算法,对ssp进行插值
|
||||
func = Akima1DInterpolator(dep, vel)
|
||||
velInterp = func(depInterp)
|
||||
# 剖面赋值
|
||||
ssp[i].z = depInterp
|
||||
ssp[i].c = velInterp
|
||||
len_real = len(depInterp)-1
|
||||
#for it in range(len_real,int(deep_max)):
|
||||
# ssp[i].c = np.append(ssp[i].c,0)
|
||||
|
||||
# Sediment
|
||||
z = np.array([z_min, z_max])
|
||||
cp = np.array([cp_min, cp_max])
|
||||
cs = np.array([cs_min, cs_max])
|
||||
rho = np.array([rho_min, rho_max])
|
||||
a_p = np.array([ap_min, ap_max])
|
||||
a_s = np.array([as_min, as_max])
|
||||
for it in range(profile_num):
|
||||
sed.append(Sed(z, cp, cs, rho, a_p, a_s))
|
||||
|
||||
# Base
|
||||
base = []
|
||||
for it in range(profile_num):
|
||||
base.append(Base(Cb_p, Cb_s, Rhob, Ab_p, Ab_s))
|
||||
|
||||
ranges, depths, TL = [], [], []
|
||||
if modelType == 'bellhop':
|
||||
sd = np.array([sourceDepth]) # Source depth
|
||||
rd = np.linspace(0, receiveDepth, int(receiveDepth / 10)) # Receiving depth
|
||||
[Pos, TL] = call_Bellhop(freq, sd, rd, bathym, ssp, sed, base)
|
||||
ranges, depths, TL = Pos.r.range, Pos.r.depth, TL[0,0,:,:]
|
||||
# Plot
|
||||
if png:
|
||||
plt.pcolor(Pos.r.range, Pos.r.depth, TL[0, 0, :, :], vmin=40, vmax=130, cmap='jet_r', shading='auto')
|
||||
plt.xlabel("Range/m")
|
||||
plt.ylabel("Depth/m")
|
||||
plt.gca().invert_yaxis()
|
||||
plt.colorbar()
|
||||
plt.show()
|
||||
print(TL[0, 0, :, :])
|
||||
elif modelType == 'kraken':
|
||||
sd = np.array([sourceDepth]) # Source depth
|
||||
rd = np.linspace(0, receiveDepth, int(receiveDepth / 10)) # Receiving depth
|
||||
[Pos, TL] = call_krakenc(freq, sd, rd, bathym, ssp, sed, base)
|
||||
ranges, depths, TL = Pos.r.range, Pos.r.depth, TL[0,0,:,:]
|
||||
# Plot
|
||||
if png:
|
||||
plt.pcolor(Pos.r.range, Pos.r.depth, TL[0, 0, :, :], vmin=40, vmax=130, cmap='jet_r', shading='auto')
|
||||
plt.xlabel("Range/m")
|
||||
plt.ylabel("Depth/m")
|
||||
plt.gca().invert_yaxis()
|
||||
plt.colorbar()
|
||||
plt.show()
|
||||
elif modelType == 'ram':
|
||||
# 调用ram模块
|
||||
[rd, rr, TL] = call_ram(freq, sourceDepth, receiveDepth, bathym, ssp, sed)
|
||||
ranges, depths, TL = rr, rd, TL
|
||||
# Plot
|
||||
if png:
|
||||
plt.pcolormesh(rr, rd, TL, vmin=60, vmax=130, cmap='jet_r', shading='auto')
|
||||
plt.xlabel("Range/m")
|
||||
plt.ylabel("Depth/m")
|
||||
plt.gca().invert_yaxis()
|
||||
plt.colorbar()
|
||||
plt.show()
|
||||
|
||||
# 保存地形数据
|
||||
bathym.r = np.around(bathym.r, decimals=0)
|
||||
bathym.d = np.around(bathym.d, decimals=0)
|
||||
bathymData = {
|
||||
"param": paramData,
|
||||
"count": len(bathym.d),
|
||||
"descript": "距离、深度",
|
||||
"data": NoIndent(list(zip(bathym.r, bathym.d)))
|
||||
}
|
||||
with open(("" if outParam["outPath"]=="" else outParam["outPath"] + "/")+"tlRealtimeOut_bathym.json", 'w') as jsonFile:
|
||||
json_data = json.dumps(bathymData, cls=MyEncoder, indent=2, ensure_ascii=False)
|
||||
jsonFile.write(json_data)
|
||||
|
||||
# 保存传播损失数据
|
||||
tlpoint = []
|
||||
depths = np.around(depths, decimals=0)
|
||||
ranges = np.around(ranges, decimals=0)
|
||||
TL = np.around(TL, decimals=2)
|
||||
tlpoint = list(zip(np.tile(depths.reshape(len(depths),1),len(ranges)).flatten(), np.tile(ranges,(len(depths),1)).flatten(), TL.flatten()))
|
||||
tlData = {
|
||||
"param": paramData,
|
||||
"count": len(ranges)*len(depths),
|
||||
"descript": "距离、深度、损失",
|
||||
"data": NoIndent(tlpoint)
|
||||
}
|
||||
with open(("" if outParam["outPath"]=="" else outParam["outPath"] + "/")+"tlRealtimeOut_tl.json", 'w') as jsonFile:
|
||||
json_data = json.dumps(tlData, cls=MyEncoder, indent=2, ensure_ascii=False)
|
||||
jsonFile.write(json_data)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
在新工单中引用
屏蔽一个用户