Skip to content
Snippets Groups Projects
Commit 0f329e54 authored by antcsny's avatar antcsny
Browse files

Quickfix of the wrong sign of positions A1, A4, A5 when plotting

parent 0171b7fc
No related merge requests found
......@@ -220,6 +220,20 @@ def check_arguments(plot_type:str, variable:str, byvariable:str):
return False
return True
def correct_positions(dataframe:pd.DataFrame):
"""Inverts the sign of the positions A1, A4 and A5, as it is not done in the database constructor
Then, it is a quickfix of the data-processor the 18 Jul, 2024
Args:
dataframe (pd.DataFrame): dataframe to correct
"""
if 'Position_A1' in dataframe.columns:
dataframe['Position_A1'] = -dataframe['Position_A1']
if 'Position_A4' in dataframe.columns:
dataframe['Position_A4'] = -dataframe['Position_A4']
if 'Position_A5' in dataframe.columns:
dataframe['Position_A5'] = -dataframe['Position_A5']
def plot_all_axis(DB, variable:str, byvariable:str, byvalues:List, MovingMotor:int, Speed:int = 50, Class:int = 0, plot_type:str = 'Lineplot', doposition:bool = False, saving:bool = False):
"""Plots variable's data from the Dataframe on each robot axis (6 subplots), differenciating the data by 'byvariable' column's name.
Create a 'Lineplot' or a 'Boxplot', depending on the argument plot
......@@ -256,6 +270,8 @@ def plot_all_axis(DB, variable:str, byvariable:str, byvalues:List, MovingMotor:i
rms.append(np.sqrt(np.mean(df[f'{variable}_A{MovingMotor}']**2)))
print(f'Motor {MovingMotor} runs rms :',rms)
correct_positions(dataframe)
fig = plt.figure(figsize=(3*6,2*4)) # Data plot
for i in range(1,7,1):
axis = plt.subplot(2,3,i)
......@@ -326,7 +342,9 @@ def plot_moving_axes(DB, variable:str, byvariable:str, byvalues:List, Speed:int
dataframe = pd.concat([dataframe, df[300:900]])
rms.append(np.sqrt(np.mean(df[f'{variable}_A{Motor}']**2))) # limits data to 2-3 iterations
print(f'Motor {Motor} runs rms :',rms)
correct_positions(dataframe)
axis = plt.subplot(2,3,Motor)
if(plot_type=='Boxplot'):
sns.boxplot(data=dataframe, y=f'{variable}_A{Motor}', hue=byvariable, ax=axis)
......@@ -390,7 +408,8 @@ def plot_grouped_load(DB, variable:str, Classes:List[List], Motor:int, Speed:int
dataframe = pd.concat([dataframe, df[300:900]]) # limits data to 2-3 iterations
rms.append(np.sqrt(np.mean(df[f'{variable}_A{Motor}']**2)))
print(f'Motor {Motor} runs rms :',rms)
correct_positions(dataframe)
lin1 = sns.lineplot(data=dataframe,x='Sample_time', y=f'{variable}_A{Motor}', hue='Class', ax=axis, alpha=0.6) # data plot
if doposition:
......@@ -407,6 +426,6 @@ def plot_grouped_load(DB, variable:str, Classes:List[List], Motor:int, Speed:int
figures = Path(f"figures/{variable} by motor by grouped Load")
if not figures.exists():
figures.mkdir(parents=True)
fig.savefig(f"figures/{variable} by motor by grouped Load/{variable}_A{Motor}_by_grouped_load.png")
fig.savefig(f"figures/{variable} by motor by grouped Load/{variable}_A{Motor}_by_grouped_load{Classes}.png")
return fig
......@@ -36,4 +36,12 @@ fig2 = plot_grouped_load(DB, 'Current', [[0,2],[4,6],[8,10],[12,14]], 1, 60, dop
fig3 = plot_moving_axes(DB,'Current','Class',[0,2], doposition=True,saving=True)
plt.show()
# %% Bungee analysis
fig2 = plot_grouped_load(DB, 'Current', [[0,4],[0,8],[0,12]], 1, 60, doposition=True, saving=True)
fig1 = plot_all_axis(DB,'Current','Class',[0,8],MovingMotor=1, saving=True)
plt.show()
# %%
fig1 = plot_all_axis(DB,'Current','Class',[0] , MovingMotor=2, doposition=True, saving=True)
# %%
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