Browse Source

P1-P42 analyze script!

master
seyffejn 3 years ago
parent
commit
3d59b97a09
15 changed files with 329 additions and 243 deletions
  1. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/current_positions.npy
  2. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/horizontal_and_diagonal_sf=0.0020410410410410407_k=3.npy
  3. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.001_k=3.npy
  4. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.00204_k=3.npy
  5. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.002105105105105105_k=3.npy
  6. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.002_k=3.npy
  7. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.003_k=3.npy
  8. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.004_k=3.npy
  9. BIN
      BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.005_k=3.npy
  10. 275
    217
      BachelorThesis/Software/PyPrecisionGUI/plot_precision_tests.py
  11. 8
    6
      BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.aux
  12. 24
    14
      BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.log
  13. BIN
      BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.pdf
  14. BIN
      BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.synctex.gz
  15. 22
    6
      BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.tex

BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/current_positions.npy View File


BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/horizontal_and_diagonal_sf=0.0020410410410410407_k=3.npy View File


BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.001_k=3.npy View File


BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.00204_k=3.npy View File


BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.002105105105105105_k=3.npy View File


BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.002_k=3.npy View File


BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.003_k=3.npy View File


BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.004_k=3.npy View File


BIN
BachelorThesis/Software/PyPrecisionGUI/calculated_positions/off_center_sf=0.005_k=3.npy View File


+ 275
- 217
BachelorThesis/Software/PyPrecisionGUI/plot_precision_tests.py View File

@@ -16,6 +16,82 @@ xy_subplot = plt.subplot2grid((1, 2), (0, 1))
yz_subplot = plt.subplot2grid((1, 2), (0, 0))


# Load all the IndLoc Recordings
center = np.load("recorded_data/center.npy")[1:, :, :]
off_center = np.load("recorded_data/off_center.npy")[1:, :, :]
horizontal = np.load("recorded_data/horizontal.npy")[1:, :, :]
diagonal = np.load("recorded_data/diagonal.npy")[1:, :, :]
zigzag_1 = np.load("recorded_data/zigzag_1.npy")
zigzag_2 = np.load("recorded_data/zigzag_2.npy")
wave_1 = np.load("recorded_data/wave_1.npy")
wave_2 = np.load("recorded_data/wave_2.npy")
spiral_1 = np.load("recorded_data/spiral_1.npy")
half_current_horizontal = np.load("recorded_data/half_current_horizontal.npy")[1:, :, :]
half_current_diagonal = np.load("recorded_data/half_current_diagonal.npy")[1:, :, :]
double_current_horizontal = np.load("recorded_data/double_current_horizontal.npy")[1:, :, :]
double_current_diagonal = np.load("recorded_data/half_current_diagonal.npy")[1:, :, :]
z_axis = np.load("recorded_data/z_axis.npy")[1:, :, :]
z_axis_off_center = np.load("recorded_data/z_axis_off_center.npy")[1:, :, :]
Three_D_movement_1 = np.load("recorded_data/3D_movement_1.npy")
Three_D_movement_2 = np.load("recorded_data/3D_movement_2.npy")
Three_D_zigzag_1 = np.load("recorded_data/3D_zigzag_1.npy")
Three_D_zigzag_2 = np.load("recorded_data/3D_zigzag_2.npy")
z_axis_moving_1 = np.load("recorded_data/z_axis_moving_1.npy")
# z_axis_moving_2 = np.load("recorded_data/z_axis_moving_2.npy") # Recording missing?
z_wave_1 = np.load("recorded_data/z_wave_1.npy")
z_wave_2 = np.load("recorded_data/z_wave_2.npy")

recordings_dict = {"center": center, # shape: (26, 2000, 19) = [P1-P25, 2k samples, fv]
"off_center": off_center,
"horizontal": horizontal,
"diagonal": diagonal,
"horizontal_and_diagonal": np.append(horizontal, diagonal, axis=0),
"zigzag_1": zigzag_1,
"zigzag_2": zigzag_2,
"wave_1": wave_1,
"wave_2": wave_2,
"spiral_1": spiral_1,
"half_current_horizontal": half_current_horizontal,
"half_current_diagonal": half_current_diagonal,
"double_current_horizontal": double_current_horizontal,
"double_current_diagonal": double_current_diagonal,
"z_axis": z_axis,
"z_axis_off_center": z_axis_off_center,
"Three_D_movement_1": Three_D_movement_1,
"Three_D_movement_2": Three_D_movement_2,
"Three_D_zigzag_1": Three_D_zigzag_1,
"Three_D_zigzag_2": Three_D_zigzag_2,
"z_axis_moving_1": z_axis_moving_1,
"z_wave_1": z_wave_1,
"z_wave_2": z_wave_2}


