✨ feat(MainWindow.py): add functionality to export advanced data to a text file 🚀 feat(MainWindow.py): add button to export advanced data to a text file 🚀 feat(MainWindow.ui): update labels for Volume and Surface to include units The keys in the dict returned by the get_advanced_data function were updated to be more descriptive. The export_advanced_data function was added to the MainWindow class to allow the user to export the advanced data to a text file. A button was added to the GUI to allow the user to export the advanced data. The labels for Volume and Surface were updated to include the units of measurement. 🎨 style(UI_MainWindow.py): rename tab_5 to parameters and tab_6 to values for better semantics The names of the tabs have been changed to better reflect their contents. The tab previously named tab_5 is now named parameters, and the tab previously named tab_6 is now named values. This improves the readability and maintainability of the code. 🎨 style(UI_MainWindow.py): rename tab_6 to values and tab to graph_pane_1, tab_2 to graph_pane_2, tab_3 to graph_pane_3, and tab_4 to graph_pane_4 for better semantics This commit only renames the tabs in the UI_MainWindow.py file to improve the semantics of the code. The tab_6 is renamed to values, and tab, tab_2, tab_3, and tab_4 are renamed to graph_pane_1, graph_pane_2, graph_pane_3, and graph_pane_4, respectively. 🔨 refactor(UI_MainWindow.py): update labels for volume and surface to include units The labels for volume and surface have been updated to include the units of measurement in millimeters. The tab names for the settings and graph panes have also been updated to improve readability and consistency with the naming conventions. 🔨 refactor(AdvancedDataWorker.py): update keys in the dict returned by the function to be more explicit 🔨 refactor(position_manipulation.py): remove unnecessary computation of the center of gravity in the verticalise function The keys in the dict returned by the AdvancedDataWorker function have been updated to be more explicit. The keys 'Volume' and 'Surface' have been updated to 'Volume en mm3' and 'Surface en mm2' respectively to indicate the units of measurement. In the position_manipulation.py file, the computation of the center of gravity in the verticalise function was unnecessary and has been removed to improve performance.
170 lines
6.5 KiB
Python
170 lines
6.5 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 as de
|
|
import numpy as np
|
|
from utils.files.input import ScannedObject
|
|
|
|
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
|
|
- theta (en rad) : list of theta 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)",
|
|
"theta (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 = de.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["theta (en rad)"].append(round(de.get_theta_from_x_y(x,y,mean_x,mean_y), ndigits))
|
|
data["rayon (en mm)"].append(round(de.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 = de.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(de.get_mean_radius(discrete_values), ndigits))
|
|
data["Rayon ecart type (en mm)"].append(round(de.get_radius_std(discrete_values), ndigits))
|
|
update_progress_bar(int(progress/len(discrete_vertices)*100))
|
|
progress += 1
|
|
return data
|
|
|
|
def get_advanced_data(discrete_data:dict, update_progress_bar= progressbar_placeholder)->dict:
|
|
"""
|
|
Calculates morphological indicators from the given discrete data
|
|
|
|
:param discrete_data: 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
|
|
:param update_progress_bar: Function to update the progress bar
|
|
:return: dict with the following keys:
|
|
- Tortuosite
|
|
- Volume en mm3
|
|
- Surface en mm2
|
|
- Moyenne des rayons moyens
|
|
- Ecart-type des rayons moyens
|
|
- Sigma r tot
|
|
- MI_l
|
|
- MI_p
|
|
"""
|
|
|
|
# Tortusity
|
|
l = 0
|
|
L = 0
|
|
vertices = list(zip(discrete_data["X moy (en mm)"],
|
|
discrete_data["Y moy (en mm)"],
|
|
discrete_data["Z moy (en mm)"]))
|
|
|
|
for index in range(len(vertices)-1):
|
|
l += de.get_distance_between_two_vertices(vertices[index], vertices[index+1])
|
|
L = de.get_distance_between_two_vertices(vertices[0], vertices[-1])
|
|
T = l/L
|
|
update_progress_bar(10)
|
|
|
|
# Volume and surface
|
|
H = discrete_data["Z moy (en mm)"][-1] - discrete_data["Z moy (en mm)"][0]
|
|
R = de.get_mean([np.power(r,2) for r in discrete_data["Rayon moyen (en mm)"]])
|
|
V = np.pi * R * H
|
|
S = 2 * np.pi * R * H
|
|
update_progress_bar(30)
|
|
|
|
# Morphological indicators
|
|
R_mean = de.get_mean(discrete_data["Rayon moyen (en mm)"])
|
|
R_mean_std = de.get_standard_deviation(discrete_data["Rayon moyen (en mm)"])
|
|
mean_sigma_r_squared = de.get_mean([np.power(r,2) for r in discrete_data["Rayon ecart type (en mm)"]])
|
|
sigma_r_tot = np.sqrt(np.power(R_mean_std,2) + mean_sigma_r_squared )
|
|
MI_l = R_mean_std/R_mean
|
|
MI_p = np.sqrt(mean_sigma_r_squared)/R_mean
|
|
update_progress_bar(100)
|
|
return {
|
|
"Tortuosité":T,
|
|
"Volume en mm3":V,
|
|
"Surface en mm2":S,
|
|
"Moyenne des rayons moyens":R_mean,
|
|
"Ecart-type des rayons moyens":R_mean_std,
|
|
"Sigma r tot":sigma_r_tot,
|
|
"MI_l":MI_l,
|
|
"MI_p":MI_p
|
|
}
|