added missing calculations and added data formating
This commit is contained in:
parent
ecccb0f8cb
commit
2968922f28
71
integration_tests/data_test.py
Normal file
71
integration_tests/data_test.py
Normal file
@ -0,0 +1,71 @@
|
||||
from utils.files import output
|
||||
|
||||
def check_discrete_data(expected_file, actual_file, ndigits=7,eps=0.00001) :
|
||||
output_file = "check_discrete_data_full.txt"
|
||||
minimal_output_file = "check_discrete_data_minimal.txt"
|
||||
minimal_output_data = ""
|
||||
output_data = ""
|
||||
expected = []
|
||||
with open(expected_file, "r") as f:
|
||||
expected = f.readlines()[1:]
|
||||
expected = [line.replace(',','.').split('\t') for line in expected]
|
||||
expected = [[float(x) for x in line] for line in expected]
|
||||
actual = []
|
||||
with open(actual_file, "r") as f:
|
||||
actual = f.readlines()[1:]
|
||||
actual = [line.split('\t') for line in actual]
|
||||
actual = [[float(x) for x in line if x != '\n'] for line in actual]
|
||||
for i in range(min(len(expected), len(actual))):
|
||||
x_diff = round(abs(expected[i][0] - actual[i][0]),ndigits)
|
||||
y_diff = round(abs(expected[i][1] - actual[i][1]),ndigits)
|
||||
z_diff = round(abs(expected[i][2] - actual[i][2]),ndigits)
|
||||
r_diff = round(abs(expected[i][3] - actual[i][3]),ndigits)
|
||||
std_diff = round(abs(expected[i][4] - actual[i][4]),ndigits)
|
||||
line = f"{str(i).rjust(4)}:\t X: {str(x_diff).rjust(8)}\t Y: {str(y_diff).rjust(8)}\t Z: {str(z_diff).rjust(8)}\t R: {str(r_diff).rjust(8)}\t STD: {str(std_diff).rjust(8)}"
|
||||
output_data += line + "\n"
|
||||
if x_diff > eps or y_diff > eps or z_diff > eps or r_diff > eps or std_diff > eps:
|
||||
minimal_output_data += line + "\n"
|
||||
output.save_output_file(output_file, output_data)
|
||||
output.save_output_file(minimal_output_file, minimal_output_data)
|
||||
|
||||
def check_raw_data(expected_file, actual_file, ndigits=7,eps=0.00001) :
|
||||
output_file = "check_raw_data_full.txt"
|
||||
minimal_output_file = "check_raw_data_minimal.txt"
|
||||
minimal_output_data = ""
|
||||
output_data = ""
|
||||
expected = []
|
||||
with open(expected_file, "r") as f:
|
||||
expected = f.readlines()[1:]
|
||||
expected = [line.replace(',','.').split('\t') for line in expected]
|
||||
expected = [[float(x) for x in line] for line in expected]
|
||||
actual = []
|
||||
with open(actual_file, "r") as f:
|
||||
actual = f.readlines()[1:]
|
||||
actual = [line.split('\t') for line in actual]
|
||||
actual = [[float(x) for x in line if x != '\n'] for line in actual]
|
||||
for i in range(min(len(expected), len(actual))):
|
||||
x_diff = round(abs(expected[i][0] - actual[i][0]),ndigits)
|
||||
y_diff = round(abs(expected[i][1] - actual[i][1]),ndigits)
|
||||
z_diff = round(abs(expected[i][2] - actual[i][2]),ndigits)
|
||||
t_diff = round(abs(expected[i][3] - actual[i][3]),ndigits)
|
||||
r_diff = round(abs(expected[i][4] - actual[i][4]),ndigits)
|
||||
xmoy_diff = round(abs(expected[i][5] - actual[i][5]),ndigits)
|
||||
ymoy_diff = round(abs(expected[i][6] - actual[i][6]),ndigits)
|
||||
line = f"{str(i).rjust(4)}:\t X: {str(x_diff).rjust(8)}\t Y: {str(y_diff).rjust(8)}\t Z: {str(z_diff).rjust(8)}\t T: {str(t_diff).rjust(8)}\t R: {str(r_diff).rjust(8)}\t Xmoy: {str(xmoy_diff).rjust(8)}\t Ymoy: {str(ymoy_diff).rjust(8)}"
|
||||
output_data += line + "\n"
|
||||
if x_diff > eps:
|
||||
minimal_output_data += f"{i} : {x_diff}\n"
|
||||
if y_diff > eps:
|
||||
minimal_output_data += f"{i} : {y_diff}\n"
|
||||
if z_diff > eps:
|
||||
minimal_output_data += f"{i} : {z_diff}\n"
|
||||
if t_diff > eps:
|
||||
minimal_output_data += f"{i} : {t_diff}\n"
|
||||
if r_diff > eps:
|
||||
minimal_output_data += f"{i} : {r_diff}\n"
|
||||
if xmoy_diff > eps:
|
||||
minimal_output_data += f"{i} : {xmoy_diff}\n"
|
||||
if ymoy_diff > eps:
|
||||
minimal_output_data += f"{i} : {ymoy_diff}\n"
|
||||
output.save_output_file(output_file, output_data)
|
||||
output.save_output_file(minimal_output_file, minimal_output_data)
|
44
main.py
44
main.py
@ -1,10 +1,50 @@
|
||||
from utils.math import utils
|
||||
from utils.files import file_data
|
||||
from utils.files import output
|
||||
from utils.files import parsers
|
||||
from integration_tests import data_test
|
||||
|
||||
def get_raw_data(obj, ndigits):
|
||||
colones = ["X (en mm)", "Y (en mm)", "Z (en mm)", "teta (en rad)", "rayon (en mm)","Xi-Xmoy","Yi-Ymoy"]
|
||||
data = {}
|
||||
for colone in colones:
|
||||
data[colone] = []
|
||||
for discrete_values in obj.get_discrete_vertices(1):
|
||||
mean_x ,mean_y, mean_z = utils.get_x_y_z_mean(discrete_values)
|
||||
for x,y,z in discrete_values:
|
||||
data["X (en mm)"].append(round(x, ndigits))
|
||||
data["Y (en mm)"].append(round(y, ndigits))
|
||||
data["Z (en mm)"].append(round(z, ndigits))
|
||||
data["teta (en rad)"].append(round(utils.get_teta_from_x_y(x,y,mean_x,mean_y), ndigits))
|
||||
data["rayon (en mm)"].append(round(utils.get_radius_from_x_y(x,y,mean_x,mean_y), ndigits))
|
||||
data["Xi-Xmoy"].append(round(x-mean_x, ndigits))
|
||||
data["Yi-Ymoy"].append(round(y-mean_y, ndigits))
|
||||
return data
|
||||
|
||||
def get_discrete_data(obj, ndigits):
|
||||
colones = ["X moy (en mm)", "Y moy (en mm)", "Z moy (en mm)","Rayon moyen (en mm)","Rayon ecart type (en mm)"]
|
||||
data = {}
|
||||
for colone in colones:
|
||||
data[colone] = []
|
||||
for discrete_values in obj.get_discrete_vertices(1):
|
||||
x,y,z = utils.get_x_y_z_mean(discrete_values)
|
||||
data["X moy (en mm)"].append(round(x, ndigits))
|
||||
data["Y moy (en mm)"].append(round(y, ndigits))
|
||||
data["Z moy (en mm)"].append(round(z, ndigits))
|
||||
data["Rayon moyen (en mm)"].append(round(utils.get_mean_radius(discrete_values), ndigits))
|
||||
data["Rayon ecart type (en mm)"].append(round(utils.get_radius_std(discrete_values), ndigits))
|
||||
return data
|
||||
|
||||
|
||||
def main():
|
||||
pass
|
||||
obj = parsers.parse_obj_file("datasets/Barette/3 - BARETTE v1.obj",normalised=True)
|
||||
data = get_raw_data(obj, 6)
|
||||
output.save_output_file('analyse_brute.txt', output.format_data(data, '\t', ["X (en mm)", "Y (en mm)", "Z (en mm)", "teta (en rad)", "rayon (en mm)","Xi-Xmoy","Yi-Ymoy"] ))
|
||||
data_test.check_raw_data("datasets/Barette/BARETTE_Delta 1,0_analyse brute.txt", "analyse_brute.txt",eps=0.001)
|
||||
|
||||
data = get_discrete_data(obj, 6)
|
||||
output.save_output_file('analyse_rayon.txt', output.format_data(data, '\t', ["X moy (en mm)", "Y moy (en mm)", "Z moy (en mm)","Rayon moyen (en mm)","Rayon ecart type (en mm)"] ))
|
||||
data_test.check_discrete_data("datasets/Barette/BARETTE_Delta 1,0_analyse rayon.txt", "analyse_rayon.txt",eps=0.001)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
120867
output.txt
120867
output.txt
File diff suppressed because it is too large
Load Diff
@ -61,6 +61,8 @@ class Object:
|
||||
splitted_data.append([])
|
||||
current_interval += step
|
||||
splitted_data[-1].append(line)
|
||||
if splitted_data[0] == []:
|
||||
splitted_data = splitted_data[1:]
|
||||
return splitted_data
|
||||
|
||||
def get_faces(self)->list:
|
||||
|
@ -2,6 +2,27 @@
|
||||
This module is used to manage the output files of the program.
|
||||
"""
|
||||
|
||||
def format_data(data:dict, separator:str, selected_columns:list = None) -> str:
|
||||
"""
|
||||
Format the data to be saved in the output file.
|
||||
|
||||
:param data: Data to be formatted
|
||||
:param selected_columns: Columns to be saved
|
||||
:param separator: Separator of the columns
|
||||
:return: Formatted data
|
||||
"""
|
||||
output = ''
|
||||
if selected_columns is None:
|
||||
selected_columns = list(data.keys())
|
||||
for column_name in selected_columns:
|
||||
output += column_name + separator
|
||||
output += '\n'
|
||||
for i in range(len(data[selected_columns[0]])):
|
||||
for column in selected_columns:
|
||||
output += str(data[column][i]).ljust(len(column)) + separator
|
||||
output += '\n'
|
||||
return output
|
||||
|
||||
def save_output_file(output_file:str, content:str):
|
||||
"""
|
||||
Save the output file.
|
||||
|
@ -3,7 +3,7 @@ This module contains functions to parse files.
|
||||
"""
|
||||
from utils.files.file_data import Object
|
||||
|
||||
def parse_obj_files(file_path:str,ratio:float = 1,normalised:bool = False)->Object:
|
||||
def parse_obj_file(file_path:str,ratio:float = 1,normalised:bool = False)->Object:
|
||||
"""
|
||||
Parse an OBJ file and return a dict with the vertices and faces
|
||||
|
||||
@ -41,7 +41,7 @@ def parse_obj_files(file_path:str,ratio:float = 1,normalised:bool = False)->Obje
|
||||
|
||||
return Object(list(zip(x,y,z)), triangles)
|
||||
|
||||
def parse_xyz_files(file_path: str, delimiter: str = ' ') -> dict:
|
||||
def parse_xyz_file(file_path: str, delimiter: str = ' ') -> dict:
|
||||
"""
|
||||
Parses an xyz file and returns a dict containing the coordinates.
|
||||
|
||||
|
@ -9,8 +9,16 @@ def get_mean(values:list):
|
||||
"""
|
||||
return np.mean(values)
|
||||
|
||||
def get_standard_deviation(values:list):
|
||||
"""
|
||||
Get the standard deviation of the values.
|
||||
|
||||
def get_x_y_mean(discrete_values:list):
|
||||
:param values: values
|
||||
:return: standard deviation of the values
|
||||
"""
|
||||
return np.std(values)
|
||||
|
||||
def get_x_y_z_mean(discrete_values:list):
|
||||
"""
|
||||
Get the mean of the x and y coordinates in the discrete range.
|
||||
|
||||
@ -35,6 +43,44 @@ def get_radius_from_x_y(xi:float, yi:float, x_mean:float, y_mean:float):
|
||||
"""
|
||||
return np.sqrt((xi - x_mean) ** 2 + (yi - y_mean) ** 2)
|
||||
|
||||
def get_mean_radius(discrete_values:list):
|
||||
"""
|
||||
Get the mean of the radius in the discrete range.
|
||||
|
||||
:param discrete_values: discrete values
|
||||
:return: mean of the radius in the discrete range
|
||||
"""
|
||||
x_mean, y_mean, z_mean = get_x_y_z_mean(discrete_values)
|
||||
radius = []
|
||||
for x,y,z in discrete_values:
|
||||
radius.append(get_radius_from_x_y(x,y,x_mean,y_mean))
|
||||
return get_mean(radius)
|
||||
|
||||
def get_radius_std(discrete_values:list):
|
||||
"""
|
||||
Get the standard deviation of the radius in the discrete range.
|
||||
|
||||
:param discrete_values: discrete values
|
||||
:return: standard deviation of the radius in the discrete range
|
||||
"""
|
||||
x_mean, y_mean, z_mean = get_x_y_z_mean(discrete_values)
|
||||
radius = []
|
||||
for x,y,z in discrete_values:
|
||||
radius.append(get_radius_from_x_y(x,y,x_mean,y_mean))
|
||||
return get_standard_deviation(radius)
|
||||
|
||||
def get_mean_teta(discrete_values:list):
|
||||
"""
|
||||
Get the mean of the teta in the discrete range.
|
||||
|
||||
:param discrete_values: discrete values
|
||||
:return: mean of the teta in the discrete range
|
||||
"""
|
||||
x_mean, y_mean, z_mean = get_x_y_z_mean(discrete_values)
|
||||
teta = []
|
||||
for x,y,z in discrete_values:
|
||||
teta.append(get_teta_from_x_y(x,y,x_mean,y_mean))
|
||||
return get_mean(teta)
|
||||
|
||||
def get_teta_from_x_y(xi:float, yi:float, x_mean:float, y_mean:float):
|
||||
"""
|
||||
@ -46,4 +92,4 @@ def get_teta_from_x_y(xi:float, yi:float, x_mean:float, y_mean:float):
|
||||
:param y_mean: mean of y coordinates in the discrete range
|
||||
:return: teta for this point
|
||||
"""
|
||||
return np.arctan2((xi - x_mean)/(yi - y_mean))
|
||||
return np.arctan2((xi - x_mean),(yi - y_mean))
|
Loading…
Reference in New Issue
Block a user