# this only takes the first sample of each recording
recording_dict_fs = {"center": center[:, 0, :],
"off_center": off_center[:, 0, :],
"horizontal": horizontal[:, 0, :],
"diagonal": diagonal[:, 0, :],
"horizontal_and_diagonal": recordings_dict["horizontal_and_diagonal"][:, 0, :],
"zigzag_1": zigzag_1[0, :],
"zigzag_2": zigzag_2[0, :],
"wave_1": wave_1[0, :],
"wave_2": wave_2[0, :],
"spiral_1": spiral_1[0, :],
"half_current_horizontal": half_current_horizontal[:, 0, :],
"half_current_diagonal": half_current_diagonal[:, 0, :],
"double_current_horizontal": double_current_horizontal[:, 0, :],
"double_current_diagonal": double_current_diagonal[:, 0, :],
"z_axis": z_axis[:, 0, :],
"z_axis_off_center": z_axis_off_center[:, 0, :],
"Three_D_movement_1": Three_D_movement_1[0, :],
"Three_D_movement_2": Three_D_movement_2[0, :],
"Three_D_zigzag_1": Three_D_zigzag_1[0, :],
"Three_D_zigzag_2": Three_D_zigzag_2[0, :],
"z_axis_moving_1": z_axis_moving_1[0, :],
"z_wave_1": z_wave_1[0, :],
"z_wave_2": z_wave_2[0, :]}


def plot_surroundings():
font = {"family": "serif", "color": "black", "size": 15}

@@ -130,11 +206,7 @@ def plot_surroundings():
# yz_subplot.add_patch(rect2)


plot_art_call_counter = 1 # used for annotating P1 to P25


def plot_art(recording_name, annotate_point):
global plot_art_call_counter
def art_file_to_position(recording_name):
"""
:param recording_name: int, Choose which recording to print e.g. Recording_!1! , Recording_!2!, etc.
"""
@@ -173,105 +245,30 @@ def plot_art(recording_name, annotate_point):

pos_counter += 1

if label_flag: # only add the label to one of the points
xy_subplot.scatter(art_info[0, 1], art_info[0, 2], color="green", label="ART System", s=100, marker="x")
yz_subplot.scatter(art_info[0, 3], art_info[0, 2], color="green", label="ART System", s=100, marker="x")
else:
xy_subplot.scatter(art_info[0, 1], art_info[0, 2], color="green", s=100, marker="x")
yz_subplot.scatter(art_info[0, 3], art_info[0, 2], color="green", s=100, marker="x")

#print("ART: x=", art_info[0, 1], ", y=", art_info[0, 2], ", z=", art_info[0, 3])

if annotate_point:
xy_subplot.annotate("P" + str(plot_art_call_counter), (art_info[0, 1], art_info[0, 2]), color="green", size=15)
yz_subplot.annotate("P" + str(plot_art_call_counter), (art_info[0, 3], art_info[0, 2]), color="green", size=15)
plot_art_call_counter += 1

# print("x=", art_info[:, 1])
# print("y=", art_info[:, 2])
pos = [art_info[0, 1], art_info[0, 2], art_info[0, 3]]
pos = [art_info[0, 1], art_info[0, 2], art_info[0, 3]] # only take the first x,y,z position of each recording (as the 0.33mm precision wont have a lot of noise anyways)
return pos

center = np.load("recorded_data/center.npy")[1:, :, :]
off_center = np.load("recorded_data/off_center.npy")[1:, :, :]
horizontal = np.load("recorded_data/horizontal.npy")[1:, :, :]
diagonal = np.load("recorded_data/diagonal.npy")[1:, :, :]
zigzag_1 = np.load("recorded_data/zigzag_1.npy")
zigzag_2 = np.load("recorded_data/zigzag_2.npy")
wave_1 = np.load("recorded_data/wave_1.npy")
wave_2 = np.load("recorded_data/wave_2.npy")
spiral_1 = np.load("recorded_data/spiral_1.npy")
half_current_horizontal = np.load("recorded_data/half_current_horizontal.npy")[1:, :, :]
half_current_diagonal = np.load("recorded_data/half_current_diagonal.npy")[1:, :, :]
double_current_horizontal = np.load("recorded_data/double_current_horizontal.npy")[1:, :, :]
double_current_diagonal = np.load("recorded_data/half_current_diagonal.npy")[1:, :, :]
z_axis = np.load("recorded_data/z_axis.npy")[1:, :, :]
z_axis_off_center = np.load("recorded_data/z_axis_off_center.npy")[1:, :, :]
Three_D_movement_1 = np.load("recorded_data/3D_movement_1.npy")
Three_D_movement_2 = np.load("recorded_data/3D_movement_2.npy")
Three_D_zigzag_1 = np.load("recorded_data/3D_zigzag_1.npy")
Three_D_zigzag_2 = np.load("recorded_data/3D_zigzag_2.npy")
z_axis_moving_1 = np.load("recorded_data/z_axis_moving_1.npy")
# z_axis_moving_2 = np.load("recorded_data/z_axis_moving_2.npy") # Recording missing?
z_wave_1 = np.load("recorded_data/z_wave_1.npy")
z_wave_2 = np.load("recorded_data/z_wave_2.npy")

