<jupyter_start><jupyter_text>Pivot Tables, Plots for PSNR, SSIM, Bhattacharrya Distances<jupyter_code>from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import sys
import os
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import imshow
from PIL import Image
from IPython.display import display
%matplotlib inline

os.chdir('/Users/xxx/Documents/GANs_Research/my_imps/research_models/v3/evaluation')
import seaborn as sns
import pandas as pd
def table_to_df(csv, exp):
    df = pd.read_csv(csv)
    df.columns = ['num_label', 'value', 'file']
    df['exp'] = exp
    return df<jupyter_output><empty_output><jupyter_text>PSNR<jupyter_code>EAI_sensor_V4p = table_to_df('Iris/EAI_sensor_V4/psnr.csv', 'EAI_sensor_V4')
EAI_sensor_OGp = table_to_df('Iris/EAI_sensor_OG/psnr.csv', 'EAI_sensor_OG')
EAI_sensor_V3p = table_to_df('Iris/EAI_sensor_V3/psnr.csv', 'EAI_sensor_V3')
iris_pix2pixp = table_to_df('Iris/iris_pix2pix/psnr.csv', 'iris_pix2pix')

EI_sensor_OGp = table_to_df('Iris/EI_sensor_OG/psnr.csv', 'EI_sensor_OG')
EI_sensor_V3p = table_to_df('Iris/EI_sensor_V3/psnr.csv', 'EI_sensor_V3')
EI_sensor_V4p = table_to_df('Iris/EI_sensor_V4/psnr.csv', 'EI_sensor_V4')
EAI_pix2pixp = table_to_df('Iris/EAI_pix2pix/psnr.csv', 'EAI_pix2pix')

EI_pix2pixp = table_to_df('Iris/EI_pix2pix/psnr.csv', 'EI_pix2pix')
EI_sensor_V5p = table_to_df('Iris/EI_sensor_V5/psnr.csv', 'EI_sensor_V5')

EAI_sensor_V5p = table_to_df('Iris/EAI_sensor_V5/psnr.csv', 'EAI_sensor_V5')

EIO_sensor_V4p = table_to_df('Iris/EIO_sensor_V4/psnr.csv', 'EIO_sensor_V4')

IO_sensor_V4p = table_to_df('Iris/IO_sensor_V4/psnr.csv', 'IO_sensor_V4')
# Needs to be in the exact same order, since I'm going to append these three df's side by side
final_p = EAI_sensor_V4p.append([EAI_sensor_OGp,
                                EAI_sensor_V3p,
                                iris_pix2pixp,
                                EI_sensor_OGp,
                                EI_sensor_V3p,
                                EI_sensor_V4p,
                                EAI_pix2pixp,
                                EI_pix2pixp,
                                EI_sensor_V5p,
                                EAI_sensor_V5p,
                                EIO_sensor_V4p,
                                IO_sensor_V4p])
final_p
final_p.dtypes
conditions = [
    (final_p['num_label'] >=0) & (final_p['num_label'] <= 20),
    (final_p['num_label'] >=21) & (final_p['num_label'] <= 41),
    (final_p['num_label'] >=42) & (final_p['num_label'] <= 62),
    (final_p['num_label'] >=63) & (final_p['num_label'] <= 83),
    (final_p['num_label'] >=84) & (final_p['num_label'] <= 104)

]
choices = ["001", "002", "021", "031", "036"]
final_p['subject']= np.select(conditions, choices, default='null')
print(final_p)
final_p
psnr_mean = pd.pivot_table(final_p,index=["exp"],values=["value"])
psnr_mean
psnr_mean_by_subject = pd.pivot_table(final_p,index=["subject", "exp"],values=["value"], aggfunc=[np.mean])
psnr_mean_by_subject 
def make_subjects(df):

    conditions = [
        (df['num_label'] >=0) & (df['num_label'] <= 20),
        (df['num_label'] >=21) & (df['num_label'] <= 41),
        (df['num_label'] >=42) & (df['num_label'] <= 62),
        (df['num_label'] >=63) & (df['num_label'] <= 83),
        (df['num_label'] >=84) & (df['num_label'] <= 104)

    ]
    choices = ["001", "002", "021", "031", "036"]
    df['subject']= np.select(conditions, choices, default='null')
    return df<jupyter_output><empty_output><jupyter_text>SSIM<jupyter_code>EAI_sensor_V4s = table_to_df('Iris/EAI_sensor_V4/ssim.csv', 'EAI_sensor_V4')
