#PURPOSE:
#
#To Plot 1/f noise in the hybrid CMOS detectors
#
execfile('/afs/slac/u/ki/lances/python/python_HxRG/HxRG_Setup.py')
execfile('/afs/slac/u/ki/lances/python/ThesisPlotSettings.py')
from ReadNoise import *

FitsFileName = '/nfs/slac/g/ki/ki04/lances/H2RG-001/ASIC/08Dec16/Dark/Dark_Gain4_8ADC_20.00V_100_H2RG_SIPIN_100_Reads_Dec16_2008_19_16_35.fits'

CDSMap, BinsCor, N, FWHM, HalfMax, StdDev = ReadNoise('H2RG-001', 'ASIC', 1, 'H2RG_001_ASICSpatialReadNoiseFiles100Reads_20V_110K.txt', TvFlag=0)

MeanRows  = mean(CDSMap, axis=1)
NumSamp   = size(MeanRows)
SampInt   = 0.0052                             #Time of row is 0.0052 seconds
SampTimes = arange(NumSamp)*SampInt            #Times of sampling
FSpac     = 1./(NumSamp*SampInt)               #Frequency Spacing
KVals     = FSpac*(-NumSamp/2+arange(NumSamp)) #KVals for full FFT
KValsReal = FSpac*arange(NumSamp/2+1)          #KVals for real FFT

mplot.figure(0)
mplot.clf()
mplot.loglog(KValsReal, rfft(MeanRows).real**2)
mplot.xlim(0.1, 100)
mplot.ylim(0.01, 1e7)
mplot.xlabel(r'\textbf{Log Frequency (Hz)}')
mplot.ylabel(r'\textbf{Log Power Spectral Density}')
mplot.figtext(0.2, 0.30,  r'\textbf{Temp = 100 K}', size=13)
mplot.figtext(0.2, 0.24,  r'\textbf{$V_{SUB}$ = 20 V}', size=13) 
mplot.savefig('/nfs/slac/g/ki/ki04/lances/LSST/KPNO/Latex/Thesis/ReadNoise/Figures/PowerSpectralDensityOfReadNoise.png')
mplot.savefig('/nfs/slac/g/ki/ki04/lances/LSST/KPNO/Latex/Thesis/ReadNoise/Figures/PowerSpectralDensityOfReadNoise.eps')
