AnalyseMorphologique/utils/data_processing/data_processing.py
Djalim Simaila 8175561250 🐛 fix(.gitignore): add test.py to the list of ignored files
 feat(data_processing.py): remove deprecated get_discrete_vertices2 method and rename get_discrete_vertices3 to get_discrete_vertices. Simplify get_discrete_vertices method by removing the selection of the discretisation method from the settings and always using the Z0-Zi < DeltaZ method. This improves code readability and maintainability.
 feat(input.py): remove deprecated result_file_path and bruteforce_discretization_result attributes from ScannedObject class. Add old_delta, old_discrete, and old_discrete_type attributes to cache the results of the get_discrete_vertices method. This improves performance by avoiding unnecessary recomputations of the discretized vertices.
 feat(MainWindow.py): add support for selecting a layer to display discrete graphs for. Add two new graph types: "Coupe de la couche" and "Difference entre le rayon de chaque points

🔧 fix(ui): change tab index to display the correct tab on startup
 feat(ui): add label and combobox to select layer to display
🔧 fix(worker): add discretisation_value parameter to PreProcessWorker constructor
 feat(math): add get_true_teta_from_x_y, get_difference_from_mean_value, and get_distance_between_two_vertices functions
The UI fix changes the tab index to display the correct tab on startup. The new label and combobox allow the user to select the layer to display. The worker fix adds a discretisation_value parameter to the PreProcessWorker constructor. The new math functions are get_true_teta_from_x_y, get_difference_from_mean_value, and get_distance_between_two_vertices. These functions are useful for calculating teta, differences from mean values, and distances between vertices.
2023-05-03 17:26:11 +02:00

98 lines
4.1 KiB
Python

"""
Created on Mon Apr 24 2023
@name: data_processing.py
@desc: A module to process the data
@auth: Djalim Simaila
@e-mail: djalim.simaila@inrae.fr
"""
from utils.math import data_extraction
from utils.files.input import ScannedObject
from utils.settings.SettingManager import SettingManager
def progressbar_placeholder(percent:int):
"""
This function is a placeholder for a progressbar function
"""
def get_raw_data(obj:ScannedObject, ndigits:int,delta_z:float=1,update_progress_bar = progressbar_placeholder)->dict:
"""
Calculates data from the given object
:param obj: Object to analyse
:param ndigits: Number of digits to keep after the comma
:param delta_z: Delta z to use for the discretisation
:param update_progress_bar: Function to update the progress bar
:return: dict(str:list) with the following keys:
- X (en mm) : list of x values
- Y (en mm) : list of y values
- Z (en mm) : list of z values
- teta (en rad) : list of teta values
- rayon (en mm) : list of radius values
- Xi-Xmoy : list of Xi-Xmoy values
- Yi-Ymoy : list of Yi-Ymoy values
"""
# Create the data dict
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] = []
# Get the discrete vertices
discrete_vertices = obj.get_discrete_vertices(delta_z)
progress = 0
# Calculate the data for each discrete vertex
for discrete_values in discrete_vertices:
mean_x ,mean_y, mean_z = data_extraction.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(data_extraction.get_teta_from_x_y(x,y,mean_x,mean_y), ndigits))
data["rayon (en mm)"].append(round(data_extraction.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))
update_progress_bar(int(progress/len(discrete_vertices)*100))
progress += 1
return data
def get_discrete_data(obj:ScannedObject, ndigits:int, delta_z:float=1, update_progress_bar= progressbar_placeholder)->dict:
"""
Calculates data from the given object
:param obj: Object to analyse
:param ndigits: Number of digits to keep after the comma
:param delta_z: Delta z to use for the discretisation
:param update_progress_bar: Function to update the progress bar
:return: dict(str:list) with the following keys:
- X moy (en mm) : list of x mean values
- Y moy (en mm) : list of y mean values
- Z moy (en mm) : list of z mean values
- Rayon moyen (en mm) : list of mean radius values
- Rayon ecart type (en mm) : list of radius standard deviation values
"""
# Create the data dict
colones = ["X moy (en mm)", "Y moy (en mm)", "Z moy (en mm)","Discretisation(en mm)","Rayon moyen (en mm)","Rayon ecart type (en mm)"]
data = {}
for colone in colones:
data[colone] = []
# Get the discrete vertices
discrete_vertices = obj.get_discrete_vertices(delta_z)
progress = 0
for discrete_values in discrete_vertices:
x,y,z = data_extraction.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))
first = discrete_values[0]
last = discrete_values[-1]
data["Discretisation(en mm)"].append(round(last[2]-first[2],ndigits))
data["Rayon moyen (en mm)"].append(round(data_extraction.get_mean_radius(discrete_values), ndigits))
data["Rayon ecart type (en mm)"].append(round(data_extraction.get_radius_std(discrete_values), ndigits))
update_progress_bar(int(progress/len(discrete_vertices)*100))
progress += 1
return data