修改czcore多进程为pool模式,修复多进程不返回结果问题
这个提交包含在:
+28
-20
@@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process, Pool
|
||||||
|
from functools import partial
|
||||||
from os import system
|
from os import system
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pyat.AcousticPara import GetEnv, Coord
|
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 = []
|
czdetail.reflectCz = []
|
||||||
return Pos.r.range, Pos.r.depth, TL[0, 0, :, :], bathm, Rays, czdetail
|
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):
|
def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPlot=False):
|
||||||
sd = np.array([sourceDepth]) # Source depth
|
sd = np.array([sourceDepth]) # Source depth
|
||||||
@@ -303,29 +316,17 @@ def call_cz(database, freq, lat, lon, azi, sourceDepth=10, receiveDepth=10, isPl
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
ranges, depths, TL, bathym, Rays = [], [], [], [], []
|
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):
|
# def child_0(interval):
|
||||||
results=child(interval)
|
# czdata=child(interval)
|
||||||
return results
|
# return czdata
|
||||||
''' 计算单个方向的会聚区 '''
|
''' 计算单个方向的会聚区 '''
|
||||||
if azi != None:
|
if azi != None:
|
||||||
[bathm, ssp, sed, base] = GetEnv(database, 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:
|
if np.mean(bathm.d) < 2000:
|
||||||
return results
|
return None
|
||||||
else:
|
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)
|
isPlot=isPlot)
|
||||||
czdetail.descript = "{:.1f}°方向".format(azi)
|
czdetail.descript = "{:.1f}°方向".format(azi)
|
||||||
results.append(CzData(0, ranges, depths, TL, bathym, Rays, czdetail))
|
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("各个方位都不会出现会聚区")
|
# file_cz_data.write("各个方位都不会出现会聚区")
|
||||||
return results
|
return results
|
||||||
else:
|
else:
|
||||||
|
pool = Pool(processes=8)
|
||||||
|
applyResults = []
|
||||||
for pi in range(8):
|
for pi in range(8):
|
||||||
pi=Process(target=child_0,args=(pi,))
|
applyResults.append(pool.apply_async(partial(child, database, freq, lat, lon, sd, rd), (pi,)))
|
||||||
pi.start()
|
# pi=Process(target=child_0,args=(pi,))
|
||||||
|
# pi.start()
|
||||||
|
pool.close()
|
||||||
|
pool.join()
|
||||||
|
for applyResult in applyResults:
|
||||||
|
results.append(applyResult.get())
|
||||||
return results
|
return results
|
||||||
在新工单中引用
屏蔽一个用户