First commit after changed file framework

这个提交包含在:
2023-03-14 18:52:04 +08:00
父节点 e23318c8f1
当前提交 79a6a31dc7
共修改 34 个文件,包含 5751 行新增和 0 行删除
可执行文件
+220
查看文件
@@ -0,0 +1,220 @@
# -*- coding: utf-8 -*-
import warnings
warnings.filterwarnings('ignore')
import argparse, json
def _argparse():
parser = argparse.ArgumentParser(description='剖面分析工具, 根据标准化剖面,得到声道, 跃层分析结果')
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 ("realtime" not in paramData):
print(f'{argfile}中的参数有误,请核实!')
return
realtime = paramData["realtime"]
if not realtime:
if ("ETOPO1Path" not in paramData) or ("STPath" not in paramData) or\
("lat" not in paramData) or ("lon" not in paramData) or\
("timeType" not in paramData) or ("png" not in paramData) or\
("outParam" not in paramData):
print(f'{argfile}中的参数有误,请核实!')
return
ETOPO1Path = paramData["ETOPO1Path"]
STPath = paramData["STPath"]
lat = float(paramData["lat"])
lon = float(paramData["lon"])
timeType = paramData["timeType"]
png = paramData["png"]
outParam = paramData["outParam"]
if "outPath" not in outParam:
outParam["outPath"] = ""
from pyat.DataBase import DataBase
import matplotlib.pyplot as plt
from pyat.ProfileTool import ProfileTool
import numpy as np
# 定义时间段
timeIndex = timeType
# 创建类
data = DataBase(ETOPO1Path, STPath)
# 设置时间段
data.set_timePeriod(timeIndex)
# 设置坐标
data.set_coord(lat, lon)
# 全海深速度剖面
velPf = data.get_velFullProfile()
# 设置剖面分析工具
velPfTool = ProfileTool()
velPfTool.set_profile(velPf)
# 计算表面声道
surfCh = velPfTool.get_surfaceChannel()
# 计算深海声道
deepCh = velPfTool.get_deepChannel()
# 计算跃层信息
surfSL, mainSL = velPfTool.get_springLayer()
# 导出结果文件
velPfTool.export_profileParm('velPfParam.txt')
# 导出剖面文件
# data.export_velFullProfile_txt('velFullProfile.txt')
data.export_velFullProfile_nc('velFullProfile.nc')
# 打印结果
f = open('velPfParam.txt')
lines=f.readlines()
for line in lines:
print(line)
f.close()
#输出json文件
outData = {}
outData["param"] = paramData
outData["lat"] = f'{round(velPf.lat,4)}'
outData["lon"] = f'{round(velPf.lon,4)}'
outData["botDep"] = f'{round(velPf.botDep)}'
properties = {
"表面声道轴深度": f'{round(surfCh.depAxis,2)}' if surfCh.exist else "NONE",
"表面声道声速": f'{round(surfCh.velAxis,4)}' if surfCh.exist else "NONE",
"深海声道轴深度": f'{round(deepCh.depAxis,2)}' if deepCh.exist else "NONE",
"深海声道声速": f'{round(deepCh.velAxis,4)}' if deepCh.exist else "NONE",
"表面跃层区间": f'{round(surfSL.limit[0],2)}, {round(surfSL.limit[1],2)}' if surfSL.exist else "NONE",
"表面跃层强度": f'{round(surfSL.intensity,4)}' if surfSL.exist else "NONE",
"主跃层区间": f'{round(mainSL.limit[0],2)}, {round(mainSL.limit[1],2)}' if mainSL.exist else "NONE",
"主跃层强度": f'{round(mainSL.intensity,4)}' if mainSL.exist else "NONE",
}
velPf.x = np.around(velPf.x, decimals=0)
velPf.y = np.around(velPf.y, decimals=4)
outData["out"] = {
"properties": properties,
"声剖面列表": list(zip(velPf.x,velPf.y))
}
with open(("" if outParam["outPath"]=="" else outParam["outPath"] + "/")+"profileOut.json", 'w') as jsonFile:
json.dump(outData, jsonFile, indent=4, ensure_ascii=False)
if png:
# 绘图
fig, ax = plt.subplots()
# 声速剖面
ax.plot(velPf.y, velPf.x)
if surfCh.exist:
ax.axhline(surfCh.depAxis, linestyle='--',
color='r', label='surface channel axis')
if deepCh.exist:
ax.axhline(deepCh.depAxis, linestyle='--',
color='g', label='deep channel axis')
if surfSL.exist:
ax.fill_between([1480, 1550], surfSL.limit[0],
surfSL.limit[1], alpha=0.2, color='r')
if mainSL.exist:
ax.fill_between([1480, 1550], mainSL.limit[0],
mainSL.limit[1], alpha=0.2, color='g')
ax.set_xlim(1480, 1550)
ax.invert_yaxis()
ax.set_xlabel('velocity')
ax.set_ylabel('depth')
ax.legend(loc=4)
# 显示绘图
plt.show()
else:
if ("ETOPO1Path" not in paramData) or ("STPath" not in paramData) or\
("profileFile" not in paramData) or ("png" not in paramData) or\
("outParam" not in paramData):
print(f'{argfile}中的参数有误,请核实!')
return
ETOPO1Path = paramData["ETOPO1Path"]
STPath = paramData["STPath"]
profileFile = paramData["profileFile"]
png = paramData["png"]
outParam = paramData["outParam"]
if "outPath" not in outParam:
outParam["outPath"] = ""
import matplotlib.pyplot as plt
from pyat.ProfileTool import ProfileTool
from pyat.ProfileRead import readRawProfile, processProfile
import numpy as np
# 读取实测声速剖面
velRawPf = readRawProfile(profileFile)
# 对剖面进行后处理
velPf = processProfile(velRawPf, ETOPO1Path, STPath)
# 设置剖面分析工具
velPfTool = ProfileTool()
velPfTool.set_profile(velPf)
# 计算表面声道
surfCh = velPfTool.get_surfaceChannel()
# 计算深海声道
deepCh = velPfTool.get_deepChannel()
# 计算跃层信息
surfSL, mainSL = velPfTool.get_springLayer()
# 导出结果文件
velPfTool.export_profileParm('velPfParam.txt')
# 打印结果
f = open('velPfParam.txt')
lines=f.readlines()
for line in lines:
print(line)
f.close()
#输出json文件
outData = {}
outData["param"] = paramData
outData["lat"] = f'{round(velPf.lat,4)}'
outData["lon"] = f'{round(velPf.lon,4)}'
outData["botDep"] = f'{round(velPf.botDep)}'
properties = {
"表面声道轴深度": f'{round(surfCh.depAxis,2)}' if surfCh.exist else "NONE",
"表面声道声速": f'{round(surfCh.velAxis,4)}' if surfCh.exist else "NONE",
"深海声道轴深度": f'{round(deepCh.depAxis,2)}' if deepCh.exist else "NONE",
"深海声道声速": f'{round(deepCh.velAxis,4)}' if deepCh.exist else "NONE",
"表面跃层区间": f'{round(surfSL.limit[0],2)}, {round(surfSL.limit[1],2)}' if surfSL.exist else "NONE",
"表面跃层强度": f'{round(surfSL.intensity,4)}' if surfSL.exist else "NONE",
"主跃层区间": f'{round(mainSL.limit[0],2)}, {round(mainSL.limit[1],2)}' if mainSL.exist else "NONE",
"主跃层强度": f'{round(mainSL.intensity,4)}' if mainSL.exist else "NONE",
}
velPf.x = np.around(velPf.x, decimals=0)
velPf.y = np.around(velPf.y, decimals=4)
profileList = list(zip(velPf.x,velPf.y))
outData["out"] = {
"properties": properties,
"声剖面列表": profileList
}
with open(("" if outParam["outPath"]=="" else outParam["outPath"] + "/")+"profileOut.json", 'w') as jsonFile:
json.dump(outData, jsonFile, indent=4, ensure_ascii=False)
if png:
# 绘图
fig, ax = plt.subplots()
# 声速剖面
ax.plot(velPf.y, velPf.x)
if surfCh.exist:
ax.axhline(surfCh.depAxis, linestyle='--',
color='r', label='surface channel axis')
if deepCh.exist:
ax.axhline(deepCh.depAxis, linestyle='--',
color='g', label='deep channel axis')
if surfSL.exist:
ax.fill_between([1480, 1550], surfSL.limit[0],
surfSL.limit[1], alpha=0.2, color='r')
if mainSL.exist:
ax.fill_between([1480, 1550], mainSL.limit[0],
mainSL.limit[1], alpha=0.2, color='g')
ax.set_xlim(1480, 1550)
ax.invert_yaxis()
ax.set_xlabel('velocity')
ax.set_ylabel('depth')
ax.legend(loc=4)
# 显示绘图
plt.show()
if __name__ == '__main__':
main()