# coding=utf-8
# Filename: astro.py
# pylint: disable=C0103
# pragma: no cover
"""
Astro utils.
"""
from __future__ import division, absolute_import, print_function


from astropy.units import degree
from astropy.coordinates import (Latitude, Longitude,
                                 EarthLocation, AltAz, SkyCoord)

from km3pipe.constants import orca_longitude, orca_latitude, orca_height

__author__ = "Moritz Lotze"
__copyright__ = "Copyright 2016, Tamas Gal and the KM3NeT collaboration."
__credits__ = []
__license__ = "MIT"
__maintainer__ = "Moritz Lotze"
__email__ = "mlotze@km3net.de"
__status__ = "Development"


orca_loc = EarthLocation.from_geodetic(
    Longitude(orca_longitude * degree),
    Latitude(orca_latitude * degree),
    height=orca_height
)


def to_frame(times, zeniths, azimuths, frame='galactic'):
    """Tranform from the Detector frame to anything else.

    Parameters:
    -----------
    frame: str [default: 'galactic']
        The reference frame to transform to (needs to be known to astropy)

    """
    zeniths *= degree
    azimuths *= degree
    orca_frame = AltAz(location=orca_loc, obstime=times)
    coords = SkyCoord(zeniths, azimuths, frame=orca_frame)
    return coords.transform_to(frame)

@@ -159,16 +159,34 @@
 nction%0A%0A
+import numpy as np
 %0Afrom as
@@ -210,16 +210,21 @@
 t degree
+, rad
 %0Afrom as
@@ -807,17 +807,16 @@
 time
-s
 , zenith
 s, a
@@ -807,25 +807,24 @@
 time, zenith
-s
 , azimuths, 
@@ -812,33 +812,32 @@
  zenith, azimuth
-s
 , frame='galacti
@@ -838,16 +838,26 @@
 alactic'
+, unit=rad
 ):%0A    %22
@@ -1070,26 +1070,47 @@
 %0A   
+ altitude = (0.5*np.pi -
  zenith
-s *= degree
+) * unit
 %0A   
@@ -1121,19 +1121,16 @@
 muth
-s
  *= 
-degree
+unit
 %0A   
@@ -1180,17 +1180,16 @@
 ime=time
-s
 )%0A    co
@@ -1208,15 +1208,16 @@
 ord(
-zeniths
+altitude
 , az
@@ -1221,17 +1221,16 @@
  azimuth
-s
 , frame=

FIX misnomer: use actual altitude instead of zenith