#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# --- výpis počtů značek všech subjektů
seegs = [15, 32, 45, 48]
seeg = seegs[0]




def vypocet_pac_fac(seeg):

    """
    Phase-amplitude and Frequency-amplitude coupling at multiple low and high frequency bands

    Parameters:
    -----------
    seeg - patient number, e.g. 15, 32 or 48

    Returns:
    --------
    df_pac_all_frequency_bands - dataframe containing basic information about patient (start position of marked oscillation, selected channels, oscillation type) and value of Phase-amplitude coupling in each frequency band
        ('[[1, 4], [4, 8]]', '[[1, 4], [8, 12]]', '[[1, 4], [12, 20]]', ...  '[[4, 8], [8, 12]]', '[[4, 8], [12, 20]]',... '[[600, 1000], [1000, 2000]]'])
    df_fac_all_frequency_bands - dataframe containing Frequency-amplitude coupling values
    """

    import pandas as pd
    pd.set_option('display.width', 2000) #nezalamuj tabulky
    from fnusa_sigproc.methods_uni import pse, pac, fac
    from funkce.nacteni import znaceni, signal, info_o_patologii

    # --- výpis počtů značek věech subjektů
    seegs = [15, 32, 45, 48] # v případě, že nemám jiná data
    #seeg = seegs[0]

    fs = 5000
    okoli = 150

    try:
        df_all_groups = pd.read_pickle("Dataframes/df_all_groups_" + str(seeg) + ".pkl") #main_df.to_pickle("Dataframes/main_df_" + str(seeg) + ".pkl")
        sig_FR = pd.read_pickle("Dataframes/sig_FR_" + str(seeg) + "_okoli_" + str(2*okoli) + ".pkl")
        sig_vFR = pd.read_pickle("Dataframes/sig_vFR_" + str(seeg) + "_okoli_" + str(2*okoli) + ".pkl")
        sig_uFR = pd.read_pickle("Dataframes/sig_uFR_" + str(seeg) + "_okoli_" + str(2*okoli) + ".pkl")

    except (OSError, IOError) as e:

        # nazev, FR, vFR, uFR, df_all_groups = znaceni(seeg)
        nazev, FR, vFR, uFR, df_all_groups = info_o_patologii(seeg)   # přidání informace o patologii
        sig_FR, sig_vFR, sig_uFR = signal(seeg, okoli)


    # čištění nepotřebných dat 
    # columns = ['pse', 'fac', 'pac', 'sample_entropy0', 'shannon_entropy','sample_entropy1', 'stop', 'ch_idx', 'group']
    # df_pac_all_frequency_bands = main_df.drop(columns, 1)

    # přidání ingormace o čísle pacienta - v případě potřeby concatu dataframů
    df_all_groups['seeg'] = seeg

    # získání kostry databáze
    df_pac_all_frequency_bands = df_all_groups.copy()

    # --- volba frekvencí
    low_fc = [1,4],[4,8],[8,12],[12,20],[20,45],[55,80],[80,250],[250,600],[600,1000]
    high_fc = [4,8],[8,12],[12,20],[20,45],[55,80],[80,250],[250,600],[600,1000],[1000,2000]

    # --- definice nových dataframe
    for lfc in low_fc:
        for hfc in high_fc:
            if lfc[0] != hfc[0] and lfc[0] < hfc[0]:
                df_pac_all_frequency_bands[str([lfc, hfc])]=0 #df_pac['rozhrani'+str(i)]=0

    # definice druhého df
    df_fac_all_frequency_bands = df_pac_all_frequency_bands.copy()


    ### Phase-amplitude & Frequency-amplitude coupling extended

    # Fast Ripples
    # hledáni indexu sloupce pro plnění hodnot
    sloupec = df_pac_all_frequency_bands.columns.get_loc(str([low_fc[0], high_fc[0]]))
    start_sloupec = sloupec

    for i in range(0, len(sig_FR.columns)):
        for lfc in low_fc:
            for hfc in high_fc:
                if lfc[0] != hfc[0] and lfc[0] < hfc[0]:

                    pac_result = pac(sig_FR[i], fs, lfc[0], lfc[1], hfc[0], hfc[1])
                    fac_result = fac(sig_FR[i], fs, lfc[0], lfc[1], hfc[0], hfc[1])

                    #print("{}/{}: {}: \t{}".format(i, sloupec, [lfc, hfc], pac_result))

                    df_pac_all_frequency_bands.iloc[i, sloupec] = pac_result
                    df_fac_all_frequency_bands.iloc[i, sloupec] = fac_result

                    sloupec += 1

        sloupec = start_sloupec


    # Very Fast Ripples

    prvni_vFR_idx = len(sig_FR.columns)

    sloupec = df_pac_all_frequency_bands.columns.get_loc(str([low_fc[0], high_fc[0]]))
    start_sloupec = sloupec

    for i in range(0, len(sig_vFR.columns)):
        for lfc in low_fc:
            for hfc in high_fc:
                if lfc[0] != hfc[0] and lfc[0] < hfc[0]:

                    pac_result = pac(sig_vFR[i], fs, lfc[0], lfc[1], hfc[0], hfc[1])
                    fac_result = fac(sig_vFR[i], fs, lfc[0], lfc[1], hfc[0], hfc[1])

                    df_pac_all_frequency_bands.iloc[prvni_vFR_idx+i, sloupec] = pac_result
                    df_fac_all_frequency_bands.iloc[prvni_vFR_idx+i, sloupec] = fac_result

                    sloupec += 1

        sloupec = start_sloupec



    # Ultra Fast Ripples
    prvni_uFR_idx = prvni_vFR_idx + len(sig_vFR.columns)


    sloupec = df_pac_all_frequency_bands.columns.get_loc(str([low_fc[0], high_fc[0]]))
    start_sloupec = sloupec

    for i in range(0, len(sig_uFR.columns)):
        for lfc in low_fc:
            for hfc in high_fc:
                if lfc[0] != hfc[0] and lfc[0] < hfc[0]:

                    pac_result = pac(sig_uFR[i], fs, lfc[0], lfc[1], hfc[0], hfc[1])
                    fac_result = fac(sig_uFR[i], fs, lfc[0], lfc[1], hfc[0], hfc[1])

                    df_pac_all_frequency_bands.iloc[prvni_uFR_idx+i, sloupec] = pac_result
                    df_fac_all_frequency_bands.iloc[prvni_uFR_idx+i, sloupec] = fac_result

                    sloupec += 1

        sloupec = start_sloupec


    df_pac_all_frequency_bands.to_pickle("Dataframes/df_pac_all_frequency_bands_" + str(seeg) + ".pkl")
    df_fac_all_frequency_bands.to_pickle("Dataframes/df_fac_all_frequency_bands_" + str(seeg) + ".pkl")


    print('Finished and saved!')

    return df_pac_all_frequency_bands, df_fac_all_frequency_bands, okoli



