Skip to content

Commit

Permalink
multiprocessor Obj added and scatter3 and triangulation fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza Sadri committed Apr 30, 2021
1 parent 37b1329 commit 09da288
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
35 changes: 29 additions & 6 deletions RobustGaussianFittingLibrary/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import matplotlib.pyplot as plt
from .cWrapper import RGFCLib
from multiprocessing import Process, Queue, cpu_count
from scipy.spatial.transform import Rotation as R

class textProgBar:
"""
Expand Down Expand Up @@ -274,7 +275,26 @@ def sGHist_multi_mP(inVec, mP, SNR=3.0):
plt.bar(modelVec, np.ones(modelVec.size), color='g',alpha=0.5)
plt.show()

def scatter3(mat, inFigure = None, returnFigure = False):
""" given a matrix input of size 3 x N, it scatters it in 3D
"""
if(inFigure is None):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
figureCnt = 0
else:
fig, ax, figureCnt = inFigure
figureCnt += 1
ax.scatter(mat[0], mat[1], mat[2], label = 'Plot ' + str(figureCnt))
if(returnFigure):
return((fig, ax, figureCnt))
else:
if(figureCnt>0):
plt.legend()
plt.show()

def getTriangularVertices(n,
rotationAngles = [0, 0, 0],
phi_start = 0,
phi_end = np.pi,
plotIt = False):
Expand All @@ -285,7 +305,11 @@ def getTriangularVertices(n,
input argument
~~~~~~~~~~~~~~
n : number of vertices on the sphere
phi_start: phi_end is the pitch
rotationAngles: input must be a numpy array of three values
in radian (0~2pi) and the output will rotate according
to these angles around axes xyz.
default:[0, 0, 0]
phi_start:
default: 0
phi_end:
default: pi
Expand All @@ -297,17 +321,16 @@ def getTriangularVertices(n,
"""
goldenRatio = (1 + 5**0.5)/2
i = np.arange(0, n)
theta = (2 * np.pi / goldenRatio) * i
theta = (2*np.pi / goldenRatio) * i
phi = np.arccos(np.linspace(np.cos(phi_end), np.cos(phi_start), n))
triVecs = np.array([np.cos(theta) * np.sin(phi),
np.sin(theta) * np.sin(phi),
np.cos(phi)])
rotMat = R.from_euler('xyz', rotationAngles)
triVecs = rotMat.as_matrix() @ triVecs

if(plotIt):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(triVecs[0], triVecs[1], triVecs[2])
plt.show()
scatter3(triVecs)

return(triVecs)

Expand Down
9 changes: 4 additions & 5 deletions RobustGaussianFittingLibrary/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,7 @@ def test_getTriangularVertices():
phi_end = np.pi,
plotIt = True)


def myFunc(anInput):
def multiprocessor_targetFunc(anInput):
data, op_type = anInput
if(op_type=='mean'):
to_return = data.mean()
Expand All @@ -1259,11 +1258,11 @@ def test_multiprocessor():
for cnt in range(N):
inputs.append((Data[cnt], Param))
someMul = RobustGaussianFittingLibrary.misc.multiprocessor(
myFunc, inputs, outputIsNumpy = True, showProgress = True)
multiprocessor_targetFunc, inputs,
outputIsNumpy = True, showProgress = True)
means = np.squeeze(someMul())
print(np.array([ [means], [Data.max(1)]]).T)


if __name__ == '__main__':
print('PID ->' + str(os.getpid()))
test_getTriangularVertices()
Expand All @@ -1286,7 +1285,6 @@ def test_multiprocessor():
test_fitValueSmallSample()
test_fitValueTensor_MultiProc()
test_fitValue2Skewed()
visOrderStat()
test_removeIslands()
test_fitLineTensor_MultiProc()
test_textProgBar()
Expand All @@ -1295,5 +1293,6 @@ def test_multiprocessor():
test_PDF2Uniform()
test_RobustAlgebraicLineFittingPy()
test_multiprocessor()
visOrderStat()
print('This was robust fitting')
exit()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
------------------------------------------------------
"""
from distutils.core import setup, Extension
_version = 'v0.1.31'
_version = 'v0.1.32'
setup(
name = 'RobustGaussianFittingLibrary', # How you named your package folder (MyLib)
packages = ['RobustGaussianFittingLibrary'], # Chose the same as "name"
Expand Down

0 comments on commit 09da288

Please sign in to comment.