EAI_sensor_OGs = table_to_df('Iris/EAI_sensor_OG/ssim.csv', 'EAI_sensor_OG')
EAI_sensor_V3s = table_to_df('Iris/EAI_sensor_V3/ssim.csv', 'EAI_sensor_V3')
iris_pix2pixs = table_to_df('Iris/iris_pix2pix/ssim.csv', 'iris_pix2pix')
EI_sensor_OGs = table_to_df('Iris/EI_sensor_OG/ssim.csv', 'EI_sensor_OG')
EI_sensor_V3s = table_to_df('Iris/EI_sensor_V3/ssim.csv', 'EI_sensor_V3')
EI_sensor_V4s = table_to_df('Iris/EI_sensor_V4/ssim.csv', 'EI_sensor_V4')
EAI_pix2pixs = table_to_df('Iris/EAI_pix2pix/ssim.csv', 'EAI_pix2pix')
EI_pix2pixs = table_to_df('Iris/EI_pix2pix/ssim.csv', 'EI_pix2pix')
EI_sensor_V5s = table_to_df('Iris/EI_sensor_V5/ssim.csv', 'EI_sensor_V5')
EAI_sensor_V5s = table_to_df('Iris/EAI_sensor_V5/ssim.csv', 'EAI_sensor_V5')
EIO_sensor_V4s = table_to_df('Iris/EIO_sensor_V4/ssim.csv', 'EIO_sensor_V4')
IO_sensor_V4s = table_to_df('Iris/IO_sensor_V4/ssim.csv', 'IO_sensor_V4')
final_s = EAI_sensor_V4s.append([EAI_sensor_OGs,
                                EAI_sensor_V3s,
                                iris_pix2pixs,
                                EI_sensor_OGs,
                                EI_sensor_V3s,
                                EI_sensor_V4s,
                                EAI_pix2pixs,
                                EI_pix2pixs,
                                EI_sensor_V5s,
                                EAI_sensor_V5s,
                                EIO_sensor_V4s,
                                IO_sensor_V4s])
final_s
final_s = make_subjects(final_s)
final_s
ssim_mean = pd.pivot_table(final_s,index=["exp"],values=["value"], aggfunc=[np.mean])
ssim_mean
ssim_mean_by_subject = pd.pivot_table(final_s,index=["subject", "exp"],values=["value"], aggfunc=[np.mean])
ssim_mean_by_subject<jupyter_output><empty_output><jupyter_text>BHATT<jupyter_code>EAI_sensor_V4b = table_to_df('Iris/EAI_sensor_V4/bhatt.csv', 'EAI_sensor_V4')
EAI_sensor_OGb = table_to_df('Iris/EAI_sensor_OG/bhatt.csv', 'EAI_sensor_OG')
EAI_sensor_V3b = table_to_df('Iris/EAI_sensor_V3/bhatt.csv', 'EAI_sensor_V3')
iris_pix2pixb = table_to_df('Iris/iris_pix2pix/bhatt.csv', 'iris_pix2pix')
EI_sensor_OGb = table_to_df('Iris/EI_sensor_OG/bhatt.csv', 'EI_sensor_OG')
EI_sensor_V3b = table_to_df('Iris/EI_sensor_V3/bhatt.csv', 'EI_sensor_V3')
EI_sensor_V4b = table_to_df('Iris/EI_sensor_V4/bhatt.csv', 'EI_sensor_V4')
EAI_pix2pixb = table_to_df('Iris/EAI_pix2pix/bhatt.csv', 'EAI_pix2pix')
EI_pix2pixb = table_to_df('Iris/EI_pix2pix/bhatt.csv', 'EI_pix2pix')
EI_sensor_V5b = table_to_df('Iris/EI_sensor_V5/bhatt.csv', 'EI_sensor_V5')
EAI_sensor_V5b = table_to_df('Iris/EAI_sensor_V5/bhatt.csv', 'EAI_sensor_V5')

