Commit 8fce0bc2 authored by Jadracka's avatar Jadracka
Browse files

Housekeeping

parent 38f86d2d
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 7 08:02:05 2021
@author: jbarker
"""
#import scipy as sp
import re
import numpy as np
#import sys
#import string
#import math as m
import config as cg
import functions as fc
#from operator import itemgetter
#from collections import namedtuple
Coords_file = open(cg.Coords_file_name,'r')
Nominal_coords = {}
for line in Coords_file.readlines():
"""Reads in and parses coordinates file. Ignores point notes at the end.
It can handle multiple occurences of delimeters,
but not a combination of them."""
words = re.split(';+|,+|\t+| +',line.strip())
Nominal_coords[words[0]] = (float(words[1]),
float(words[2]),
float(words[3]))
del line
Coords_file.close()
LoS_Meas_file = open(cg.Measurements_file_name_2,'r')
LoS_measurements_1 = {}
for row in LoS_Meas_file.readlines():
"""
- Reads in and parses Meas_file.
- The format is string Line name 'space'
string Point name 'space' float Distance [mm] 'space'
float Hz angle [gon] 'space' float Z angle [gon].
- Ignores point notes at the end.
- It can handle multiple occurences of delimeters but not a
combination of them.
- LoS_measurements_1 - a Dictionary of lines which contains a
Dictionary of points, where Point
name is a key and measured values
are triplet tuple"""
words = re.split(';+|,+|\t+| +',row.strip())
if words[0] not in LoS_measurements_1.keys():
LoS_measurements_1[words[0]] = {}
LoS_measurements_1[words[0]][words[1]] = \
(float(words[2]), float(words[3]), float(words[4]))
else:
LoS_measurements_1[words[0]][words[1]] = \
(float(words[2]), float(words[3]), float(words[4]))
del words, row
LoS_Meas_file.close()
# =============================================================================
# Initial checks for LoS measurements.
# If you want to print, change: Print_typos to True
# =============================================================================
# Checking point names for typos and misspells and creating the list of
# measured points in lines sorted based on the config file definition:
sorted_measured_points_in_lines = {}
all_measured_points = []
measured_lines_all_good = True
measured_points_all_good = True
#nominal_lines_all_measured = True #not checking at the moment
nominal_points_all_measured = True
all_points_in_lines_measured = True
for line in LoS_measurements_1:
if (cg.Print_typos) and (line not in cg.Lines_of_sight):
# printing which lines are in measurements input but are not in the
# default naming either due to typo or just simply missing in the nominal
# LoS decription
print("Line %s was measured, but not expected." % (line))
measured_lines_all_good = False
else:
line_points_sorted = []
for point in cg.Lines_of_sight[line]:
if point in LoS_measurements_1[line].keys():
line_points_sorted.append(point)
sorted_measured_points_in_lines[line] = tuple(line_points_sorted)
if line_points_sorted != list(cg.Lines_of_sight[line]):
all_points_in_lines_measured = False
if cg.Print_typos:
print("Not all points were measured in %s line"% (line))
del line_points_sorted
for point in LoS_measurements_1[line]:
if (cg.Print_typos) and (point not in Nominal_coords):
print("Measured point with name %s in %s is not in the Nominal" \
" Coordinate file." % (point, line))
measured_points_all_good = False
if point not in cg.Lines_of_sight[line]:
measured_points_all_good = False
if cg.Print_typos:
print("Point %s does not nominally belong to %s line"
% (point, line))
if point not in all_measured_points:
all_measured_points.append(point)
del line, point
for point in Nominal_coords.keys():
if (cg.Print_typos) and (point not in all_measured_points):
print("Point %s was not measured in any line." % (point))
nominal_points_all_measured = False
del point
if (cg.Print_typos) and (measured_lines_all_good):
print("All measured lines were expected, no typos found.")
if (cg.Print_typos) and (measured_points_all_good):
print("All measured points are correct, in correct lines, no typos found.")
if (cg.Print_typos) and (nominal_points_all_measured):
print("All nominal points were measured at least once.")
if (cg.Print_typos) and not (all_points_in_lines_measured):
print("Not all points in lines were measured. Continuing in analysis.")
del all_measured_points, nominal_points_all_measured,\
all_points_in_lines_measured
measured_distances_in_lines = {}
if cg.Using_nominal_compare:
nominal_distances_in_line = {}
differences_in_distances = {}
StDev_distances_in_lines = {}
if measured_lines_all_good and measured_points_all_good:
del measured_lines_all_good, measured_points_all_good
# Calculating distance deltas
for line in LoS_measurements_1:
deltas = ()
if cg.Using_nominal_compare:
deltas_nominal = ()
for i in range (1,len(sorted_measured_points_in_lines[line])):
delta = (LoS_measurements_1[line][
sorted_measured_points_in_lines[line][i]][0]\
- LoS_measurements_1[line][
sorted_measured_points_in_lines[line][i-1]][0],)
deltas = deltas + delta
if cg.Using_nominal_compare:
d = fc.slope_distance(
Nominal_coords[
sorted_measured_points_in_lines[line][i-1]],
Nominal_coords[
sorted_measured_points_in_lines[line][i]])
deltas_nominal = deltas_nominal + (d,)
measured_distances_in_lines[line] = deltas
if cg.Using_nominal_compare:
nominal_distances_in_line[line] = deltas_nominal
del deltas_nominal
del line, i, delta, deltas, d
if cg.Using_nominal_compare:
for line in LoS_measurements_1:
differences_in_distances[line] = np.asarray(
nominal_distances_in_line[line])\
- np.asarray(
measured_distances_in_lines[line])
StDev_distances_in_lines[line] = np.std(
differences_in_distances[line])
if StDev_distances_in_lines[line] == 0:
StDev_distances_in_lines[line] = None
differences_in_distances[line] = tuple(
differences_in_distances[line])
del line
else:
print("Analysis cannot be performed as there are typos and errors in "
"input data. Please correct before running the script again. "
"To help troubleshoot, change Print_typos in config.py to True.")
print(differences_in_distances, StDev_distances_in_lines)
print('End of the script')
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 13 11:12:15 2021
@author: jbarker
"""
#=============================================================================
# Overflow code
#=============================================================================
import config as cg
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import NewCode as nc
if cg.Print_FIDs:
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.axis('equal')
xdata = []
ydata = []
zdata = []
PointID = []
for key in nc.Nominal_coords:
PointID.append(key)
xdata.append(nc.Nominal_coords[key][0])
ydata.append(nc.Nominal_coords[key][1])
zdata.append(nc.Nominal_coords[key][2])
# ax.scatter3D(xdata, ydata, zdata);
for i in range(len(PointID)): #plot each point + it's index as text above
ax.scatter(xdata[i],ydata[i],zdata[i],color='b')
ax.text(xdata[i],ydata[i],zdata[i], '%s' % (str(PointID[i])), size=9, zorder=1, color='k')
plt.show()
\ No newline at end of file
......@@ -37,7 +37,7 @@ Instrument_1 PQK36_3 2152.053 31.6737 89.8183
Instrument_1 PQK36_2 2063.496 34.8810 93.1692
Instrument_1 PQK36_1 2072.912 34.8412 109.2065
Instrument_1 PQK36_7 1770.548 27.2686 110.7741
Instrument_1 Girder TP 1738.710 23.3771 118.5030
Instrument_1 Girder_TP 1738.710 23.3771 118.5030
Instrument_1 Girder_13 1449.653 13.8719 113.3475
Instrument_1 Girder_14 1983.839 0.9051 109.6234
Instrument_1 PQL6_1 1226.675 -6.2772 115.5865
......
# -*- coding: utf-8 -*-
"""
Created on Wed May 5 13:07:50 2021
@author: jbarker
"""
import functions as fc
class Point3DCart(dict):
def __init__(self, PointID, X, Y, Z):
self.PointID = PointID
self.X = X
self.Y = Y
self.Z = Z
def display(self):
print(f'PointID = {self.PointID}, X = {self.X}, '
f'Y = {self.Y}, Z = {self.Z}')
def trans2Pol(self):
return(self.PointID,fc.cart2polal3Dgon(self.X,self.Y,self.Z))
Point = Point3DCart('PQL6_12',138.13,12393.31,13.13)
class Point3DPol(dict):
def __init__(self, PointID, Sd, Hz, Z):
self.PointID = PointID
self.Sd = Sd
self.Hz = Hz
self.Z = Z
def display(self):
print(f'PointID = {self.PointID}, Sd = {self.Sd}, '
f'Hz = {self.Hz}, Z = {self.Z}')
def trans2Cart(self):
return(self.PointID,fc.polar2cart3Dgon(self.Sd,self.Hz,self.Z))
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 11 10:50:35 2021
@author: jbarker
"""
#import scipy as sp
import numpy as np
#import matplotlib as mp
#import sys
#import string
#import math as m
import re
import config as cg
import functions as fc
from operator import itemgetter
#from collections import namedtuple
Coords_file = open(cg.Coords_file_name,'r')
Nominal_coords = {}
for line in Coords_file.readlines():
"""Reads in and parses coordinates file. Ignores point notes at the end.
It can handle multiple occurences of delimeters,
but not a combination of them."""
words = re.split(';+|,+|\t+| +',line.strip())
Nominal_coords[words[0]] = (float(words[1]), float(words[2]), float(words[3]))
del line
Coords_file.close()
if cg.Using_nominal_compare:
#Calculates nominal distances in ideal lines as seen in config file
nominal_distances_in_lines = {}
for line, Tupple_of_points in cg.Lines_of_sight.items():
First_point_Coords = Nominal_coords[Tupple_of_points[0]]
distances_list = []
for point in Tupple_of_points[1:]:
distance = fc.slope_distance(First_point_Coords,Nominal_coords[point])
distances_list.append(distance)
nominal_distances_in_lines[line] = distances_list
Meas_file = open(cg.Measurements_file_name,'r')
Meas = {}
Measured_lines = []
Points_on_measured_lines = {}
measured_distances = {}
full_measurement_matrix = {}
for row in Meas_file.readlines():
"""
- Reads in and parses Meas_file.
- The format is string Group name (aka Line of sight) 'space'
string Point name 'space' float Distance [mm] 'space'
float Hz angle [gon] 'space' float V angle [gon].
- Ignores point notes at the end.
- It can handle multiple occurences of delimeters but not a combination of
them.
- It creates
- Meas - Dictionary of list of Tuples where the name of the Line of
sight is the key and tuples are measured values to the points
- full measurement matrix - a Dictionary of lines which contains a
Dictionary of points, where Point name is
a key and measured values are triplet tuple
- measured_distances - Dictionary of measured disances"""
words = re.split(';+|,+|\t+| +',row.strip())
if str(words[0]) not in Measured_lines:
Measured_lines.append(words[0])
if words[0] not in Meas:
Meas[words[0]] = [(float(words[2]), float(words[3]), float(words[4]))]
measured_distances[words[0]] = (words[2],)
full_measurement_matrix[words[0]] = {}
full_measurement_matrix[words[0]][words[1]] = \
(float(words[2]), float(words[3]), float(words[4]))
else:
Meas[words[0]]= Meas[words[0]]+[(float(words[2]), float(words[3]), \
float(words[4]))]
measured_distances[words[0]] = measured_distances[words[0]] + \
(words[2],)
full_measurement_matrix[words[0]][words[1]] = \
(float(words[2]), float(words[3]), float(words[4]))
del words, row
# =============================================================================
# Finding the minimal distance measured in each line and storing it, together
# in dictionary of lists. Dictionary keys = line names, values = list of pairs:
# Point_name, measured distance (first of the triplet tuple of measurements)
# =============================================================================
minimal_distances_in_line = {}
for line in full_measurement_matrix:
"""itemgetter(which position I want to consider)[returns what is needed
- without [] whole tuple]"""
minimal_distances_in_line[line] = []
distance = min(Meas[line],key=itemgetter(0))[0]
"""some pretty cool mumbo jumbo! Using the .values() and .keys()
for a nested dictionary [line], searching for key of the nested
dictionary (point name) using .index(), where the index value is the
minimum distance found from the value=tuple of measured triplet of the
key=point"""
minimal_distance_point_name = \
(list(full_measurement_matrix[line].keys()) \
[list(full_measurement_matrix[line].values()).index(min(Meas[line],\
key=itemgetter(0)))])
minimal_distances_in_line[line] = [minimal_distance_point_name, distance]
del minimal_distance_point_name, distance
for dictionary in full_measurement_matrix:
# Points on measured lines dictionary of key = line name and list = points
Points_on_measured_lines[dictionary] = \
list(full_measurement_matrix[dictionary].keys())
del dictionary
# =============================================================================
# Calculating the nominal and real differential distances for each point
# of the line except the one closest to the tracker (=beginning of the line).
# Storing those in dictionary of lists. Key is the line's name.
# =============================================================================
nominal_distances_measured = {}
for line in measured_distances:
distances_list = []
for point in Points_on_measured_lines[line]:
if point != minimal_distances_in_line[line][0]:
delta_distance = fc.slope_distance(Nominal_coords \
[minimal_distances_in_line[line][0]],Nominal_coords[point])
distances_list.append(delta_distance)
nominal_distances_measured[line] = distances_list
del distances_list, delta_distance, line, point
real_distances_measured = {}
for line in measured_distances:
distances_list = []
for distance in measured_distances[line]:
if float(distance) != float(minimal_distances_in_line[line][1]):
delta_distance = float(distance) - \
float(minimal_distances_in_line[line][1])
distances_list.append(delta_distance)
real_distances_measured[line] = distances_list
del distances_list, delta_distance, line, distance
differences_real_nominal_distances = {}
for line in nominal_distances_measured:
diff = np.subtract((nominal_distances_measured[line]), \
(real_distances_measured[line]))
differences_real_nominal_distances[line] = list(diff)
if cg.Line_differences_checking:
if diff[0] > 1:
print('discrapancy in:',line,'\n')
else:
print('It looks ok')
del line, diff
......@@ -45,7 +45,7 @@ Group aka Line name 'space' Point name 'space' Sd [mm] 'space' Hz [gon] 'space'
Epochs_dictionary = {'LoS':{},'Pol':{}}
Epochs_dictionary['LoS'][0] = "Testing_measurements_Epoch0.txt"
Epochs_dictionary['LoS'][1] = "Testing_measurements_Epoch1.txt"
Epochs_dictionary['Pol'][0] = "Polar_measurements_1.txt"
Epochs_dictionary['Pol'][0] = "Polar_measurements_0.txt"
Epochs_dictionary['Pol'][1] = "Polar_measurements_1.txt"
"""Which Epochs gonna be used and adding the data into the code"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment