# Path: tests/data.py

# 
# Path: blimpy/ephemeris/compute_lst.py
# def compute_lst(wf):
#     """ Compute LST for observation
# 
#     Computes local sidereal time (LST) for the observation, using SLALIB.
# 
#     Args:
#         wf (bl.Waterfall): blimpy Waterfall object.
#     """
#     if wf.header['telescope_id'] == 6:
#         wf.coords = gbt_coords
#     elif wf.header['telescope_id'] == 4:
#         wf.coords = parkes_coords
#     else:
#         raise RuntimeError("Currently only Parkes and GBT supported")
#     if HAS_SLALIB:
#         # dut1 = (0.2 /3600.0) * np.pi/12.0
#         dut1 = 0.0
#         mjd = wf.header['tstart']
#         tellong = np.deg2rad(wf.coords[1])
#         last = s.sla_gmst(mjd) - tellong + s.sla_eqeqx(mjd) + dut1
#         # lmst = s.sla_gmst(mjd) - tellong
#         if last < 0.0: last = last + 2.0 * np.pi
#         return last
#     else:
#         raise RuntimeError("This method requires pySLALIB")
# 
# Path: blimpy/ephemeris/compute_lsrk.py
# def compute_lsrk(wf):
#     """ Computes the LSR in km/s
# 
#     Computes the Local standard of rest kinematic using the time (MJD),
#     RA and DEC of the observation to compute along with the telescope location.
#     Requires pyslalib
# 
#     Args:
#         wf (bl.Waterfall): Waterfall object for which to compute LSR
#     """
#     ra = Angle(wf.header['src_raj'], unit='hourangle')
#     dec = Angle(wf.header['src_dej'], unit='degree')
#     mjdd = wf.header['tstart']
#     rarad = ra.to('radian').value
#     dcrad = dec.to('radian').value
#     last = compute_lst(wf)
#     tellat = np.deg2rad(wf.coords[0])
#     tellong = np.deg2rad(wf.coords[1])
# 
#     # convert star position to vector
#     starvect = s.sla_dcs2c(rarad, dcrad)
# 
#     # velocity component in ra,dec due to Earth rotation
#     Rgeo = s.sla_rverot(tellat, rarad, dcrad, last)
# 
#     # get Barycentric and heliocentric velocity and position of the Earth.
#     evp = s.sla_evp(mjdd, 2000.0)
#     dvb = evp[0]  # barycentric velocity vector, in AU/sec
#     dpb = evp[1]  # barycentric position vector, in AU
#     dvh = evp[2]  # heliocentric velocity vector, in AU/sec
#     dph = evp[3]  # heliocentric position vector, in AU
# 
#     # dot product of vector to object and heliocentric velocity
#     # convert AU/sec to km/sec
#     vcorhelio = -s.sla_dvdv(starvect, dvh) * 149.597870e6
#     vcorbary = -s.sla_dvdv(starvect, dvb) * 149.597870e6
# 
#     # rvlsrd is velocity component in ra,dec direction due to the Sun's
#     # motion with respect to the "dynamical" local standard of rest
#     rvlsrd = s.sla_rvlsrd(rarad, dcrad)
# 
#     # rvlsrk is velocity component in ra,dec direction due to i
#     # the Sun's motion w.r.t the "kinematic" local standard of rest
#     rvlsrk = s.sla_rvlsrk(rarad, dcrad)
# 
#     # rvgalc is velocity component in ra,dec direction due to
#     # the rotation of the Galaxy.
#     rvgalc = s.sla_rvgalc(rarad, dcrad)
#     totalhelio = Rgeo + vcorhelio
#     totalbary = Rgeo + vcorbary
#     totallsrk = totalhelio + rvlsrk
#     totalgal = totalbary + rvlsrd + rvgalc
# 
#     return totallsrk


import blimpy as bl
import numpy as np
import pylab as plt
from pprint import pprint
from tests.data import voyager_fil, voyager_h5
from blimpy.ephemeris import compute_lst, compute_lsrk



def test_compute_lst():
    """ Load Voyager dataset and test plotting """
    print("Loading HDF5 data with Waterfall()..."),
    a = bl.Waterfall(voyager_h5)
    print(compute_lst(a))


def test_compute_lsrk():

# Path: tests/data.py

