import numpy as np


import matplotlib.pyplot as plt



import matplotlib
matplotlib.rcParams.update({'font.size': 16})


plt.rcParams.update({
    "text.usetex": True,
    "font.family": "Helvetica"
})





def getPercentileLines(lineData,xs):
    print(np.shape(lineData))

    p05,p25,p50,p75,p95 = np.zeros(len(xs)), \
                          np.zeros(len(xs)), \
                          np.zeros(len(xs)), \
                          np.zeros(len(xs)), \
                          np.zeros(len(xs))
    
    for i in range(len(xs)):
        a = lineData[:,i]
        p05[i] = np.percentile(a,  5)
        p25[i] = np.percentile(a, 25)
        p50[i] = np.percentile(a, 50)
        p75[i] = np.percentile(a, 75)
        p95[i] = np.percentile(a, 95)

    return p05, p25, p50, p75, p95


orange = '#E69F00'
blue = '#0072B2'
green = '#009E73'
red = '#D55E00'


green2 = '#004D40'
blue2 = '#1E88E5'
orange2 = '#FFC107'
red2 = '#D81B60'

colSimp=orange
colGalExt=green
colGal = 'k'

agnHs = np.genfromtxt('agn_h_nF9.dat')
logfs = np.linspace(-9.,-6.,15)
p05,p25,p50,p75,p95 = getPercentileLines(agnHs,logfs)


p05,p25,p50,p75,p95 = getPercentileLines(agnHs,logfs)

print(np.shape(agnHs))


fs = [10.**f for f in logfs]
fs = np.atleast_1d(fs)

plt.fill_between(logfs,p05,p95,alpha=0.3,color=colSimp)
plt.fill_between(logfs,p25,p75,alpha=0.3,color=colSimp)
plt.plot(logfs,p50,color=colSimp,ls='--')



nFreqs=9
galLinesDir = '/home/ADF/middlehr/Documents/PTA/EPTAInterp/results/gal_model/f{0}/f{0}_plotting_things/'.format(nFreqs)
hdata = np.genfromtxt('{}/h_lines.dat'.format(galLinesDir))

print(np.shape(hdata))

p05,p25,p50,p75,p95 = getPercentileLines(hdata,logfs)

fs = [10.**f for f in logfs]
fs = np.atleast_1d(fs)

plt.fill_between(logfs,p05,p95,alpha=0.3,color=colGalExt)
plt.fill_between(logfs,p25,p75,alpha=0.3,color=colGalExt)
plt.plot(logfs,p50,color=colGalExt,ls='--')




plt.ylabel(r'$h_{\rm c}$')
plt.xlabel(r'$\log_{10} f\,({\rm Hz})$')
plt.tight_layout()
plt.savefig('hlines.png')
plt.show()

