from numpy import *
import numpy as np
from matplotlib.pyplot import *
import matplotlib as mpl
mpl.rcParams['xtick.major.size'] = 8
mpl.rcParams['xtick.minor.size'] = 4
mpl.rcParams['xtick.major.width'] = 1.5
mpl.rcParams['xtick.minor.width'] = 1.5
mpl.rcParams['ytick.major.size'] = 8
mpl.rcParams['ytick.minor.size'] = 4
mpl.rcParams['ytick.major.width'] = 1.5
mpl.rcParams['ytick.minor.width'] = 1.5

ticksize=20
labelsize=22
shade_start=55.93
shade_stop =257.8

semw=loadtxt('semw00.txt')
semn=loadtxt('semn00.txt')
start=loadtxt('sr_start00.txt')
coin=loadtxt('sr_coin00.txt')

##############################################################################3
fig=figure(figsize=(10,14))
ax=fig.add_subplot(6,1,1)
plot(semw[:,0],semw[:,1],label='SEM_wide')
plot(semn[:,0],semn[:,1],label='SEM_narrow')
#title('Year 2000 Comparision',fontsize=20)
ylabel('UV Flux \n $\mathrm{\mathsf{[cm^{-2}s^{-1}]}}$',fontsize=18)
ax.ticklabel_format(axis='y',style='sci')
#legend()
xticks(())
yticks([2e10,4e10,6e10,8e10,1e11],['2e10','4e10','6e10','8e10','1e11'],fontsize=18)
ylim(1e10,1e11)
fill_between(array([shade_start,shade_stop]),array([1,1])*1e10,array([1,1])*1e11,color='y',alpha=0.2)
xlim(0,365)

##############################################################################3
subplot(6,1,2)
plot(start[:,0],start[:,1],'r',label='TOF Start Count Rate')
#legend()
ylabel('SF \n $\mathrm{\mathsf{[s^{-1}]}}$',fontsize=18)
ylim(7000,23000)
fill_between(array([shade_start,shade_stop]),array([1,1])*7e3,array([1,1])*23000,color='y',alpha=0.2)
xticks(())
yticks([1e4,1.4e4,1.8e4,2.2e4],['1e4','1.4e4','1.8e4','2.2e4'],fontsize=18)

xlim(0,365)

##############################################################################3
ax=fig.add_subplot(6,1,3)
plot(coin[:,0],coin[:,1],'m',label='TOF Double Coincidence Rate')
#legend()
ylabel('SFR \n $\mathrm{\mathsf{[s^{-1}]}}$',fontsize=18)
xlabel('DOY in 2000',fontsize=18)
ax.tick_params(axis='x',which='major',top='off')
xticks(fontsize=18)
yticks(fontsize=18)
ylim(0,240)
fill_between(array([shade_start,shade_stop]),array([1,1])*0,array([1,1])*240,color='y',alpha=0.2)
xlim(0,365)

show()

ax.annotate("  ",
	          xy=(-1., -2), xycoords='axes fraction',
	          xytext=(-0.845, -1), textcoords='axes fraction',
	          size=1, va="center", ha="center",

	          bbox=dict(boxstyle="square", fc="w"),
	          arrowprops=dict(
#					  arrowstyle="--",
#		                          connectionstyle="arc3,rad=0.2",
#		                          relpos=(0., 0.),
#		                          fc="w"), 
			facecolor='black', shrink=0.01,edgecolor='black',width=1.)
	          )

ax.annotate("  ",
	          xy=(1.,-2), xycoords='axes fraction',
	          xytext=(0.705, -1), textcoords='axes fraction',
	          size=1, va="center", ha="center",

	          bbox=dict(boxstyle="square", fc="w"),
	          arrowprops=dict(
#					  arrowstyle="--",
#		                          connectionstyle="arc3,rad=0.2",
#		                          relpos=(0., 0.),
#		                          fc="w"), 
			facecolor='black', shrink=0.01,edgecolor='black',width=1.)
	          )
##############################################################################3
ax=fig.add_subplot(3,1,3)

coin_doy=coin[:,0]
coin_flux=coin[:,1]
mask_coin=(coin_doy>shade_start)*(coin_doy<shade_stop)
plot(coin_doy[mask_coin],coin_flux[mask_coin]/(4470.037609*coin_doy[mask_coin]**(-0.908087)),'m',label='SFR')

plot(semw[:,0],semw[:,1]/np.average(semw[:,1]),label='SEM_W',linewidth=2)
plot(semn[:,0],semn[:,1]/np.average(semn[:,1]),label='SEM_N',linewidth=2)

start_doy=start[:,0]
start_flux=start[:,1]
mask_start=(start_doy>shade_start)*(start_doy<shade_stop)
plot(start_doy[mask_start],start_flux[mask_start]/(163175.633526*start_doy[mask_start]**(-0.534131))-1,'r',label='SF',linewidth=1)


#legend()
ylabel('Percent \n deviation',fontsize=18)
xlabel('DOY in 2000',fontsize=18)
ax.tick_params(axis='x',which='major',top='off')
xticks(fontsize=18)
yticks(fontsize=18)
ylim(0.5,1.5)
xlim(shade_start,shade_stop)
tight_layout(pad=0.5,h_pad=-3.6,w_pad=1)
#tight_layout(pad=0.5,h_pad=-1.5,w_pad=0.001)
show()


