import numpy

datapath = '../../data/instruments/'
imgpath  = '../../img/'

# load data
range_virgo = numpy.loadtxt(datapath + 'o3a_range_virgo.txt')
range_llo   = numpy.loadtxt(datapath + 'o3a_range_llo.txt')
range_lho   = numpy.loadtxt(datapath + 'o3a_range_lho.txt')

import matplotlib
matplotlib.use('agg')
matplotlib.rcParams['text.usetex'] = True
matplotlib.rcParams['font.size'] = 9
matplotlib.rcParams['savefig.dpi'] = 300
matplotlib.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
matplotlib.rcParams['legend.fontsize'] = 9
from matplotlib import pyplot
pyplot.rc('axes', axisbelow=True)

colors = {'L1': '#4ba6ff', 'H1': '#ee0000', 'V1': '#9b59b6'}

fig = pyplot.figure(figsize=(3.375,3))

pyplot.plot( range_virgo[:,0], range_virgo[:,1], '.', label='Virgo', markersize=2, color=colors['V1'])
pyplot.plot( range_lho[:,0], range_lho[:,1], '.', label='LIGO Hanford', markersize=2, color=colors['H1'])
pyplot.plot( range_llo[:,0], range_llo[:,1], '.', label='LIGO Livingston', markersize=2, color=colors['L1'])

l1, = pyplot.plot([0], [0], '-', linewidth=4, label=r'$\mathrm{LIGO}\,\mathrm{Livingston}$', color=colors['L1'])
l2, = pyplot.plot([0], [0], '-', linewidth=4, label=r'$\mathrm{LIGO}\,\mathrm{Hanford}$', color=colors['H1'])
l3, = pyplot.plot([0], [0], '-', linewidth=4, label=r'$\mathrm{Virgo}$', color=colors['V1'])

pyplot.ylim([0, 150])
pyplot.xlim([0, 183])
pyplot.xlabel(r'$\mathrm{Time}\,\mathrm{[Days]}\,\mathrm{from}\,\mathrm{April}\,\mathrm{01},\,\mathrm{2019}$')
#pyplot.xlabel(r'$\mathrm{Days}\,\mathrm{from}\,\mathrm{O3a}\,\mathrm{start}$')
pyplot.ylabel(r'$\mathrm{Median}\,\mathrm{BNS}\,\mathrm{Range}\,\mathrm{[Mpc]}$')
#pyplot.legend(handles=(l2,l1,l3), title=r'$\mathrm{Hourly}\,\mathrm{median}$', framealpha=1)

pyplot.grid()
fig.tight_layout()
pyplot.savefig(imgpath + "range_hourly_median.pdf")
