From ea2a7195a957a17e93808c99de7cc3430c7c787e Mon Sep 17 00:00:00 2001 From: shunli Date: Tue, 28 Mar 2023 11:31:57 +0800 Subject: [PATCH] Added para datasource to database, modified calling method of database --- .gitignore | 2 ++ cs.py | 4 +--- cz.py | 9 ++++++++- pyat/DataBase.py | 2 +- pyat/czcore.py | 14 ++++---------- pyat/tlcore.py | 14 ++++---------- tl.py | 12 ++++++++++-- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 7b015dd..6d5e539 100644 --- a/.gitignore +++ b/.gitignore @@ -161,6 +161,7 @@ cython_debug/ #.idea/ .vscode/ +out/ packages/ pyat/at/ pyat/bin/ @@ -169,3 +170,4 @@ test/ *.json *.c +*.sh diff --git a/cs.py b/cs.py index 2711cf2..eebf917 100644 --- a/cs.py +++ b/cs.py @@ -29,8 +29,6 @@ def main(): outParam = paramData["outParam"] from pyat.cscore import np, dis_mats, pn_funcs, ag_funcs - import sys - print(sys.path) # 输出: @@ -85,4 +83,4 @@ def main(): # jsonFile.write(json_data) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/cz.py b/cz.py index 753f88d..a1e3698 100644 --- a/cz.py +++ b/cz.py @@ -44,13 +44,20 @@ def main(): from pyat.czcore import call_cz import numpy as np + # 定义时间段 + timeIndex = timeType + # 创建类 + database = DataBase(ETOPO1Path, STPath,datasource="") + # 设置时间段 + database.set_timePeriod(timeIndex) + # call_cz函数返回汇聚区计算的中间值CzData的列表 # CzData保存了方位角、距离、深度、损失、地形、会聚区等数据 # 其中czdata.azi是方位角、czdata.ranges是距离列表、czdata.depths是深度列表、 # czdata.TL是损失、czdata.bathym是地形数据 # czdata.Rays是声线数据 # czdata.CzDetail是会聚区数据,包括会聚区宽度和距离 - res = call_cz(ETOPO1Path, STPath, freq, lat, lon, azi, sourceDepth, receiveDepth, timeType=timeType) + res = call_cz(database, freq, lat, lon, azi, sourceDepth, receiveDepth) # call_cz(25, 18.0, 114.0, 10, 3500) # write data to file diff --git a/pyat/DataBase.py b/pyat/DataBase.py index 5c21c5e..f099021 100644 --- a/pyat/DataBase.py +++ b/pyat/DataBase.py @@ -33,7 +33,7 @@ class DataBase(): """ 获取数据库中的剖面信息 """ - def __init__(self,ETOPO1path,STpath): + def __init__(self,ETOPO1path,STpath,dataSource): # 打开ETOPO1数据 fileETOPO1 = ETOPO1path+'/ETOPO1_Bed_g_gmt4.nc' dataETOPO1 = Dataset(fileETOPO1) diff --git a/pyat/czcore.py b/pyat/czcore.py index c3af077..5e66740 100644 --- a/pyat/czcore.py +++ b/pyat/czcore.py @@ -277,22 +277,16 @@ def call_fangwei(freq, sd, rd, bathm, ssp, sed, base, isPlot=False): czdetail.reflectCz = [] return Pos.r.range, Pos.r.depth, TL[0, 0, :, :], bathm, Rays, czdetail -def call_cz(ETOPO1Path, STPath, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, timeType='Annual', isPlot=False): +def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPlot=False): sd = np.array([sourceDepth]) # Source depth rd = np.linspace(0, receiveDepth, 351) # Receiving depth - # 定义时间段 - timeIndex = timeType - # 创建类 - data = DataBase(ETOPO1Path, STPath) - # 设置时间段 - data.set_timePeriod(timeIndex) results = [] ranges, depths, TL, bathym, Rays = [], [], [], [], [] ''' 计算单个方向的会聚区 ''' if azi != None: - [bathm, ssp, sed, base] = GetEnv(data, 25, Coord(lon, lat), R=100, azi=azi) + [bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=azi) if np.mean(bathm.d) < 2000: return results else: @@ -302,7 +296,7 @@ def call_cz(ETOPO1Path, STPath, freq, lat, lon, azi, sourceDepth=10, receiveDept return results ''' 计算8个方向的会聚区 ''' - [bathm, ssp, sed, base] = GetEnv(data, 25, Coord(lon, lat), R=100, azi=0) + [bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=0) if bathm.d[0] < 2000: # file_cz_data.write("各个方位都不会出现会聚区") return results @@ -310,7 +304,7 @@ def call_cz(ETOPO1Path, STPath, freq, lat, lon, azi, sourceDepth=10, receiveDept descripts = ["正北方向", "东北方向", "正东方向", "东南方向", "正南方向", "西南方向", "正西方向", "西北方向"] theta = np.arange(0, 359, 45) for i in range(8): - [bathm, ssp, sed, base] = GetEnv(data, 25, Coord(lon, lat), R=100, azi=theta[i]) + [bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=theta[i]) if np.mean(bathm.d) < 2000: # 不会出现会聚区 continue diff --git a/pyat/tlcore.py b/pyat/tlcore.py index cf4e1ff..bbd8c15 100644 --- a/pyat/tlcore.py +++ b/pyat/tlcore.py @@ -6,8 +6,8 @@ from pyat.krakenc import call_krakenc from pyat.ram import call_ram import matplotlib.pyplot as plt -def call_tl(ETOPO1Path, STPath, freq, sourceDepth, sourceLat, sourceLon, receiveDepth, - receiveLat=None, receiveLon=None, range=None, azi=None, timeType='Annual', modelType='kraken', isPlot=False): +def call_tl(database, freq, sourceDepth, sourceLat, sourceLon, receiveDepth, + receiveLat=None, receiveLon=None, range=None, azi=None, modelType='kraken', isPlot=False): """ Input: freq - float, Frequency sourceDepth - float, Source depth @@ -29,18 +29,12 @@ def call_tl(ETOPO1Path, STPath, freq, sourceDepth, sourceLat, sourceLon, receive TL 传播损失 bathym类 地形数据 bathym.r距离 bathym.d深度 """ - # 定义时间段 - timeIndex = timeType - # 创建类 - data = DataBase(ETOPO1Path, STPath) - # 设置时间段 - data.set_timePeriod(timeIndex) bathym, ssp, sed, base = [], [], [], [] if (receiveLat != None) and (receiveLon != None): - [bathym, ssp, sed, base] = GetEnv(data, 25, Coord(sourceLon, sourceLat), coordR=Coord(receiveLon, receiveLat)) + [bathym, ssp, sed, base] = GetEnv(database, 25, Coord(sourceLon, sourceLat), coordR=Coord(receiveLon, receiveLat)) elif (range != None) and (azi != None): - [bathym, ssp, sed, base] = GetEnv(data, 25, Coord(sourceLon, sourceLat), R=range, azi=azi) + [bathym, ssp, sed, base] = GetEnv(database, 25, Coord(sourceLon, sourceLat), R=range, azi=azi) else: print('no receive info!') return [], [], [], bathym diff --git a/tl.py b/tl.py index aedb543..5e67943 100644 --- a/tl.py +++ b/tl.py @@ -42,8 +42,16 @@ def main(): from pyat.tlcore import call_tl import numpy as np - [ranges, depths, TL, bathym] = call_tl(ETOPO1Path, STPath, freq=freq, sourceDepth=sourceDepth, sourceLat=sLat, sourceLon=sLon, receiveDepth=receiveDepth, - receiveLat=rLat, receiveLon=rLon, timeType=timeType, modelType=modelType, isPlot=png) + + # 定义时间段 + timeIndex = timeType + # 创建类 + database = DataBase(ETOPO1Path, STPath) + # 设置时间段 + database.set_timePeriod(timeIndex) + + [ranges, depths, TL, bathym] = call_tl(database=database, freq=freq, sourceDepth=sourceDepth, sourceLat=sLat, sourceLon=sLon, receiveDepth=receiveDepth, + receiveLat=rLat, receiveLon=rLon, modelType=modelType, isPlot=png) # write data to file # 保存地形数据