recordings_dict = {"center": center, # shape: (26, 2000, 19) = [P1-P25, 2k samples, fv]
"off_center": off_center,
"horizontal": horizontal,
"diagonal": diagonal,
"horizontal_and_diagonal": np.append(horizontal, diagonal, axis=0),
"zigzag_1": zigzag_1,
"zigzag_2": zigzag_2,
"wave_1": wave_1,
"wave_2": wave_2,
"spiral_1": spiral_1,
"half_current_horizontal": half_current_horizontal,
"half_current_diagonal": half_current_diagonal,
"double_current_horizontal": double_current_horizontal,
"double_current_diagonal": double_current_diagonal,
"z_axis": z_axis,
"z_axis_off_center": z_axis_off_center,
"Three_D_movement_1": Three_D_movement_1,
"Three_D_movement_2": Three_D_movement_2,
"Three_D_zigzag_1": Three_D_zigzag_1,
"Three_D_zigzag_2": Three_D_zigzag_2,
"z_axis_moving_1": z_axis_moving_1,
"z_wave_1": z_wave_1,
"z_wave_2": z_wave_2}

# print("recordings_dict: ", recordings_dict["zigzag_1"])
# print("shape: recordings_dict: ", np.shape(recordings_dict["zigzag_1"]))
def plot_art_positions(positions, annotate_flag, markersize, annotation_size):

# this only takes the first sample of each recording
recording_dict_fs = {"center": center[:, 0, :],
"off_center": off_center[:, 0, :],
"horizontal": horizontal[:, 0, :],
"diagonal": diagonal[:, 0, :],
"horizontal_and_diagonal": recordings_dict["horizontal_and_diagonal"][:, 0, :],
"zigzag_1": zigzag_1[0, :],
"zigzag_2": zigzag_2[0, :],
"wave_1": wave_1[0, :],
"wave_2": wave_2[0, :],
"spiral_1": spiral_1[0, :],
"half_current_horizontal": half_current_horizontal[:, 0, :],
"half_current_diagonal": half_current_diagonal[:, 0, :],
"double_current_horizontal": double_current_horizontal[:, 0, :],
"double_current_diagonal": double_current_diagonal[:, 0, :],
"z_axis": z_axis[:, 0, :],
"z_axis_off_center": z_axis_off_center[:, 0, :],
"Three_D_movement_1": Three_D_movement_1[0, :],
"Three_D_movement_2": Three_D_movement_2[0, :],
"Three_D_zigzag_1": Three_D_zigzag_1[0, :],
"Three_D_zigzag_2": Three_D_zigzag_2[0, :],
"z_axis_moving_1": z_axis_moving_1[0, :],
"z_wave_1": z_wave_1[0, :],
"z_wave_2": z_wave_2[0, :]}
for i in range(len(positions)):
if i == 0: # only add the label to one of the points
xy_subplot.scatter(positions[i, 0], positions[i, 1], color="green", label="ART System", s=markersize, marker="x")
yz_subplot.scatter(positions[i, 2], positions[i, 1], color="green", label="ART System", s=markersize, marker="x")
else:
xy_subplot.scatter(positions[i, 0], positions[i, 1], color="green", s=markersize, marker="x")
yz_subplot.scatter(positions[i, 2], positions[i, 1], color="green", s=markersize, marker="x")

#print("ART: x=", art_info[0, 1], ", y=", art_info[0, 2], ", z=", art_info[0, 3])

if annotate_flag:
xy_subplot.annotate("P" + str(i+1), (positions[i, 0], positions[i, 1]), color="green", size=annotation_size)
yz_subplot.annotate("P" + str(i+1), (positions[i, 2], positions[i, 1]), color="green", size=annotation_size)


def calc_multiple_positions(recording_name, only_fs, sf_list, k_list):
def calc_multiple_positions(data, output_filename, only_fs, sf_list, k_list):
"""
Takes a recording name and calculates a lot of positions for it, for each given scaling_factor and k_nearest_factor
and stores them all as numpy arrays in folder "calculated_positions/..."
@@ -279,28 +276,45 @@ def calc_multiple_positions(recording_name, only_fs, sf_list, k_list):
:param only_fs: only take first sample of recording
:param sf_list: list with all scaling factors to localize with
:param k_list: list with all k_nearest factors to localize with
:param output_filename: it saves the positions under this name. It adds stuff like the scaling factor , k-nearest automatically
:return returns an array containing all positions [3, len(sf_list)*len(k_list)]
"""
if only_fs:
data = recording_dict_fs[recording_name]
else:
data = recordings_dict[recording_name]

positions = np.zeros((len(sf_list)*len(k_list), np.shape(data)[0], 3)) # shape: [1000, 42, 3] = [Combinations of sf and k, P1-P42, 3 xyz]

path_list = []
i = 0
j = 0
print("----Calculating positions for ", len(sf_list) * len(k_list), " combinations of sf and k-----")
for sf in sf_list:
localization.scale_factor = sf
for k in k_list:
localization.k_nearest = k
localization.localize_all_samples_direct(data, recording_name + "_sf=" + str(sf) + "_k=" + str(k))
path_list.append("calculated_positions/"+recording_name + "_sf=" + str(sf) + "_k=" + str(k)+".npy")
positions[(i+j), :, :] = localization.localize_all_samples_direct(data, output_filename + "_sf=" + str(sf) + "_k=" + str(k))

