##^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Lance Simms, Lawrence Livermore National Laboratory (2011)^
#NAME:
#  TestSolarPanelIllumination
#PURPOSE:
#  To test the shadowing functions used for the CXBN solar panels
#
###############################################################################################
import os
execfile(os.path.expanduser('~')+'/Desktop/Software/Python/CZTCubeSat/CZTCubeSatSetup.py')

import ephem
from datetime import *
from CXBN_Utilities import *

# Main routine if we are called as a script
if __name__ == "__main__":

  #Create a satellite object
  cxbn = CubeSat()

  #Create an instance of the constant object
  c = c()

  #Set up angles for looping through
  ChangeElevation = 1
  ThisElevation   = 2*pi/20
  ChangeAzimuth   = 0
  ThisAzimuth     = 1*pi/20
  r_sun_b   = vec3()

  #Only makes sense to go 0 to 180 for theta
  if ChangeElevation == 1: NumAngles = 180
  if ChangeAzimuth == 1: NumAngles = 360
  Angles = arange(NumAngles)

  #Now declare some storage
  I_minus_y_arr = zeros(NumAngles, dtype=float32)
  I_plus_y_arr  = zeros(NumAngles, dtype=float32)
  I_minus_x_arr = zeros(NumAngles, dtype=float32)
  I_plus_x_arr  = zeros(NumAngles, dtype=float32)

  #Now loop through the angles
  for i in Angles:

    #Get this vector
    if ChangeElevation == 1:
      ThisElevation = i*pi/180.
    if ChangeAzimuth == 1:
      ThisAzimuth = i*pi/180.

    r_sun_b.x     = sin(ThisElevation)*cos(ThisAzimuth)
    r_sun_b.y     = sin(ThisElevation)*sin(ThisAzimuth)
    r_sun_b.z     = cos(ThisElevation)

    #Now get the fluxes on each of the solar panels
    plus_x_i, minus_x_i, plus_y_i, minus_y_i = getSolarPanelIllumination(r_sun_b, cxbn)

    I_plus_x_arr[i]  = plus_x_i
    I_minus_x_arr[i] = minus_x_i
    I_plus_y_arr[i]  = plus_y_i
    I_minus_y_arr[i] = minus_y_i


#Plot the four
mplot.figure(0)
mplot.clf()
mplot.plot(I_minus_x_arr, label='-x')
mplot.plot(I_plus_x_arr, label='+x')
mplot.legend()

mplot.figure(1)
mplot.clf()
mplot.plot(I_minus_y_arr, label='-y')
mplot.plot(I_plus_y_arr, label='+y')
mplot.legend()

