123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- from localization import Localization
- from plot_results import Plotting
- from ART import ART_plotting
- import matplotlib.pyplot as plt
- import numpy as np
- import re
-
-
- """------------------ A lot of generic plotting (no need to change or read anything here) -------------------------"""
- mm = 1000 # this factor will convert everything from metre to millimetre
- font = {"family": "serif", "color": "black", "size": 15}
-
- fig = plt.figure(figsize=[24, 9])
- ax1 = plt.subplot2grid((1, 2), (0, 1))
- ax2 = plt.subplot2grid((1, 2), (0, 0))
-
- plt.subplots_adjust(left=0.07, bottom=0.07, right=0.89, top=0.89, wspace=0.2, hspace=0.2)
-
- # Set Axis
- ax1.set_xlim([-0.02*mm, 0.52*mm])
- ax1.set_ylim([-0.02*mm, 0.52*mm])
- #ax1.set_xticks(np.arange(0.0*mm, 0.55*mm, 0.05*mm))
- #ax1.set_yticks(np.arange(0.0*mm, 0.55*mm, 0.05*mm))
- ax1.set_xlabel('X-Position of object [mm]', fontdict=font)
- ax1.set_ylabel('Y-Position of object [mm]', fontdict=font)
- ax1.grid(alpha=0.6)
- #for label in ax1.xaxis.get_ticklabels():
- # label.set_rotation(90)
-
- ax2.set_ylim([0.1*mm, 0.6*mm])
- ax2.set_xlim([0.0*mm, 0.2*mm])
- ax2.set_yticks(np.arange(-0.05*mm, 0.65*mm, 0.05*mm))
- ax2.set_xticks(np.arange(0.00*mm, 0.20*mm, 0.01*mm))
- ax2.set_ylabel('Y-Position of object [mm]', fontdict=font)
- ax2.set_xlabel('Z-Position of object [mm]', fontdict=font)
- ax2.grid(alpha=0.5)
- for label in ax2.xaxis.get_ticklabels():
- label.set_rotation(90)
-
- # Set Titles
- ax1.set_title("XY", fontdict=font)
- ax2.set_title("ZY", fontdict=font)
-
-
- # CONFIGURE X, Y PLOT
- # Add the legend for different data plot lines
- # data_legend = plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.)
- # data_legend = plt.gca().add_artist(data_legend)
-
- # Indicate Exciter
- Exciter = ax1.vlines(x=0.0*mm, ymin=0.0*mm, ymax=0.5*mm, linestyles="-", colors="#5b9bd5", label="Exciter", linewidth=6)
- ax1.vlines(x=0.5*mm, ymin=0.0*mm, ymax=0.5*mm, linestyles="-", colors="#5b9bd5", linewidth=6)
- ax1.hlines(y=0.0*mm, xmin=0.0*mm, xmax=0.5*mm, linestyles="-", colors="#5b9bd5", linewidth=6)
- ax1.hlines(y=0.5*mm, xmin=0.0*mm, xmax=0.5*mm, linestyles="-", colors="#5b9bd5", linewidth=6)
-
- # Indicate Localization Area
- # LocArea = ax1.vlines(x=0.045, ymin=0.045, ymax=0.495, linestyles="dashed", colors="#7f7f7f",
- # label="Loc.\nArea")
- # ax1.vlines(x=0.495, ymin=0.045, ymax=0.495, linestyles="dashed", colors="#7f7f7f")
- # ax1.hlines(y=0.045, xmin=0.045, xmax=0.495, linestyles="dashed", colors="#7f7f7f")
- # ax1.hlines(y=0.495, xmin=0.045, xmax=0.495, linestyles="dashed", colors="#7f7f7f")
-
- # SHOW ANTENNAS
- AntPosX = [0*mm, 0*mm, 0.13*mm, 0.375*mm, 0.5*mm, 0.5*mm, 0.125*mm, 0.38*mm] # Safing each Antennas Position in a list -> e.g. : X position of frame ant 1, X pos of frame ant 2, x pos of frame ant 3, ...
- AntPosY = [0.125*mm, 0.375*mm, 0.5*mm, 0.5*mm, 0.125*mm, 0.375*mm, 0*mm, 0*mm]
-
-
-
- AntOrientY = [270, 270, 180, 180, 90, 90, 0,
- 0] # analog as AntPosX,Y , just with Orientation degrees (direction in z-axis
-
- # Select Antenna plotting options here
- patchAlpha = 1.0
- # ITERATE THROUGH CMAP-------------
- n = 8
- # color = iter(cm.jet(np.linspace(0, 1, n)))
- # ----------------------------
- for i in range(8): # iterate through antennas
- x = AntPosX[i] # get x and y pos of antennas
- y = AntPosY[i]
- # c = next(color) # Comment in for coloured antennas
- c = "k" # black antennas
- if i == 7: # only print one label for the Antennas (otherwise its 8 times in legend)
- label = label = str("Receiving\nCoils")
- else:
- label = ""
- if AntOrientY[i] == 0:
- # identify antennas orientation
- patchX = float(x - 0.033*mm / 2)
- patchY = float(y - 0.033*mm / 2)
- rect = plt.Rectangle((patchX, patchY), 0.033*mm, 0.033*mm,
- color=c, alpha=patchAlpha, label=label)
- ax1.add_patch(rect)
-
- if AntOrientY[i] == 180:
- patchX = float(x - 0.033*mm / 2)
- patchY = float(y - 0.033*mm / 2)
- rect = plt.Rectangle((patchX, patchY), 0.033*mm, 0.033*mm,
- color=c, alpha=patchAlpha)
- ax1.add_patch(rect)
-
- if AntOrientY[i] == 90:
- patchX = float(x - 0.033*mm / 2)
- patchY = float(y - 0.033*mm / 2)
- rect = plt.Rectangle((patchX, patchY), 0.033*mm, 0.033*mm,
- color=c, alpha=patchAlpha)
- ax1.add_patch(rect)
- if AntOrientY[i] == 270:
- patchX = float(x - 0.033*mm / 2)
- patchY = float(y - 0.033*mm / 2)
- rect = plt.Rectangle((patchX, patchY), 0.033*mm, 0.033*mm,
- color=c, alpha=patchAlpha)
- ax1.add_patch(rect)
- """------------------- End of generic plotting stuff ----------------------------------------------------------------"""
-
-
- def plot_art(recording_number):
- """
- :param recording_name: int, Choose which recording to print e.g. Recording_!1! , Recording_!2!, etc.
- """
-
- """--------------- Open, format and save ART positions from text files---------------------------------------"""
- # Opening a recording
- art_recording = open('ART_IndLoc precision tests/Recording_' + str(recording_number) + '.txt', 'r')
- art_recording = art_recording.read()
-
- # Formatting a recording
- art_recording = re.split(' |\n', art_recording) # split string at whitespace and linebreak
- art_recording = np.array(art_recording) # list -> np.array
- # Count the total number of recorded positions
- total_pos_counter = 0
- for i in art_recording:
- if i == '6d': # this is the flag marking a 6d position (Syntax of the ART guys in the txt files)
- total_pos_counter += 1
-
- # Create an empty array which will store the ART measurement infos
- art_info = np.zeros((total_pos_counter, 7)) # [t, x, y, z, alpha, beta, gamma]
-
- # Fill the empty numpy array with the information's of the art_recording
- pos_counter = 0
- for i in range(len(art_recording)-9):
- if art_recording[i] == 'ts': # following entry is timestamp
- art_info[pos_counter] = float(art_recording[i + 1])
- if art_recording[i] == '6d': # following entries are x,y,z,alpha,beta,gamma
- art_info[pos_counter, 1] = float(art_recording[i + 3].split('[')[1]) # x (had to delete some excess text)
- art_info[pos_counter, 2] = float(art_recording[i + 4]) # y
- art_info[pos_counter, 3] = float(art_recording[i + 5]) # z
-
- art_info[pos_counter, 4] = float(art_recording[i + 6]) # alpha
- art_info[pos_counter, 5] = float(art_recording[i + 7]) # beta
- art_info[pos_counter, 6] = float(
- art_recording[i + 8].split(']')[0]) # gamma (had to delete some excess text
-
- pos_counter += 1
-
- ax1.plot(art_info[:, 1], art_info[:, 2], color="green", label="ART System", linewidth=1)
-
- print("x=", art_info[:, 1])
- print("y=", art_info[:, 2])
-
-
- # Constructors for other classes we need for plotting and localizing
- localization = Localization()
- plotting = Plotting()
-
-
- # Decide what scaling_factors and Recording
- scale_factors = np.arange(0.001, 0.0035, 0.0005)
- #scale_factors = [1]
- localization.k_nearest = 15
-
- Recording = 2 # which ART Recording to pick
-
-
- for sf in scale_factors:
- print("sf =", sf)
- localization.scale_factor = sf
-
- # Localization calculation
- localization.localize_all_samples("ART Recordings/Recording_" + str(Recording),"Recording_" + str(Recording)+"_sf=" + str(sf)) # NORMAL LOCALIZATION
-
- # localization.localize_averaged_samples(filename_localize_in.get(), filename_localize_out.get()) #AVERAGED LOCALIZATION
-
- # Load IndLoc positions
- positions = np.load("calculated_positions/Recording_" + str(Recording)+"_sf=" + str(sf) + ".npy")
- positions = positions * mm # convert from m to mm
-
- # Plot IndLoc Positions
- ax1.plot(positions[:, 0], positions[:, 1], label="sf = " + str(sf), linewidth=1)
- ax2.plot(positions[:, 2], positions[:, 1], label="sf = " + str(sf), linewidth=1)
-
-
- plot_art(Recording)
-
- ax1.legend(bbox_to_anchor=(1.01, 1.00), loc=2, borderaxespad=0.)
- plt.show()
|