-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_insights.py
56 lines (46 loc) · 2.16 KB
/
data_insights.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from constants import RETINAL_LAYERS
sns.set_style('white')
# sns.set_context('poster')
df = pd.read_csv('./inputs/dataset/full.csv')
# print(df.head())
for lay in RETINAL_LAYERS:
cols = [col for col in df.columns if col.split('_')[0] == lay and 'THICKNESS' in col]
df_layer = pd.melt(df, id_vars=['GS'], value_vars=cols)
# df_layer = df[cols].stack()
# print(df_layer)
# df_layer['GS'] = np.repeat(df['GS'].values, len(cols))
print(df_layer.head())
fig, ax = plt.subplots(figsize=(12, 4))
sns.boxplot(x='variable', y='value', hue='GS', data=df_layer, ax=ax, showmeans=False, showfliers=False)
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, loc='center left', bbox_to_anchor=(1, 0.5), title='GS')
# print(ax.get_xticklabels())
ax.set_xticklabels(['_'.join(str(lbl).split('_')[1:])[:-2] for lbl in ax.get_xticklabels()], rotation=90)
fig.tight_layout()
ax.set_xlabel(lay)
ax.set_ylabel('Thickness [$\mu$m]')
fig.savefig(f'./outputs/insights/boxplots/boxplot_{lay}.png')
for lay in RETINAL_LAYERS:
cols = [col for col in df.columns if col.split('_')[0] == lay and 'THICKNESS' in col]
df_adim = pd.DataFrame()
df_adim['GS'] = df['GS']
for col in cols:
df_adim[col] = df[col] / df[col.replace(lay, 'RT')]
df_layer = pd.melt(df_adim, id_vars=['GS'], value_vars=cols)
# df_layer = df[cols].stack()
# print(df_layer)
# df_layer['GS'] = np.repeat(df['GS'].values, len(cols))
print(df_layer.head())
fig, ax = plt.subplots(figsize=(12, 4))
sns.boxplot(x='variable', y='value', hue='GS', data=df_layer, ax=ax, showmeans=False, showfliers=False)
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, loc='center left', bbox_to_anchor=(1, 0.5), title='GS')
# print(ax.get_xticklabels())
ax.set_xticklabels(['_'.join(str(lbl).split('_')[1:])[:-2] for lbl in ax.get_xticklabels()], rotation=90)
fig.tight_layout()
ax.set_xlabel(f'{lay}/RT')
ax.set_ylabel('Thickness adim. [-]')
fig.savefig(f'./outputs/insights/boxplots/boxplot_{lay}_adim.png')