first approahch to vector view

master
Eggert Jung 3 years ago
parent 3f0739f6ff
commit 9eb24b9be0

@ -30,6 +30,7 @@ import numpy as np
from matplotlib import pyplot
import channels
import liveview
echoCmd = 0
@ -77,7 +78,7 @@ def Configure_Backplane(s):
#instrSend(s, "dmm.nplc = 0.1")
instrSend(s, "dmm.autorange = dmm.OFF")
instrSend(s, "dmm.range = 100")
instrSend(s, "dmm.range = 10000")
## crossover connection is made on backplane 3 & 4
instrSend(s, 'channel.setbackplane("1001:1030", "1913")')
@ -106,6 +107,15 @@ def get_mapped(arr):
return out
def get_vector_mapped(arr):
out = np.zeros(shape=(9, 10, 2))
for i in range(0,90):
x, y = channels.map[i]
out[x-1][y-1] = arr[i]
return out
def done():
instrSend(s, "beeper.beep(0.500, 440)")
instrSend(s, "beeper.beep(0.500, 440)")
@ -126,14 +136,23 @@ def done():
instrSend(s, "beeper.beep(0.150, 523)")
instrSend(s, "beeper.beep(1.000, 440)")
def calc_vector(x, y, arr):
pass
def calc_vector(px, py, point_specific_matrix):
vect = [0, 0]
for x in range(9):
for y in range(10):
if(px != x or py != y):
diff = [px-x, py-y] #Abstandsvektor
mag = np.sqrt(diff[0]**2 + diff[1]**2) #betrag
vect[0] += point_specific_matrix[x][y]*diff[0] / mag
vect[1] += point_specific_matrix[x][y]*diff[1] / mag
return vect
""" ==============================================================================================================
MAIN CODE STARTS HERE
============================================================================================================== """
parser = argparse.ArgumentParser()
parser.add_argument('-view', default="R")
parser.add_argument('-fromfile')
parser.add_argument('-tofile')
parser.add_argument('-ip', default="192.168.0.53")
@ -143,40 +162,52 @@ args = parser.parse_args()
ip_address = args.ip
port = args.port
print(ip_address)
# reserve space for matrixes
full_matrix = np.zeros(shape=(90, 90))
full_matrix = np.zeros(shape=(90, 90))
point_specific_matrix = np.zeros(shape=(9, 10))
pyplot.ion()
fig, ax = pyplot.subplots()
axim = ax.imshow(full_matrix, interpolation='nearest', cmap='gray', vmin=0, vmax=30)
t1 = time.time() # Start the timer...
if args.fromfile:
#TODO check bounds of imported matrix
full_matrix = np.genfromtxt(args.fromfile, delimiter='\t')
for row in full_matrix:
point_specific_matrix=get_mapped(row)
axim.set_data(point_specific_matrix)
fig.canvas.flush_events()
if args.view == "R":
viewer = liveview.ResistanceView(maximum=full_matrix.max())
for row in full_matrix:
point_specific_matrix=get_mapped(row)
viewer.updateView(point_specific_matrix)
if args.view == "V":
vectormap = np.zeros(shape=(90, 2))
i = 0
for row in full_matrix:
point_specific_matrix=get_mapped(row)
vectormap[i] = calc_vector(0, 0, point_specific_matrix)
i+=1
mapped_vectormap = get_vector_mapped(vectormap)
mapped_vectormap /= max(mapped_vectormap.min(), mapped_vectormap.max(), key=abs)
print(mapped_vectormap)
viewer = liveview.VectorView(mapped_vectormap)
else:
s = socket.socket() # Establish a TCP/IP socket object
instrConnect(s, ip_address, port, 20000, 0, 0)
Configure_Backplane(s)
if args.view == "R":
viewer = liveview.ResistanceView(maximum=4000)
x = 0
y = 0
print()
for ch1 in [*range(1001, 1031)] + [*range(2001, 2031)] + [*range(3001, 3031)]:
for ch2 in [*range(1031, 1061)] + [*range(2031, 2061)] + [*range(3031, 3061)]:
full_matrix[x][y]=diff_4W_mess(s, ch1, ch2)
point_specific_matrix=get_mapped(full_matrix[x])
axim.set_data(point_specific_matrix)
fig.canvas.flush_events()
if args.view == "R":
point_specific_matrix=get_mapped(full_matrix[x])
viewer.updateView(point_specific_matrix)
y+=1
y=0
x+=1
@ -186,6 +217,10 @@ else:
# Close the socket connection
instrDisconnect(s)
if args.view == "M":
viewer = liveview.ResistanceView(maximum=full_matrix.max())
viewer.updateView(get_mapped(np.mean(full_matrix, axis = 0)))
if args.tofile:
np.savetxt(args.tofile, full_matrix, delimiter="\t")

@ -0,0 +1,34 @@
import numpy as np
from matplotlib import pyplot
class ResistanceView:
def __init__(self, maximum=30):
pyplot.ion()
self.fig, self.ax = pyplot.subplots()
self.axim = self.ax.imshow(np.zeros(shape=(9, 10)), interpolation='nearest', cmap='gray', vmin=0, vmax=maximum)
def updateView(self, matrix):
self.axim.set_data(matrix)
self.fig.canvas.flush_events()
class VectorView:
def __init__(self, vectormap):
# Vector origin location
X = np.repeat(range(9), 10)
Y = np.resize(range(10), 10*9)
# Directional vectors
U = vectormap[:,:,0] # np.zeros(shape=(90))#
V = vectormap[:,:,1] # np.zeros(shape=(90))#
# Creating plot
pyplot.quiver(X, Y, U, V, color='b', units='xy', scale=1)
pyplot.title('Single Vector')
## x-lim and y-lim
#pyplot.xlim(-2, 5)
#pyplot.ylim(-2, 2.5)
# Show plot with grid
pyplot.grid()
pyplot.show()
Loading…
Cancel
Save