1 from string
import ascii_uppercase
3 from mpl_toolkits
import mplot3d
5 import matplotlib.pyplot
as plt
6 from scipy.optimize
import curve_fit
9 from mpl_toolkits.mplot3d
import Axes3D
10 import matplotlib.pyplot
as plt
14 return sum(lst) / len(lst)
17 parser = argparse.ArgumentParser()
22 "-i",
"--Input", help=
"The Input File Path", required=
True)
24 args = parser.parse_args()
25 inputFile = open(args.Input,
'r')
26 lines = inputFile.readlines()
35 while (lineId < len(lines)):
36 pinDrivenLine = lines[lineId]
37 pinDriverLine = lines[lineId+1]
38 delayLine = lines[lineId+2]
39 if (pinDrivenLine.find(
"=> SLICE_X") >= 0
and pinDriverLine.find(
"=> SLICE_X") >= 0):
40 drivenDrivenSiteName = pinDrivenLine.replace(
"\n",
"").split(
" ")[3]
41 drivenSiteX = int(drivenDrivenSiteName[drivenDrivenSiteName.rfind(
42 "_X")+2:drivenDrivenSiteName.rfind(
"Y")])
44 drivenDrivenSiteName[drivenDrivenSiteName.rfind(
"Y")+1:])
45 drivenDriverSiteName = pinDriverLine.replace(
"\n",
"").split(
" ")[3]
46 driverSiteX = int(drivenDriverSiteName[drivenDriverSiteName.rfind(
47 "_X")+2:drivenDriverSiteName.rfind(
"Y")])
49 drivenDriverSiteName[drivenDriverSiteName.rfind(
"Y")+1:])
51 disX = abs(drivenSiteX-driverSiteX)
52 disY = abs(drivenSiteY-driverSiteY)
53 if (disX*disX+disY*disY>36):
54 tupleXY = (disX, disY)
55 delay = int(delayLine.split(
" ")[1])
56 if (
not tupleXY
in disXY2delay.keys()):
57 disXY2delay[tupleXY] = []
58 disXY2delay[tupleXY].append(delay)
61 delayList.append(delay)
72 z = np.array(delayList)
76 data = np.vstack((x, y, z))
80 X, Y = np.meshgrid(np.arange(0.1, 40, 1), np.arange(0.1, 120, 1))
85 A = np.c_[np.ones(data.shape[0]), (data[:, :2])**0.3, data[:, :2]**0.5]
86 C, _, _, _ = scipy.linalg.lstsq(A, data[:, 2])
88 print(
"the factors for the 3-D fitting: ", C)
92 Z = np.dot(np.c_[np.ones(XX.shape), (XX)**0.3, (YY)**0.3,
93 XX**0.5, YY**0.5], C).reshape(X.shape)
97 ax = fig.gca(projection=
'3d')
98 ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.3)
99 ax.scatter(data[:, 0], data[:, 1], data[:, 2], c=
'r', s=5, alpha=0.1)
109 print(
"delay = ", C[0] + XX**0.3*C[1]+YY **
110 0.3*C[2]+XX**0.5*C[3]+YY**0.5*C[4])