#TestAngularScan.py              Lance Simms, LLNL 2010
#
#PURPOSE:
#  To determine the optimum way to scan the sky in angle.  This will depend on 
#  the incremental change in angle that is desired. 
#
#KEYWORDS:
#  AngSep: float
#    The minimum change in angle needed while scanning the sky 
#
#EXAMPLES
#
########

import os
execfile(os.path.expanduser('~')+'/Desktop/Software/Python/CZTCubeSat/CZTCubeSatSetup.py')

import ephem
from datetime import *

##PARSE KEYWORDS
keywords    = ['AngSep=']

#DEFAULT VALUES FOR KEYWORDS
AngeSep     = 1

#NOW PARSE KEYWORDS
opts, extraparams = getopt.getopt(sys.argv[1:],'',keywords)
for o,p in opts:
  if o in ['--AngSep']:
    DateTime = p

#Set up the previous RA and DEC for comparison
PreviousRA      = 0
PreviousRA_Rad  = PreviousRA*pi/180
PreviousDEC     = -90
PreviousDEC_Rad = PreviousDEC*pi/180
NumAnglesTotal  = 0
 
#Now go through and calculate these angles rotated to the sun pointed frame  
for DEC in (arange(181)-90): 
  
  #Get the declination in Radians
  ThisDEC_Rad = DEC*pi/180
   
  #Number of RAs
  NumRAs = floor(359*cos(ThisDEC_Rad)+1)
  RAArr  = arange(NumRAs)*360./NumRAs
  NumAnglesTotal += NumRAs
  print "Num RAs" + str(NumRAs)
 
  #Now find all of the objects within FOV_Deg degrees of pointing
  for RA in RAArr:
  
    #Get this right ascension in Radians    
    ThisRA_Rad = RA*pi/180

    #Determine separation between CZT Pointing and Object
    ThisAngSep  = Astro_Angular_Separation(ThisRA_Rad, ThisDEC_Rad, \
                    PreviousRA_Rad, PreviousDEC_Rad) 
    ThisAngSep  = (180/pi)*ThisAngSep
   
    #Get the old RA, DEC
    PreviousRA      = RA
    PreviousRA_Rad  = ThisRA_Rad
    PreviousDEC     = DEC 
    PreviousDEC_Rad = ThisDEC_Rad
  
    #print out the separation
    # print "Angular Separation :" + str(ThisAngSep)

  #pdb.set_trace() 
