#PURPOSE:
#
#To plot the offset of a semi-permanent spot in the HxRG detectors as 
#a function of time.  The values will simply be held here in the file 
#as arrays:
#
#INPUTS:
#     DetectorName: string
#        The name of the detector ('H2RG-32-147' or 'H2RG-32-029')
#
#THESIS PLOT:
#  run PersistenceScripts/PlotPermaSpotVsTime.py 'H2RG-32-029'
#
execfile('/afs/slac/u/ki/lances/python/python_HxRG/HxRG_Setup.py')
from HxRG_Class import *
from pylab import *
from matplotlib.finance import quotes_historical_yahoo
from matplotlib.dates import YearLocator, MonthLocator, DateFormatter
import datetime

#Set Up for plotting
PlotFile='/afs/slac/u/ki/lances/python/ThesisPlotSettingsBigFont.py'
if os.path.exists(PlotFile) : execfile(PlotFile)

#Get the filename and options from command line
DetectorName = sys.argv[1]

if DetectorName == 'H2RG-32-029':
  PlotDir = '/nfs/slac/g/ki/ki04/lances/SNAPImages/SpotHistory/'
  Date1 = datetime.date(2007, 12, 12); ADU1 = 1100
  Date2 = datetime.date(2007, 12, 21); ADU2 = 1100
  Date3 = datetime.date(2008, 1,  29); ADU3 = 920
  Date4 = datetime.date(2008, 3,  21); ADU4 = 600
  Date5 = datetime.date(2008, 5,  8 ); ADU5 = 100
  Date6 = datetime.date(2008, 5,  9 ); ADU6 = 0
  Dates = date2num([Date1, Date2, Date3, Date4, Date5, Date6])
  ADUs  = [ADU1, ADU2, ADU3, ADU4, ADU5, ADU6]
else:
  PlotDir = '/nfs/slac/g/ki/ki04/lances/H2RG-32-147/Plots/PermaSpot/'
  Date1 = datetime.date(2007, 12, 18); ADU1 = 500
  Date2 = datetime.date(2008,  2,  1); ADU2 = 500
  Date3 = datetime.date(2008,  3, 21); ADU3 = 500
  Dates = date2num([Date1, Date2, Date3])
  ADUs  = [ADU1, ADU2, ADU3]

years    = YearLocator()   # every year
months   = MonthLocator()  # every month
yearsFmt = DateFormatter('%Y') 

mplot.clf()
ax = subplot(111)
plot_date(Dates, ADUs)
ax.xaxis.set_major_locator(months)
FR = max(ADUs)-0
ylim([0, max(ADUs)+0.1*FR])
mplot.xlabel(r'\textbf{Date}', fontsize=16)
mplot.ylabel(r'\textbf{ADU Above Background}', fontsize=16)
#mplot.twinx(ax=ax)
#mplot.ylabel(r'\textbf{e$^{-}$ Above Background (approx.)}')
#ylim(0, 5.85*(max(ADUs)+0.1*FR))
mplot.savefig(PlotDir+'SpotHistory_'+DetectorName+'.png')