def vykresleni_pac_fac_boxplot(seegs, okoli):
    import pandas as pd

    """
    Phase-amplitude and Frequency-amplitude coupling at multiple low and high frequency bands

    Parameters:
    -----------
    seegs - patient number, e.g. [15, 32, 45, 48]

    Returns:
    --------
    graphs
    Note: calling of a function: vykresleni_pac_fac([15, 32, 45, 48])

    """
    okoli = 150
    seegs = [15, 32, 45, 48]

    # df_all_groups: pd.DataFrame = pd.concat([FR, vFR, uFR])
    # df_all_groups.reset_index(drop=True, inplace=True)
    #
    # df_all_groups.to_pickle("Dataframes/df_all_groups_" + str(seeg) + ".pkl") #("Dataframes/df_all_groups_" + str(seeg) + ".pkl")

    df_pac_all_frequency_bands_one_seeg = pd.DataFrame()
    df_fac_all_frequency_bands_one_seeg = pd.DataFrame()

    df_pac_all_frequency_bands_all_seegs = pd.DataFrame()
    df_fac_all_frequency_bands_all_seegs = pd.DataFrame()

    df_pac_all_frequency_bands_all_seegs_list=list()
    df_fac_all_frequency_bands_all_seegs_list = list()


    for seeg in seegs:
        try:
            df_pac_all_frequency_bands_one_seeg = pd.read_pickle("Dataframes/df_pac_all_frequency_bands_" + str(seeg) + ".pkl")
            df_fac_all_frequency_bands_one_seeg = pd.read_pickle("Dataframes/df_fac_all_frequency_bands_" + str(seeg) + ".pkl")

            # df_all_groups = pd.read_pickle("Dataframes/df_all_groups_" + str(seeg) + ".pkl") #main_df.to_pickle("Dataframes/main_df_" + str(seeg) + ".pkl")


        except (OSError, IOError) as e:
            print('zatím nic, později sem dát vypocet_pac_fac(seeg)')
            print('df_pac_all_frequency_bands, df_fac_all_frequency_bands = vypocet_pac_fac(seeg)')

        #df_pac_all_frequency_bands_all_seegs_list = \
        df_pac_all_frequency_bands_all_seegs_list.append(df_pac_all_frequency_bands_one_seeg)
        #df_fac_all_frequency_bands_all_seegs_list = \
        df_fac_all_frequency_bands_all_seegs_list.append(df_fac_all_frequency_bands_one_seeg)


    # df_pac_all_frequency_bands_all_seegs: pd.DataFrame =  pd.concat(df_pac_all_frequency_bands_one_seeg)

    df_pac_all_frequency_bands_all_seegs = pd.concat(df_pac_all_frequency_bands_all_seegs_list)
    df_fac_all_frequency_bands_all_seegs = pd.concat(df_fac_all_frequency_bands_all_seegs_list)



    df_pac_all_frequency_bands_all_seegs.to_pickle("Dataframes/df_pac_all_frequency_bands_all_seegs_" + str(seegs) + ".pkl")
    df_fac_all_frequency_bands_all_seegs.to_pickle("Dataframes/df_fac_all_frequency_bands_all_seegs_" + str(seegs) + ".pkl")


    # čistění proměnných ať temporary proměnné nepletou
    del df_pac_all_frequency_bands_all_seegs_list
    del df_fac_all_frequency_bands_all_seegs_list
    del df_pac_all_frequency_bands_one_seeg
    del df_fac_all_frequency_bands_one_seeg


    import matplotlib.pyplot as plt
    import seaborn as sns


    low_fc = [1,4],[4,8],[8,12],[12,20],[20,45],[55,80],[80,250],[250,600],[600,1000]
    high_fc = [4,8],[8,12],[12,20],[20,45],[55,80],[80,250],[250,600],[600,1000],[1000,2000]


    plt.figure(1, figsize=(20,5))
    # fig_pse = sns.boxplot(x='typ', y="pse", data=main_df, palette="Set1", orient="v", width=0.5) # hue="ch_name"



    pocet_kombinaci = df_pac_all_frequency_bands_all_seegs.shape[1] - 7 # 7 sloupců jsou popisy dat

    for sub in range(1, 9):

        colname = df_pac_all_frequency_bands_all_seegs.columns[7+sub-1]

        plt.subplot(1, len(range(1, 9)), sub)
        fig_all = sns.boxplot(x='typ', y=colname, data=df_pac_all_frequency_bands_all_seegs, hue="seeg", palette="Set1", orient="v", width=0.5) # hue="ch_name"


        max_graf = 1 #option number two
        plt.ylim(0, max_graf)
        #plt.tight_layout()

        # fig_pse_sw = sns.swarmplot(x="typ", y="pse", data=main_df, hue="ch_name", dodge=True, color=".3", size=3) ###########přidat  hue="ch_name",

        fig_all.legend_.remove()

    plt.show()



    plt.savefig("Grafy/pac_all_frequency_bands_all_seegs_" + str(seegs) + ".png")


    # nepřehledné zobrazení
    ## čtvercový subplot
    # for sub in range(1, 56):
    #
    #     colname = df_pac_all_frequency_bands_all_seegs.columns[7+sub-1]
    #
    #     plt.subplot(8, 9, sub)
    #     fig_all = sns.boxplot(x='typ', y=colname, data=df_pac_all_frequency_bands_all_seegs, hue="seeg", palette="Set1", orient="v", width=0.5) # hue="ch_name"
    #
    #
    #     max_graf = 1 #option number two
    #     plt.ylim(0, max_graf)
    #     #plt.tight_layout()
    #
    #     # fig_pse_sw = sns.swarmplot(x="typ", y="pse", data=main_df, hue="ch_name", dodge=True, color=".3", size=3) ###########přidat  hue="ch_name",
    #
    #     fig_all.legend_.remove()
    #
    # plt.show()

