From 19bfea7575800eb6c4d46199b54bade002ab84df Mon Sep 17 00:00:00 2001 From: antcsny <131650489+antcsny@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:22:31 +0200 Subject: [PATCH] File displacement and fix for code imports from tools in examples --- {tools => examples}/movement_treatment.py | 8 +++++--- examples/variable_by.py | 3 +++ tools/movement_extractor.py | 9 +++------ 3 files changed, 11 insertions(+), 9 deletions(-) rename {tools => examples}/movement_treatment.py (96%) diff --git a/tools/movement_treatment.py b/examples/movement_treatment.py similarity index 96% rename from tools/movement_treatment.py rename to examples/movement_treatment.py index aed748f..f80e18e 100644 --- a/tools/movement_treatment.py +++ b/examples/movement_treatment.py @@ -45,6 +45,7 @@ def explained_variance_ratio(obj, p: int): plt.ylabel("Variance explained in ratio and cumulation") plt.xlabel("Number of factors") + plt.title('Explained variance ratio by the components and cumulation') plt.show() def corelations_circle(Xraw:pd.DataFrame, Xtransform:np.ndarray, p:int) -> pd.DataFrame: @@ -83,7 +84,7 @@ def corelations_circle(Xraw:pd.DataFrame, Xtransform:np.ndarray, p:int) -> pd.Da plt.xlabel('Component 1') plt.ylabel('Component 2') - + plt.title('Circle of the corelations between initial variables and components') plt.show() return pd.DataFrame({'id': Xraw.columns, 'COR_1': corvar[:, 0], 'COR_2': corvar[:, 1]}) @@ -106,11 +107,12 @@ def scatter_points(Xtransform:np.ndarray, Group_vect : pd.Series, Add_points : n plt.xlabel('Component 1') plt.ylabel('Component 2') + plt.title('Scatter plot of the transformed points') plt.show() return fig # %% LDA per motors____________________________________________ -for Motor in range(1,7,1): +for Motor in range(1,2,1): lda = LinearDiscriminantAnalysis() Movements_Data_Motor = Movements_Data_File.loc[Movements_Data_File['Motor'] == Motor].copy() @@ -128,7 +130,7 @@ for Motor in range(1,7,1): explained_variance_ratio(lda, p) coef = corelations_circle(Movements_Data_Motor, Xlda, Movements_Data_Motor.shape[1]) scatter_points(Xlda, Group_Data, New_points) - # print(coef) + print(coef) # %% ACP per motors (less revelating than LDA but still interesting) ____________________________________________ for Motor in range(1,7,1): diff --git a/examples/variable_by.py b/examples/variable_by.py index 28f06f3..34a9a7c 100644 --- a/examples/variable_by.py +++ b/examples/variable_by.py @@ -6,6 +6,9 @@ import seaborn as sns import scipy.signal as scs from pathlib import Path +import sys +sys.path.append("../") +# Must be ath te same level of main.py to work with regular execution from tools.database import Database from tools.utils import from_class_to_text from tools.plots import plot_all_axis, plot_grouped_load, plot_moving_axes diff --git a/tools/movement_extractor.py b/tools/movement_extractor.py index 8037edd..c22f5ba 100644 --- a/tools/movement_extractor.py +++ b/tools/movement_extractor.py @@ -8,9 +8,8 @@ import seaborn as sns import matplotlib.pyplot as plt import scipy.signal as scs -from tools.database import Database -from tools.plots import Spectrogram_plot -from tools.processing import RMS, FFT +from .database import Database +from .processing import RMS DB = Database(f"D:\VSB\Programs\DB\Robot2-LoadTest.sqlite") @@ -245,12 +244,10 @@ class Movement_Extractor: plt.show() return DataMovementFile - -# Example of uses : if __name__ == "__main__": # %% Extract movement from exel file and store it in Data_Movements.xlsx - Extractor = Movement_Extractor(fr"D:\VSB\Programs\data-collection\data\[2024-06-18] 10h53 data [30%-80%] [4ms] [class 4] [10 10 10 10 10 10] - Robot 2_TRACE.xlsx") + Extractor = Movement_Extractor(fr"D:\VSB\Programs\data-collection\data\[2024-06-18] 10h53 data [30%-80%] [4ms] [class 0] [10 10 10 10 10 10] - Robot 2_TRACE.xlsx") Total_Data = Extractor.movements_from_file(plot = 'current') # plots the extracted current Total_Data.to_excel("Data_Movements.xlsx") -- GitLab