EIO_sensor_V4b = table_to_df('Iris/EIO_sensor_V4/bhatt.csv', 'EIO_sensor_V4')
IO_sensor_V4b = table_to_df('Iris/IO_sensor_V4/bhatt.csv', 'IO_sensor_V4')
final_b = EAI_sensor_V4b.append([EAI_sensor_OGb,
                                EAI_sensor_V3b,
                                iris_pix2pixb,
                                EI_sensor_OGb,
                                EI_sensor_V3b,
                                EI_sensor_V4b,
                                EAI_pix2pixb,
                                EI_pix2pixb,
                                EI_sensor_V5b,
                                EAI_sensor_V5b,
                                EIO_sensor_V4b,
                                IO_sensor_V4b])

final_b
final_b = make_subjects(final_b)
final_b
bhatt_mean = pd.pivot_table(final_b,index=["exp"],values=["value"], aggfunc=[np.mean])
bhatt_mean
foo = bhatt_mean.reset_index()
foo
foo.columns = foo.columns.droplevel(0)
foo
foo.columns = ['exp', 'bhatt']
foo
bhatt_mean_by_subject = pd.pivot_table(final_b,index=["exp", "subject"],values=["value"], aggfunc=[np.mean])<jupyter_output><empty_output><jupyter_text>Summary Table of all the metrics per image<jupyter_code>g = final_b.merge(final_s, on=["file", "exp", "num_label", "subject"])
g
final = g.merge(final_p, on=["file", "exp", "num_label", "subject"])
final
final.columns = ['image_num', 'bhatt', 'image_file', 'exp', 'subj', 'ssim', 'psnr']
final = final[['image_num', 'image_file', 'subj', 'exp', 'bhatt', 'psnr', 'ssim']]
final<jupyter_output><empty_output><jupyter_text>Means<jupyter_code>def format_means(df, metric):
    foo = df.reset_index()
    foo.columns = foo.columns.droplevel(0)
    foo.columns = ['exp', '{}'.format(metric)]
    return foo
moo = psnr_mean.reset_index()
#moo.columns = moo.columns.droplevel(0)
moo.columns = ['exp', 'psnr']
moo
hoo = ssim_mean.reset_index()
hoo.columns = hoo.columns.droplevel(0)
hoo.columns = ['exp', 'ssim']
hoo
a = hoo.merge(moo, on='exp')
a
foo<jupyter_output><empty_output><jupyter_text>Means dataframe<jupyter_code>means = foo.merge(a, on='exp', how='right')
means<jupyter_output><empty_output><jupyter_text>Corr plot<jupyter_code>Iris_fid = {'EAI_sensor_V4': 292.781397710478,
            'EAI_sensor_OG':  294.28299200868344,
            'EAI_sensor_V3': 320.27602875309253,
            'iris_pix2pix': 223.93605974131592,
            'EI_sensor_OG':239.19802090258594,
            'EI_sensor_V3':288.72030727307583,
            'EI_sensor_V4':209.00391996933087,
            'EAI_pix2pix': 289.85910941654214,
            'EI_pix2pix':232.78058331302114,
            'EI_sensor_V5':295.97486935921165,
            'EAI_sensor_V5':331.212507932028,
            'EIO_sensor_V4':221.13156684754878,
            'IO_sensor_V4':223.80250864887427
            
            
    
}
mT = means.set_index('exp').T
foo = (pd.DataFrame.from_dict(Iris_fid, orient='index')).T
iris_metrics = mT.append(foo)
iris_metrics = iris_metrics.rename(index={0: 'fid'})
iris_metrics
iris_metrics_T_reset = ((iris_metrics.T).reset_index())
iris_metrics_T_reset = iris_metrics_T_reset.rename(columns={"index": "exp"})
iris_metrics_T_reset<jupyter_output><empty_output><jupyter_text>Plots for Paper<jupyter_code>iris_metrics_T_reset
#iris_metrics_T_reset.to_csv('iris_metrics_T_reset_10282020.csv')
iris_metrics<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13638729828214471, 'fraction_numerical': 0.04622592399791775, 'mean_word_length': 3.5119774542038518, 'pattern_counts': {'":': 1, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '20227', 'license': 'Apache-2.0', 'n_tokens_mistral': 4216, 'n_tokens_neox': 4000, 'n_words': 466, 'path': 'quant_eval/scripts/iris/Iris_Metrics.ipynb', 'repo_name': 'ffffconf1/anon', 'size': '9605'}