# Path: skyfield/constants.py
# AU_M = 149597870700             # per IAU 2012 Resolution B2
# AU_KM = 149597870.700
# ASEC360 = 1296000.0
# DAY_S = 86400.0
# ASEC2RAD = 4.848136811095359935899141e-6
# DEG2RAD = 0.017453292519943296
# RAD2DEG = 57.295779513082321
# C = 299792458.0                            # m/s
# ANGVEL = 7.2921150e-5           # radians/s
# ERAD = 6378136.6                # meters
# IERS_2010_INVERSE_EARTH_FLATTENING = 298.25642
# GS = 1.32712440017987e+20
# T0 = 2451545.0
# B1950 = 2433282.4235
# C_AUDAY = C * DAY_S / AU_M
# 
# Path: skyfield/data/spice.py

# 
# Path: skyfield/functions.py
# def mxm(M1, M2):
#     """Matrix times matrix: multiply two NxN matrices."""
#     return einsum('ij...,jk...->ik...', M1, M2)
# 
# def rot_x(theta):
#     c = cos(theta)
#     s = sin(theta)
#     zero = theta * 0.0
#     one = zero + 1.0
#     return array(((one, zero, zero), (zero, c, -s), (zero, s, c)))
# 
# def rot_z(theta):
#     c = cos(theta)
#     s = sin(theta)
#     zero = theta * 0.0
#     one = zero + 1.0
#     return array(((c, -s, zero), (s, c, zero), (zero, zero, one)))


from numpy import array
from .constants import ANGVEL, ASEC2RAD, DAY_S, tau
from .data.spice import inertial_frames as _inertial_frames
from .functions import mxm, rot_x, rot_z
    # Include second-order corrections to diagonal elements.

    xx = 1.0 - 0.5 * (yx * yx + zx * zx)
    yy = 1.0 - 0.5 * (yx * yx + zy * zy)
    zz = 1.0 - 0.5 * (zy * zy + zx * zx)

    return array(((xx, xy, xz), (yx, yy, yz), (zx, zy, zz)))

ICRS_to_J2000 = build_matrix()
del build_matrix

_identity = array([(1,0,0), (0,1,0), (0,0,1)])

class ICRS(object):
    """The International Coordinate Reference System (ICRS).

    The ICRS is a permanent reference frame which has replaced J2000,
    with which its axes agree to within 0.02 arcseconds (closer than the
    precision of J2000 itself).  The ICRS also supersedes older
    equinox-based systems like B1900 and B1950.

    """
    @staticmethod
    def rotation_at(t):
        return _identity

def build_ecliptic_matrix(t):
    # Build the matrix to rotate an ICRF vector into ecliptic coordinates.
    _, d_eps = t._nutation_angles_radians
    true_obliquity = t._mean_obliquity_radians + d_eps

# Path: skyfield/constants.py
# AU_M = 149597870700             # per IAU 2012 Resolution B2
# AU_KM = 149597870.700
# ASEC360 = 1296000.0
# DAY_S = 86400.0
# ASEC2RAD = 4.848136811095359935899141e-6
# DEG2RAD = 0.017453292519943296
# RAD2DEG = 57.295779513082321
# C = 299792458.0                            # m/s
# ANGVEL = 7.2921150e-5           # radians/s
# ERAD = 6378136.6                # meters
# IERS_2010_INVERSE_EARTH_FLATTENING = 298.25642
# GS = 1.32712440017987e+20
# T0 = 2451545.0
# B1950 = 2433282.4235
# C_AUDAY = C * DAY_S / AU_M
# 
# Path: skyfield/data/spice.py

# 
# Path: skyfield/functions.py
# def mxm(M1, M2):
#     """Matrix times matrix: multiply two NxN matrices."""
#     return einsum('ij...,jk...->ik...', M1, M2)
# 
# def rot_x(theta):
#     c = cos(theta)
#     s = sin(theta)
#     zero = theta * 0.0
#     one = zero + 1.0
#     return array(((one, zero, zero), (zero, c, -s), (zero, s, c)))
# 
# def rot_z(theta):
#     c = cos(theta)
#     s = sin(theta)
#     zero = theta * 0.0
#     one = zero + 1.0
#     return array(((c, -s, zero), (s, c, zero), (zero, zero, one)))


# Path: skyfield/framelib.py
from numpy import array
from .constants import ANGVEL, ASEC2RAD, DAY_S, tau
from .data.spice import inertial_frames as _inertial_frames
from .functions import mxm, rot_x, rot_z

    # Include second-order corrections to diagonal elements.

    xx = 1.0 - 0.5 * (yx * yx + zx * zx)
    yy = 1.0 - 0.5 * (yx * yx + zy * zy)
    zz = 1.0 - 0.5 * (zy * zy + zx * zx)

    return array(((xx, xy, xz), (yx, yy, yz), (zx, zy, zz)))

ICRS_to_J2000 = build_matrix()
del build_matrix

_identity = array([(1,0,0), (0,1,0), (0,0,1)])

class ICRS(object):
    """The International Coordinate Reference System (ICRS).

    The ICRS is a permanent reference frame which has replaced J2000,
    with which its axes agree to within 0.02 arcseconds (closer than the
    precision of J2000 itself).  The ICRS also supersedes older
    equinox-based systems like B1900 and B1950.

    """
    @staticmethod
    def rotation_at(t):
        return _identity

def build_ecliptic_matrix(t):
    # Build the matrix to rotate an ICRF vector into ecliptic coordinates.
    _, d_eps = t._nutation_angles_radians
    true_obliquity = t._mean_obliquity_radians + d_eps

    return mxm(rot_x(- true_obliquity), t.M)