if len(k_list) != 1: # only increment this if we have multiple k_nearests getting tested
j += 1
if len(sf_list) != 1: # only increment i if we have mutliple scaling factors getting tested
i += 1
print("progress ", i, "/", (len(sf_list)*len(k_list)))
print("----Finished all position calculations-----")
for path in path_list:
print(path)
return positions


def plot_multiple_positions(recording_name, sf_list, k_list, only_label_once, xy_title, yz_title, annotate_points, labels, color_all_black):
global plot_art_call_counter
def plot_multiple_positions(positions_filename, sf_list, k_list, only_label_once, xy_title, yz_title, annotate_points, labels, color_all_black, markersize, annotationsize):
"""
You can give this function the name of an IndLoc recording and a bunch of scaling factors and k-nearests
and it will plot you all of them.
:param recording_name:
:param sf_list:
:param k_list:
:param only_label_once:
:param xy_title:
:param yz_title:
:param annotate_points:
:param labels:
:param color_all_black:
:return:
"""
colors = iter(plt.cm.jet(np.linspace(0, 1, len(sf_list)*len(k_list))))
#markers = iter(['o', '8', 'p', '>', 'd', 'H', 'x','v', '^','*', 'D','s', 'h', '+', '<'])
markers = iter(['x', 'x'])
@@ -310,23 +324,23 @@ def plot_multiple_positions(recording_name, sf_list, k_list, only_label_once, xy
for k in k_list:
color = next(colors)
marker = next(markers)
positions = np.load("calculated_positions/"+recording_name + "_sf=" + str(sf) + "_k=" + str(k)+".npy")
positions = np.load("calculated_positions/"+positions_filename + "_sf=" + str(sf) + "_k=" + str(k)+".npy")
# print("Plotting positions for: sf=", sf, ", k=", k, positions) # show all positions
print("Plotting positions for: sf=", sf, ", k=", k) # minimal print view
if color_all_black:
xy_subplot.scatter(positions[:, 0], positions[:, 1], marker=marker, color="black", label=next(labels), s=100)
yz_subplot.scatter(positions[:, 2], positions[:, 1], marker=marker, color="black", s=100)
xy_subplot.scatter(positions[:, 0], positions[:, 1], marker=marker, color="black", label=next(labels), s=markersize)
yz_subplot.scatter(positions[:, 2], positions[:, 1], marker=marker, color="black", s=markersize)
if annotate_points:
for i in range(len(positions[:, 0])):
xy_subplot.annotate("P" + str(i + 1), (positions[i, 0], positions[i, 1]), color="black", size=15)
yz_subplot.annotate("P" + str(i + 1), (positions[i, 2], positions[i, 1]), color="black", size=15)
xy_subplot.annotate("P" + str(i + 1), (positions[i, 0], positions[i, 1]), color="black", size=annotationsize)
yz_subplot.annotate("P" + str(i + 1), (positions[i, 2], positions[i, 1]), color="black", size=annotationsize)
else:
xy_subplot.scatter(positions[:, 0], positions[:, 1], marker=marker, facecolor=color, label=next(labels))
yz_subplot.scatter(positions[:, 2], positions[:, 1], marker=marker, facecolor=color)
if annotate_points:
for i in range(len(positions[:, 0])):
xy_subplot.annotate("P" + str(i + 1), (positions[i, 0], positions[i, 1]), color=color, size=15)
yz_subplot.annotate("P" + str(i + 1), (positions[i, 2], positions[i, 1]), color=color, size=15)
xy_subplot.annotate("P" + str(i + 1), (positions[i, 0], positions[i, 1]), color=color, size=annotationsize)
yz_subplot.annotate("P" + str(i + 1), (positions[i, 2], positions[i, 1]), color=color, size=annotationsize)



@@ -334,124 +348,168 @@ def plot_multiple_positions(recording_name, sf_list, k_list, only_label_once, xy
xy_subplot.set_title(str(yz_title), size=20)


def eval_loc(IndLoc_pos, ART_pos):
"""
Takes 2 arrays full of x,y,z positions. Calculated the distance between the two for each position.
Then calculates the distance for each point. Then the mean_distance and the standard_deviation of all positions together.

recording_selection = "horizontal_and_diagonal"
:param IndLoc_pos: np.array[i, 3] (a number of positions: x,y,z)
:param ART_pos: np.array[i, 3] (a number of positions: x,y,z)
:return: distances, mean_distance, std_dev_distance
"""

if np.shape(IndLoc_pos) != np.shape(ART_pos):
print("During calc distance function. Positions arrays dont have the same shape. \n IndLoc (shape):",
np.shape(IndLoc_pos), " ART (shape):", np.shape(ART_pos))
else:
distances = np.zeros((np.shape(IndLoc_pos)[0], 1)) # create an array containing all distances
for i in range(np.shape(IndLoc_pos)[0]): # iterate through all positions
x_IndLoc = IndLoc_pos[i, 0]
y_IndLoc = IndLoc_pos[i, 1]
z_IndLoc = IndLoc_pos[i, 2]

x_ART = ART_pos[i, 0]
y_ART = ART_pos[i, 1]
z_ART = ART_pos[i, 2]

distance = math.sqrt(
(x_IndLoc - x_ART) ** 2 + (y_IndLoc - y_ART) ** 2) # calculate difference for each position
distances[i] = distance
# print("i", i)
# print("IndLoc: x=", x_IndLoc, ", y=", y_IndLoc)
# print("ART: x=", x_ART, ", y=", y_ART)

mean_distance = np.mean(distances)
std_dev_distance = np.std(distances)

return distances, round(mean_distance, 2), round(std_dev_distance, 2)


def load_entire_ART(recording_names):
"""
:param recording_names: list of all recording that are to be loaded ["center", "horizontal", "diagonal"]
:return: an array containing them all appended together
"""
x_list = []
y_list = []
z_list = []

for i in range(len(recording_names)): # iterate through list of wanted recordings
print("Loading ART", recording_names[i])
for j in range(1, 30): # it always starts with "P1 and ends variable but never over P30"
try:
current_pos = art_file_to_position(recording_names[i]+"_P"+(str(j)))
x_list.append(current_pos[0])
y_list.append(current_pos[1])
z_list.append(current_pos[2])
except FileNotFoundError:
break

pos = np.zeros((len(x_list), 3))

pos[:, 0] = x_list
pos[:, 1] = y_list
pos[:, 2] = z_list

return pos



# Normal ART Loading (1 Recording)
# for i in range(1, 26):
# print("i", i)
# # if i <= 21:
# # pos = plot_art("horizontal_P" + str(i), annotate_point=False)
# if i == 26:
# label_flag = True
# pos = plot_art(recording_selection+"_P" + str(i), annotate_point=False)
# x_list.append(pos[0])
# y_list.append(pos[1])
# z_list.append(pos[2])


# Make the plot look nice
plot_surroundings()

# Load ART positions
ART_pos = load_entire_ART(["double_current_horizontal", "double_current_diagonal"])

# Load IndLoc data
horizontal = recordings_dict["double_current_horizontal"]
diagonal = recordings_dict["double_current_diagonal"]
IndLoc_data = np.append(horizontal, diagonal, axis=0) # shape (42, 2000, 19) = (P1-P42, 2k samples, fv)

# Average IndLoc data
IndLoc_data = np.average(IndLoc_data, axis=1) # shape (42, 19) = (P1-P42, fv_avg)

# # std dev and average calculations
ART = np.zeros((42, 3))
label_flag = False
# Localize IndLoc data for each scaling factor in sf_list and each k in k_list
sf_list = [0.001] # [0.002]
k_list = [3]
IndLoc_pos = calc_multiple_positions(data=IndLoc_data,
output_filename="horizontal_diagonal",
only_fs=True,
sf_list=sf_list,
k_list=k_list)

x_list = []
y_list = []
z_list = []
# Find the best localization
best_mean = 10000
best_std_dev = 10000
best_both = 10000
for i in range((len(sf_list)*len(k_list))):
distances, curr_mean, curr_std_dev = eval_loc(ART_pos=ART_pos, IndLoc_pos=IndLoc_pos[i])

for i in range(1, 43):
print("i", i)
if i <= 21:
pos = plot_art("horizontal_P" + str(i), annotate_point=False)
else:
if i == 42:
label_flag = True
pos = plot_art("diagonal_P" + str(i-21), annotate_point=False)
x_list.append(pos[0])
y_list.append(pos[1])
z_list.append(pos[2])

ART[:, 0] = x_list
ART[:, 1] = y_list
ART[:, 2] = z_list


# print("ART shape", np.shape(ART))
# print("ART nach dem laden:\n", ART)


IndLoc = np.zeros((42, 3))
data = recording_dict_fs[recording_selection]

scale_factor_list = [0.00204] #[0.001755, 0.001, 0.002, 0.003, 0.004, 0.005]
print("Testing so many scaling_factors: ", len(scale_factor_list))
min_avg = 10000
min_std = 10000
min_both = 10000

best_sf = 0
mean_at_best_sf = 1000
std_at_best_sf = 1000

for s_f in scale_factor_list:
localization.scale_factor = s_f
localization.k_nearest = 3
IndLoc = localization.localize_all_samples_direct(data, "current_positions")

# print("IndLoc shape", np.shape(IndLoc))
# print("IndLoc:\n", IndLoc)


distances = np.zeros((42, 1))
for i in range(np.shape(IndLoc)[0]):
x_IndLoc = IndLoc[i, 0]
y_IndLoc = IndLoc[i, 1]
z_IndLoc = IndLoc[i, 2]

x_ART = ART[i, 0]
y_ART = ART[i, 1]
z_ART = ART[i, 2]

distance = math.sqrt( (x_IndLoc - x_ART)**2 + (y_IndLoc - y_ART)**2 )
distances[i] = distance
# print("i", i)
# print("IndLoc: x=", x_IndLoc, ", y=", y_IndLoc)
# print("ART: x=", x_ART, ", y=", y_ART)

avg_distance = np.average(distances)
median_distance = np.median(distances)
mean_distance = np.mean(distances)
std_dev_distance = np.std(distances)

both = avg_distance + std_dev_distance

if avg_distance < min_avg:
min_avg = avg_distance
# print("[mean]minimum found at scaling_factor = ", s_f, "; min_avg = ", min_both)
if std_dev_distance < min_std:
min_std = std_dev_distance
# print("[std_dev]minimum found at scaling factor = ", s_f, "; min_std = ", min_std)
if both < min_both:
min_both = both
# print("[both]scaling factor for lowest min_both = ", s_f, "; min_both = ", min_both)
best_sf = s_f
mean_at_best_sf = avg_distance
std_at_best_sf = std_dev_distance

print("Best scaling factor = ", best_sf, " mean = ", mean_at_best_sf, "std_dev = ", std_at_best_sf, "; min_both = ", min_both)

# print("avg_distance", avg_distance)
# print("median_distance", median_distance)
# print("mean_distance", mean_distance)
# print("std dev distance", std_dev_distance)

calc_multiple_positions(recording_name=recording_selection,
only_fs=True,
sf_list=[best_sf],
k_list=[3])
curr_both = curr_mean + curr_std_dev

if curr_mean <= best_mean:
best_both = curr_both
best_mean = curr_mean
best_std_dev = curr_std_dev
index = i

plot_multiple_positions(recording_name=recording_selection,
best_sf = sf_list[index]

print("\n----Best localization parameters were found!-----\n scaling_factor = ", best_sf, "\n mean_error = ", best_mean,
"\n standard_deviation = ", best_std_dev)


# Plot IndLoc pos
plot_multiple_positions(positions_filename="horizontal_diagonal",
sf_list=[best_sf],
k_list=[3],
k_list=k_list,
only_label_once=True,
xy_title="Testing the scaling factor for the entire localization area",
yz_title="Testing the scaling factor for the entire localization area",
xy_title="Statistical optimization of the scaling factor for the entire localization area",
yz_title="Statistical optimization of the scaling factor for the entire localization area",
annotate_points=False,
labels=iter(["scaling factor = " + str(best_sf)]),
color_all_black=True)


annotationsize=15,
labels=iter(["scaling factor = " + str("{:.6f}".format(best_sf))]),
color_all_black=True,
markersize=100)

# Plot ART positions
plot_art_positions(ART_pos, annotate_flag=False, markersize=100, annotation_size=15)


# print(IndLoc_pos)
#recording_selection = "horizontal_and_diagonal"



# scale_factor_list = [0.001755]
#
# calc_multiple_positions(recording_name=recording_selection,
# only_fs=True,
# sf_list=[0.001755],
# k_list=[3])
#
# plot_multiple_positions(recording_name=recording_selection,
# sf_list=[0.001755],
# k_list=[3],
# only_label_once=True,
# xy_title="Statistical optimization of the scaling factor for an offcenter set of points",
# yz_title="Statistical optimization of the scaling factor for an offcenter set of points",
# annotate_points=False,
# labels=iter(["scaling factor = " + str("{:.6f}".format(0.001755))]),
# color_all_black=True)

xy_subplot.legend(bbox_to_anchor=(1.01, 1.00), loc=2, borderaxespad=0., fontsize=10)
plt.show()

+ 8
- 6
BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.aux View File

@@ -190,15 +190,17 @@
\newlabel{fig:estimation_scaling_factor_1}{{14}{21}}
\@writefile{lof}{\contentsline {figure}{\numberline {15}{\ignorespaces A zoomed in view of Figure \ref {fig:estimation_scaling_factor_1} shows which scaling factors result in a localization closest to the correct positions.\relax }}{22}\protected@file@percent }
\newlabel{fig:estimation_scaling_factor_2}{{15}{22}}
\@writefile{lof}{\contentsline {figure}{\numberline {16}{\ignorespaces Placing the object in 25 positions near the centre of the localization area with a scaling factor of 0.001755, resulting in mean error $\mu = 3.757\textit {m}m$ and standard deviation $\sigma = 3.279\textit {m}m$.\relax }}{23}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {16}{\ignorespaces Placing the object in 25 positions near the centre of the localization area with a scaling factor of 0.001755, resulting in mean error $\mu = 3.76\textit {m}m$ and standard deviation $\sigma = 3.28\textit {m}m$.\relax }}{23}\protected@file@percent }
\newlabel{fig:estimation_scaling_factor_3}{{16}{23}}
\@writefile{lof}{\contentsline {figure}{\numberline {17}{\ignorespaces The localization with a scaling factor of 0.001755 with a set of points which is located more towards the edges of the localization area\relax }}{24}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {17}{\ignorespaces Placing the object in 25 positions near the corner of the localization area with a scaling factor of 0.001755, , resulting in mean error $\mu = 6.18\textit {m}m$ and standard deviation $\sigma = 7.71\textit {m}m$.\relax }}{24}\protected@file@percent }
\newlabel{fig:estimation_scaling_factor_4}{{17}{24}}
\@writefile{lof}{\contentsline {figure}{\numberline {18}{\ignorespaces Using the entire localization area. The best scaling factor was found at 0.00204 $\mu = 7.42 \tmspace +\medmuskip {.2222em} \sigma = 6.48$\relax }}{24}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {18}{\ignorespaces Placing the object in 42 positions running from the centre to the edges of the localization area with a scaling factor of 0.00204, , resulting in mean error $\mu = 7.42\textit {m}m$ and standard deviation $\sigma = 6.48\textit {m}m$.\relax }}{24}\protected@file@percent }
\newlabel{fig:estimation_scaling_factor_5}{{18}{24}}
\@writefile{toc}{\contentsline {section}{\numberline {6}RESULTS}{25}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {7}DISCUSSION}{26}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {8}SUMMARY, OUTLOOK INTO THE FUTURE}{27}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {19}{\ignorespaces With averaged IndLoc feature vectors 0.00204, , resulting in mean error $\mu = 7.34\textit {m}m$ and standard deviation $\sigma = 6.49\textit {m}m$.\relax }}{25}\protected@file@percent }
\newlabel{fig:estimation_scaling_factor_6}{{19}{25}}
\@writefile{toc}{\contentsline {section}{\numberline {6}RESULTS}{26}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {7}DISCUSSION}{27}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {8}SUMMARY, OUTLOOK INTO THE FUTURE}{28}\protected@file@percent }
\bibdata{Literatur_BA_2}
\bibcite{HARRIEHAUSEN.2020b}{1}
\bibcite{Albach.2014}{2}

