From cc9a89d40c74824f0af19a06be921b21e8af44bb Mon Sep 17 00:00:00 2001 From: shunli Date: Thu, 6 Apr 2023 23:24:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9czcore=E5=A4=9A=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E4=B8=BApool=E6=A8=A1=E5=BC=8F=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=A4=9A=E8=BF=9B=E7=A8=8B=E4=B8=8D=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyat/czcore.py | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/pyat/czcore.py b/pyat/czcore.py index e55dcf0..ba7231b 100644 --- a/pyat/czcore.py +++ b/pyat/czcore.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -from multiprocessing import Process +from multiprocessing import Process, Pool +from functools import partial from os import system import numpy as np from pyat.AcousticPara import GetEnv, Coord @@ -296,6 +297,18 @@ def call_fangwei(freq, sd, rd, bathm, ssp, sed, base, azi, isPlot=False): czdetail.reflectCz = [] return Pos.r.range, Pos.r.depth, TL[0, 0, :, :], bathm, Rays, czdetail +def child(database, freq, lat, lon, sd, rd, i): + descripts = ["正北方向", "东北方向", "正东方向", "东南方向", "正南方向", "西南方向", "正西方向", "西北方向"] + theta = np.arange(0, 359, 45) + [bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=theta[i]) + if np.mean(bathm.d) < 2000: + # 不会出现会聚区 + ddd=[] + return None + else: + ranges, depths, TL, bathym, Rays, czdetail = call_fangwei(freq, sd, rd, bathm, ssp, sed, base, azi=theta[i],isPlot=True) + czdetail.descript = descripts[i] + return CzData(theta[i], ranges, depths, TL, bathym, Rays, czdetail) def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPlot=False): sd = np.array([sourceDepth]) # Source depth @@ -303,29 +316,17 @@ def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPl results = [] ranges, depths, TL, bathym, Rays = [], [], [], [], [] - def child(i): - descripts = ["正北方向", "东北方向", "正东方向", "东南方向", "正南方向", "西南方向", "正西方向", "西北方向"] - theta = np.arange(0, 359, 45) - [bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=theta[i]) - if np.mean(bathm.d) < 2000: - # 不会出现会聚区 - ddd=[] - else: - ranges, depths, TL, bathym, Rays, czdetail = call_fangwei(freq, sd, rd, bathm, ssp, sed, base, azi=theta[i],isPlot=True) - czdetail.descript = descripts[i] - results.append(CzData(theta[i], ranges, depths, TL, bathym, Rays, czdetail)) - return results - def child_0(interval): - results=child(interval) - return results + # def child_0(interval): + # czdata=child(interval) + # return czdata ''' 计算单个方向的会聚区 ''' if azi != None: [bathm, ssp, sed, base] = GetEnv(database, 25, Coord(lon, lat), R=100, azi=azi) if np.mean(bathm.d) < 2000: - return results + return None else: - ranges, depths, TL, bathym, Rays, czdetail = call_fangwei(freq, sd, rd, bathm, ssp, sed, base, + ranges, depths, TL, bathym, Rays, czdetail = call_fangwei(freq, sd, rd, bathm, ssp, sed, base, azi, isPlot=isPlot) czdetail.descript = "{:.1f}°方向".format(azi) results.append(CzData(0, ranges, depths, TL, bathym, Rays, czdetail)) @@ -337,7 +338,14 @@ def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPl # file_cz_data.write("各个方位都不会出现会聚区") return results else: + pool = Pool(processes=8) + applyResults = [] for pi in range(8): - pi=Process(target=child_0,args=(pi,)) - pi.start() - return results \ No newline at end of file + applyResults.append(pool.apply_async(partial(child, database, freq, lat, lon, sd, rd), (pi,))) + # pi=Process(target=child_0,args=(pi,)) + # pi.start() + pool.close() + pool.join() + for applyResult in applyResults: + results.append(applyResult.get()) + return results