# for seeg in seegs:
#     vykresleni_pac_fac_heatmap(seegs, okoli)


def vykresleni_pac_fac_heatmap(): # později případně volání (seegs, okoli) - pokud bude měněno okolí
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns

    """
    Phase-amplitude and Frequency-amplitude coupling at multiple low and high frequency bands

    Parameters:
    -----------
    seegs - patient number, e.g. [15, 32, 45, 48]

    Returns:
    --------
    graphs
    Note: calling of a function: vykresleni_pac_fac([15, 32, 45, 48])

    """
    okoli = 150
    seegs = [15, 32, 45, 48]
    # seegs = [45, 48]


    okoli = 2*okoli


    def fill_upper_diag(fq):
        import numpy as np
        n = int(np.sqrt(len(fq)*2))+1
        mask = np.tri(n,dtype=bool, k=0) # or np.arange(n)[:,None] > np.arange(n)
        mask = np.logical_not(mask) # pro upper tria -- vymazat tento řádek a je z toho lower
        out = np.zeros((n,n))#,dtype=int)
        out[mask] = fq
        return out, mask


    # výpočet pro obě metody -- stačí načtení picklu a dál zobecnit jméno (odstranit pac), přidat met do subplotu a zaindexovat subploty..
    methods = ['pac', 'fac']
    met_idx = 0
    fig_number = 0

    for met in methods:
        print('OK_methods')

        met_idx = met_idx+1

        for seeg in seegs:

            # načtení dat (případně výpočet přes vypocet_pac_fac(seeg))

            try:
                df_met_all_frequency_bands = pd.read_pickle("Dataframes/df_" + str(met) + "_all_frequency_bands_" + str(seeg) + ".pkl")
            except (OSError, IOError) as e:
                df_met_all_frequency_bands = vypocet_pac_fac(seeg)

            # df sort, aby se v grafech zobrazovalo vždy stejné pořadí
            df_met_all_frequency_bands = df_met_all_frequency_bands.sort_values(['group', 'resection'])


            # hledání FR, vFR a uFR pro průměrování a odstranění hodnot nan
            df_met_FR = (df_met_all_frequency_bands.where(df_met_all_frequency_bands.group==0)).dropna()
            df_met_vFR = (df_met_all_frequency_bands.where(df_met_all_frequency_bands.group==1)).dropna()
            df_met_uFR = (df_met_all_frequency_bands.where(df_met_all_frequency_bands.group==2)).dropna()


            resection_info = df_met_all_frequency_bands['resection'].unique()

            for res in resection_info:
                print('Ok_res_info')

                # ještě dělení na resection no/yes
                df_met_FR_res = (df_met_FR.where(df_met_FR.resection==res)).dropna()
                df_met_vFR_res = (df_met_vFR.where(df_met_vFR.resection==res)).dropna()
                df_met_uFR_res = (df_met_uFR.where(df_met_uFR.resection==res)).dropna()


                # průměrování hodnot
                df_met_FR_mean = df_met_FR_res.mean()
                df_met_vFR_mean = df_met_vFR_res.mean()
                df_met_uFR_mean = df_met_uFR_res.mean()


                # první sloupec, který mě zajímá
                # sloupec = df_met_FR.columns.get_loc(str([low_fc[0], high_fc[0]]))

                # beru si data, která mě zajímají
                df_met_FR_mean = df_met_FR_mean[5:len(df_met_all_frequency_bands)]
                df_met_vFR_mean = df_met_vFR_mean[5:len(df_met_all_frequency_bands)]
                df_met_uFR_mean = df_met_uFR_mean[5:len(df_met_all_frequency_bands)]


                # df_met_FR_mean.axes
                # df_met_FR_mean.values


                # průměrné hodnoty jednotlivých frekvenčních pásem
                fq_FR_met = df_met_FR_mean.values
                fq_vFR_met = df_met_vFR_mean.values
                fq_uFR_met = df_met_uFR_mean.values

                ### výpočet diagonální matice + definice masky

                upper_FR, mask = fill_upper_diag(fq_FR_met)
                upper_vFR, mask = fill_upper_diag(fq_vFR_met)
                upper_uFR, mask = fill_upper_diag(fq_uFR_met)


                import numpy as np
                # deleting last row and first column
                # upper = np.delete(fq,(len(low_fc)), axis=0) #row
                # upper = np.delete(fq,(0), axis=1) #column


                low_high_fc = [1,4],[4,8],[8,12],[12,20],[20,45],[55,80],[80,250],[250,600],[600,1000],[1000,2000]


                # matice v požadovaném tvaru
                if len(resection_info)==1:
                    frequency_matrix_FR_res0 = pd.DataFrame(data=upper_FR, index=low_high_fc, columns=low_high_fc) #index=high_fc, columns=low_fc)
                    frequency_matrix_vFR_res0 = pd.DataFrame(data=upper_vFR, index=low_high_fc, columns=low_high_fc)
                    frequency_matrix_uFR_res0 = pd.DataFrame(data=upper_uFR, index=low_high_fc, columns=low_high_fc)

                elif len(resection_info)==2:
                    if res == 'no':
                        frequency_matrix_FR_res0 = pd.DataFrame(data=upper_FR, index=low_high_fc, columns=low_high_fc) #index=high_fc, columns=low_fc)
                        frequency_matrix_vFR_res0 = pd.DataFrame(data=upper_vFR, index=low_high_fc, columns=low_high_fc)
                        frequency_matrix_uFR_res0 = pd.DataFrame(data=upper_uFR, index=low_high_fc, columns=low_high_fc)
                    elif res == 'yes':
                        frequency_matrix_FR_res1 = pd.DataFrame(data=upper_FR, index=low_high_fc, columns=low_high_fc) #index=high_fc, columns=low_fc)
                        frequency_matrix_vFR_res1 = pd.DataFrame(data=upper_vFR, index=low_high_fc, columns=low_high_fc)
                        frequency_matrix_uFR_res1 = pd.DataFrame(data=upper_uFR, index=low_high_fc, columns=low_high_fc)


                # vyber = frequency_matrix.columns[0]


                vvmin = min([min(df_met_FR_mean.values), min(df_met_vFR_mean.values), min(df_met_uFR_mean.values)])
                vvmax = max([max(df_met_FR_mean.values), max(df_met_vFR_mean.values), max(df_met_uFR_mean.values)])


                mask_fig = np.logical_not(mask)






            ####### vykreslení

            if len(resection_info) == 1:
                print('k těmto datům chybí porovnání kanálu z resekované nebo neresekované oblasti')
                figsize_res = 20,5
                nrow = 1
            elif len(resection_info) ==2:
                figsize_res = 20,10
                nrow = 2



            if met == 'pac':
                method_name = 'Phase_amplitude_coupling'
                cmap_met= "Reds"    #"PiYG"
            elif met == 'fac':
                method_name = 'Frequency_amplitude_coupling'
                cmap_met="Greens"



            fig_number = fig_number + 1 # musí být před každým figure

            # vykresleny průměrné hodnoty


            #přepisuji aby napsal správně titul ke grafu (nyní je hodnota již druhého prvku v res_info
            res0 = resection_info[0]

            plt.figure(fig_number, figsize=figsize_res)
            plt.subplots_adjust(left=None, bottom=0.22, right=None, top=None, wspace=None, hspace=0.54)

            plt.suptitle('' + str(method_name) +': mean, seeg_' + str(seeg))
            plt.subplot(nrow,3,1)
            fig_FR = sns.heatmap(frequency_matrix_FR_res0, mask=mask_fig, vmin=vvmin, vmax=vvmax, xticklabels=1, square=True, cmap=str(cmap_met)) #, annot=True) # xticklabels zařídí zobrazení všech labels
            fig_FR.set_aspect("equal")
            plt.title('Fast ripples, resection: ' + str(res0.lower())) #Method' + str(met.upper()) + '_FR_seeg' + str(seeg) + '


            plt.subplot(nrow,3,2)
            fig_vFR = sns.heatmap(frequency_matrix_vFR_res0, mask=mask_fig, vmin=vvmin, vmax=vvmax, xticklabels=1, square=True, cmap=str(cmap_met)) #, annot=True)
            fig_vFR.set_aspect("equal")
            plt.title('Very fast ripples, resection: ' + str(res0.lower())) #('Method' + str(met.upper()) + '_vFR_seeg' + str(seeg) + '_resection_' + str(res0))

            plt.subplot(nrow,3,3)
            fig_uFR=sns.heatmap(frequency_matrix_uFR_res0, mask=mask_fig, vmin=vvmin, vmax=vvmax, xticklabels=1, square=True, cmap=str(cmap_met)) #, annot=True)
            fig_uFR.set_aspect("equal")
            plt.title('Ultra fast ripples, resection: ' + str(res0.lower())) #('Method' + str(met.upper()) + '_uFR_seeg' + str(seeg) + '_resection_' + str(res0))


            if len(resection_info)==2: # tedy pokud existují z seeg souboru oba kanály - resekovaný i neresekovaný

                res1 = resection_info[1]


                plt.subplot(nrow,3,4)
                fig_FR = sns.heatmap(frequency_matrix_FR_res1, mask=mask_fig, vmin=vvmin, vmax=vvmax, xticklabels=1, square=True, cmap=str(cmap_met)) #, annot=True) # xticklabels zařídí zobrazení všech labels
                fig_FR.set_aspect("equal")
                plt.title('Fast ripples, resection: ' + str(res1)) #('Method_' + str(met.upper()) + '_FR_seeg' + str(seeg) + '_resection_' + str(res))


                plt.subplot(nrow,3,5)
                fig_vFR = sns.heatmap(frequency_matrix_vFR_res1, mask=mask_fig, vmin=vvmin, vmax=vvmax, xticklabels=1, square=True, cmap=str(cmap_met)) #, annot=True)
                fig_vFR.set_aspect("equal")
                plt.title('Very fast ripples, resection: ' + str(res1)) #('Method_' + str(met.upper()) + '_vFR_seeg' + str(seeg) + '_resection_' + str(res))

                plt.subplot(nrow,3,6)
                fig_uFR=sns.heatmap(frequency_matrix_uFR_res1, mask=mask_fig, vmin=vvmin, vmax=vvmax, xticklabels=1, square=True, cmap=str(cmap_met)) # annot=True)
                fig_uFR.set_aspect("equal")
                plt.title('Ultra fast ripples, resection: ' + str(res1)) #('Method_' + str(met.upper()) + '_uFR_seeg' + str(seeg) + '_resection_' + str(res))


            plt.savefig("Grafy/" + str(method_name) + "_mean_" + str(seeg) + "_okoli_" + str(okoli) + ".png")


            # matice rozdílu, absolutní hodnoty
            diff_FR_vFR = abs(frequency_matrix_FR_res0 - frequency_matrix_vFR_res0)
            diff_vFR_uFR = abs(frequency_matrix_vFR_res0 - frequency_matrix_uFR_res0)
            diff_uFR_FR = abs(frequency_matrix_uFR_res0 - frequency_matrix_FR_res0)

            vvmin_diff = min([diff_FR_vFR.values.min(), diff_vFR_uFR.values.min(), diff_uFR_FR.values.min()])
            vvmax_diff = max([diff_FR_vFR.values.max(), diff_vFR_uFR.values.max(), diff_uFR_FR.values.max()])



            # vykreslení

            fig_number = fig_number + 1 # musí být před každým figure

            res = resection_info[0]

            plt.figure(fig_number, figsize=figsize_res)
            plt.subplots_adjust(left=None, bottom=0.22, right=None, top=None, wspace=None, hspace=0.54)
            plt.suptitle('' + str(method_name) +', abs(diff), seeg_' + str(seeg))

            plt.subplot(nrow,3,1)
            sns.heatmap(diff_FR_vFR, mask=mask_fig, vmin=vvmin_diff, vmax=vvmax_diff, xticklabels=1, square=True, cmap=str(cmap_met)) # xticklabels zařídí zobrazení všech labels
            plt.title('Fast ripples - very fast ripples, resection: ' + str(res)) #'Method' + str(met.upper()) + '_diff_FR_vFR_seeg' + str(seeg))

            plt.subplot(nrow,3,2)
            sns.heatmap(diff_vFR_uFR, mask=mask_fig, vmin=vvmin_diff, vmax=vvmax_diff, xticklabels=1, square=True, cmap=str(cmap_met))
            plt.title('Very fast ripples - ultra fast ripples, resection: ' + str(res)) #('Method' + str(met.upper()) + '_diff_vFR_uFR_seeg' + str(seeg))

            plt.subplot(nrow,3,3)
            sns.heatmap(diff_uFR_FR, mask=mask_fig, vmin=vvmin_diff, vmax=vvmax_diff, xticklabels=1, square=True, cmap=str(cmap_met))
            plt.title('Ultra fast ripples - fast ripples, resection: ' + str(res)) #('Method' + str(met.upper()) + '_diff_uFR_FR_seeg' + str(seeg))


            if len(resection_info)==2: # tedy pokud existují z seeg souboru oba kanály - resekovaný i neresekovaný

                res1 = resection_info[1]

                # matice rozdílu, absolutní hodnoty
                diff_FR_vFR = abs(frequency_matrix_FR_res1 - frequency_matrix_vFR_res1)
                diff_vFR_uFR = abs(frequency_matrix_vFR_res1 - frequency_matrix_uFR_res1)
                diff_uFR_FR = abs(frequency_matrix_uFR_res1 - frequency_matrix_FR_res1)


                plt.figure(fig_number, figsize=figsize_res)
                plt.subplots_adjust(left=None, bottom=0.22, right=None, top=None, wspace=None, hspace=0.54)
                plt.suptitle('' + str(method_name) +', abs(diff), seeg_' + str(seeg))

                plt.subplot(nrow,3,4)
                sns.heatmap(diff_FR_vFR, mask=mask_fig, vmin=vvmin_diff, vmax=vvmax_diff, xticklabels=1, square=True, cmap=str(cmap_met)) # xticklabels zařídí zobrazení všech labels
                plt.title('Fast ripples - very fast ripples, resection: ' + str(res1)) #('Method' + str(met.upper()) + '_diff_FR_vFR_seeg' + str(seeg))

                plt.subplot(nrow,3,5)
                sns.heatmap(diff_vFR_uFR, mask=mask_fig, vmin=vvmin_diff, vmax=vvmax_diff, xticklabels=1, square=True, cmap=str(cmap_met))
                plt.title('Very fast ripples - ultra fast ripples, resection: ' + str(res1)) #('Method' + str(met.upper()) + '_diff_vFR_uFR_seeg' + str(seeg))

                plt.subplot(nrow,3,6)
                sns.heatmap(diff_uFR_FR, mask=mask_fig, vmin=vvmin_diff, vmax=vvmax_diff, xticklabels=1, square=True, cmap=str(cmap_met))
                plt.title('Ultra fast ripples - fast ripples, resection: ' + str(res1)) #('Method' + str(met.upper()) + '_diff_uFR_FR_seeg' + str(seeg))


            plt.savefig("Grafy/" + str(method_name) + "_abs_diff_" + str(seeg) + "_okoli_" + str(okoli) + ".png")