+ 24
- 14
BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.log View File

@@ -1,4 +1,4 @@
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7250 64-bit) (preloaded format=pdflatex 2020.4.5) 9 FEB 2021 09:08
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7250 64-bit) (preloaded format=pdflatex 2020.4.5) 9 FEB 2021 13:48
entering extended mode
**"./2021_Seyffer_Investigating the precision of an induction-based localizatio
n system for medical applications.tex"
@@ -1079,23 +1079,33 @@ LaTeX Warning: `h' float specifier changed to `ht'.
File: Images/estimation_scaling_factor_5.png Graphic file (type png)
<use Images/estimation_scaling_factor_5.png>
Package pdftex.def Info: Images/estimation_scaling_factor_5.png used on input
line 575.
line 580.
(pdftex.def) Requested size: 372.48503pt x 257.75844pt.

LaTeX Warning: `h' float specifier changed to `ht'.

[23 <./Images/estimation_scaling_factor_3.png>] [24 <./Images/estimation_scalin
g_factor_4.png> <./Images/estimation_scaling_factor_5.png>] [25
<Images/estimation_scaling_factor_6.png, id=169, 928.21782pt x 625.58719pt>
File: Images/estimation_scaling_factor_6.png Graphic file (type png)
<use Images/estimation_scaling_factor_6.png>
Package pdftex.def Info: Images/estimation_scaling_factor_6.png used on input
line 592.
(pdftex.def) Requested size: 371.28055pt x 250.23044pt.

] [26
LaTeX Warning: `h' float specifier changed to `ht'.

[23 <./Images/estimation_scaling_factor_3.png>] [24 <./Images/estimation_scalin
g_factor_4.png> <./Images/estimation_scaling_factor_5.png>] [25 <./Images/estim
ation_scaling_factor_6.png>] [26

] [27

] [28

]
("2021_Seyffer_Investigating the precision of an induction-based localization s
ystem for medical applications.bbl" [28
ystem for medical applications.bbl" [29

] [29]) [30]
] [30]) [31]
("2021_Seyffer_Investigating the precision of an induction-based localization s
ystem for medical applications.aux") )
(\end occurred inside a group at level 1)
@@ -1103,10 +1113,10 @@ ystem for medical applications.aux") )
### semi simple group (level 1) entered at line 27 (\begingroup)
### bottom level
Here is how much of TeX's memory you used:
16145 strings out of 492482
326303 string characters out of 3121123
413498 words of memory out of 3000000
20168 multiletter control sequences out of 15000+200000
16153 strings out of 492482
326600 string characters out of 3121123
413508 words of memory out of 3000000
20176 multiletter control sequences out of 15000+200000
14809 words of font info for 52 fonts, out of 3000000 for 9000
1141 hyphenation exceptions out of 8191
64i,19n,83p,1843b,12246s stack positions out of 5000i,500n,10000p,200000b,50000s
@@ -1133,10 +1143,10 @@ ers/Julian/AppData/Local/Programs/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cms
y9.pfb><C:/Users/Julian/AppData/Local/Programs/MiKTeX 2.9/fonts/type1/public/am
sfonts/cm/cmti10.pfb>
Output written on "2021_Seyffer_Investigating the precision of an induction-bas
ed localization system for medical applications.pdf" (33 pages, 5459603 bytes).
ed localization system for medical applications.pdf" (34 pages, 5505845 bytes).

PDF statistics:
253 PDF objects out of 1000 (max. 8388607)
258 PDF objects out of 1000 (max. 8388607)
0 named destinations out of 1000 (max. 500000)
244 words of extra memory for PDF output out of 10000 (max. 10000000)
249 words of extra memory for PDF output out of 10000 (max. 10000000)


BIN
BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.pdf View File


BIN
BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.synctex.gz View File


+ 22
- 6
BachelorThesis/Writing/2021_Seyffer_Investigating the precision of an induction-based localization system for medical applications.tex View File

@@ -548,12 +548,12 @@ The standard deviation for each scaling factor was calculated with the formula:
\begin{figure}[h]
\includegraphics[scale=0.4]{estimation_scaling_factor_3}
\centering
\caption{Placing the object in 25 positions near the centre of the localization area with a scaling factor of 0.001755, resulting in mean error $\mu = 3.757\milli\metre$ and standard deviation $\sigma = 3.279\milli\metre$.}
\caption{Placing the object in 25 positions near the centre of the localization area with a scaling factor of 0.001755, resulting in mean error $\mu = 3.76\milli\metre$ and standard deviation $\sigma = 3.28\milli\metre$.}
\label{fig:estimation_scaling_factor_3}
\end{figure}

\newpage
Each equation was applied to a total of 500 scaling factors ((0.0015, 0.002, 0.000001 - start, stop, step)). An optimum was found at a scaling factor of 0.001755 with $\mu = 3.757$ and $\sigma = 3.279$ resulting in the localization which can be seen in Figure \ref{fig:estimation_scaling_factor_3}. In order to verify these results another set of positions was used, which was positioned more to the edge of the localization area.
Each equation was applied to a total of 500 different scaling factors ((0.0015, 0.002, 0.000001 - start, stop, step)). An optimum was found at a scaling factor of 0.001755 with $\mu = 3.76\milli\metre \:$ and $\sigma = 3.28\milli\metre \:$ resulting in the localization which can be seen in Figure \ref{fig:estimation_scaling_factor_3}. In order to verify these results another set of positions was used, which was positioned more to the edge of the localization area.

\begin{comment}
avg distance 3.757373465139104
@@ -565,21 +565,37 @@ std dev distance 3.2792325092288714
\begin{figure}[h]
\includegraphics[scale=0.4]{estimation_scaling_factor_4}
\centering
\caption{The localization with a scaling factor of 0.001755 with a set of points which is located more towards the edges of the localization area}
\caption{Placing the object in 25 positions near the corner of the localization area with a scaling factor of 0.001755, , resulting in mean error $\mu = 6.18\milli\metre$ and standard deviation $\sigma = 7.71\milli\metre$.}
\label{fig:estimation_scaling_factor_4}
\end{figure}

As the localization accuracy declined it suggested that for each position of the setup a different scaling factor optimum could be found. For this reason the whole localization system had to be taken into account.
Statistically optimizing the scaling factor for the off center set of points resulted in a scaling factor of 0.002105. Resulting in a mean error $\mu = 6.18\milli\metre \:$ and a standard deviation $\sigma = 7.71\milli\metre$.

\begin{comment}
Best scaling factor = mean = 6.180273611932338 std_dev = 7.715220033729418 ; min_both = 13.895493645661755
\end{comment}
As the localization accuracy declined it suggested that the optimal scaling factor is positional dependant. For this reason the whole localization system had to be taken into account (Figure \ref{fig:estimation_scaling_factor_5}).

\begin{figure}[h]
\includegraphics[scale=0.4]{estimation_scaling_factor_5}
\centering
\caption{Using the entire localization area. The best scaling factor was found at 0.00204 $\mu = 7.42 \: \sigma = 6.48$}
\caption{Placing the object in 42 positions running from the centre to the edges of the localization area with a scaling factor of 0.00204, , resulting in mean error $\mu = 7.42\milli\metre$ and standard deviation $\sigma = 6.48\milli\metre$.}
\label{fig:estimation_scaling_factor_5}
\end{figure}

\begin{comment}
best sf = 0.00204 mean = 7.421424662824991 std dev = 6.481103235160666 ; min both = 13.902527897985657
\end{comment}


\begin{figure}[h]
\includegraphics[scale=0.4]{estimation_scaling_factor_6}
\centering
\caption{With averaged IndLoc feature vectors 0.00204, , resulting in mean error $\mu = 7.34\milli\metre$ and standard deviation $\sigma = 6.49\milli\metre$.}
\label{fig:estimation_scaling_factor_6}
\end{figure}

Averaging the 2000 samples before localizing Figure \ref{fig:estimation_scaling_factor_6}.

\clearpage
\section{RESULTS}

Loading…
Cancel
Save