# 
# Path: blimpy/ephemeris/compute_lst.py
# def compute_lst(wf):
#     """ Compute LST for observation
# 
#     Computes local sidereal time (LST) for the observation, using SLALIB.
# 
#     Args:
#         wf (bl.Waterfall): blimpy Waterfall object.
#     """
#     if wf.header['telescope_id'] == 6:
#         wf.coords = gbt_coords
#     elif wf.header['telescope_id'] == 4:
#         wf.coords = parkes_coords
#     else:
#         raise RuntimeError("Currently only Parkes and GBT supported")
#     if HAS_SLALIB:
#         # dut1 = (0.2 /3600.0) * np.pi/12.0
#         dut1 = 0.0
#         mjd = wf.header['tstart']
#         tellong = np.deg2rad(wf.coords[1])
#         last = s.sla_gmst(mjd) - tellong + s.sla_eqeqx(mjd) + dut1
#         # lmst = s.sla_gmst(mjd) - tellong
#         if last < 0.0: last = last + 2.0 * np.pi
#         return last
#     else:
#         raise RuntimeError("This method requires pySLALIB")
# 
# Path: blimpy/ephemeris/compute_lsrk.py
# def compute_lsrk(wf):
#     """ Computes the LSR in km/s
# 
#     Computes the Local standard of rest kinematic using the time (MJD),
#     RA and DEC of the observation to compute along with the telescope location.
#     Requires pyslalib
# 
#     Args:
#         wf (bl.Waterfall): Waterfall object for which to compute LSR
#     """
#     ra = Angle(wf.header['src_raj'], unit='hourangle')
#     dec = Angle(wf.header['src_dej'], unit='degree')
#     mjdd = wf.header['tstart']
#     rarad = ra.to('radian').value
#     dcrad = dec.to('radian').value
#     last = compute_lst(wf)
#     tellat = np.deg2rad(wf.coords[0])
#     tellong = np.deg2rad(wf.coords[1])
# 
#     # convert star position to vector
#     starvect = s.sla_dcs2c(rarad, dcrad)
# 
#     # velocity component in ra,dec due to Earth rotation
#     Rgeo = s.sla_rverot(tellat, rarad, dcrad, last)
# 
#     # get Barycentric and heliocentric velocity and position of the Earth.
#     evp = s.sla_evp(mjdd, 2000.0)
#     dvb = evp[0]  # barycentric velocity vector, in AU/sec
#     dpb = evp[1]  # barycentric position vector, in AU
#     dvh = evp[2]  # heliocentric velocity vector, in AU/sec
#     dph = evp[3]  # heliocentric position vector, in AU
# 
#     # dot product of vector to object and heliocentric velocity
#     # convert AU/sec to km/sec
#     vcorhelio = -s.sla_dvdv(starvect, dvh) * 149.597870e6
#     vcorbary = -s.sla_dvdv(starvect, dvb) * 149.597870e6
# 
#     # rvlsrd is velocity component in ra,dec direction due to the Sun's
#     # motion with respect to the "dynamical" local standard of rest
#     rvlsrd = s.sla_rvlsrd(rarad, dcrad)
# 
#     # rvlsrk is velocity component in ra,dec direction due to i
#     # the Sun's motion w.r.t the "kinematic" local standard of rest
#     rvlsrk = s.sla_rvlsrk(rarad, dcrad)
# 
#     # rvgalc is velocity component in ra,dec direction due to
#     # the rotation of the Galaxy.
#     rvgalc = s.sla_rvgalc(rarad, dcrad)
#     totalhelio = Rgeo + vcorhelio
#     totalbary = Rgeo + vcorbary
#     totallsrk = totalhelio + rvlsrk
#     totalgal = totalbary + rvlsrd + rvgalc
# 
#     return totallsrk


# Path: tests/test_ephemeris.py
import blimpy as bl
import numpy as np
import pylab as plt
from pprint import pprint
from tests.data import voyager_fil, voyager_h5
from blimpy.ephemeris import compute_lst, compute_lsrk




def test_compute_lst():
    """ Load Voyager dataset and test plotting """
    print("Loading HDF5 data with Waterfall()..."),
    a = bl.Waterfall(voyager_h5)
    print(compute_lst(a))


def test_compute_lsrk():

    a = bl.Waterfall(voyager_h5)