# Path: attitude/geom/util.py
# def vector(*args):
#     """
#     A single vector in any coordinate basis,
#     as a numpy array.
#     """
#     return N.array(args)
# 
# def unit_vector(*args):
#     v = vector(*args)
#     return v/norm(v)
# 
# def dot(*matrices):
#     return reduce(N.dot, matrices)


import numpy as N
from mplstereonet import stereonet_math
from scipy.stats import chi2
from numpy.testing import assert_array_almost_equal
from .geom.util import vector, unit_vector, dot
    """
    Returns major axes of error ellipse or
    hyperbola, rescaled using chi2 test statistic
    """
    dof = len(cov_axes)
    x2t = chi2.ppf(confidence_level,dof)
    return N.sqrt(x2t*cov_axes)

def normal_errors(axes, covariance_matrix, **kwargs):
    """
    Currently assumes upper hemisphere of stereonet
    """
    level = kwargs.pop('level',1)
    traditional_layout = kwargs.pop('traditional_layout',True)
    d = N.diagonal(covariance_matrix)
    ell = ellipse(**kwargs)

    if axes[2,2] < 0:
        axes *= -1

    # Not sure where this factor comes from but it
    # seems to make things work better
    c1 = 2
    axis_lengths = d[:2]
    f = N.linalg.norm(
        ell*axis_lengths,axis=1)

    e0 = -ell.T*d[2]*c1
    e = N.vstack((e0,f))


# Path: attitude/geom/util.py
# def vector(*args):
#     """
#     A single vector in any coordinate basis,
#     as a numpy array.
#     """
#     return N.array(args)
# 
# def unit_vector(*args):
#     v = vector(*args)
#     return v/norm(v)
# 
# def dot(*matrices):
#     return reduce(N.dot, matrices)


# Path: attitude/stereonet.py
import numpy as N
from mplstereonet import stereonet_math
from scipy.stats import chi2
from numpy.testing import assert_array_almost_equal
from .geom.util import vector, unit_vector, dot

    """
    Returns major axes of error ellipse or
    hyperbola, rescaled using chi2 test statistic
    """
    dof = len(cov_axes)
    x2t = chi2.ppf(confidence_level,dof)
    return N.sqrt(x2t*cov_axes)

def normal_errors(axes, covariance_matrix, **kwargs):
    """
    Currently assumes upper hemisphere of stereonet
    """
    level = kwargs.pop('level',1)
    traditional_layout = kwargs.pop('traditional_layout',True)
    d = N.diagonal(covariance_matrix)
    ell = ellipse(**kwargs)

    if axes[2,2] < 0:
        axes *= -1

    # Not sure where this factor comes from but it
    # seems to make things work better
    c1 = 2
    axis_lengths = d[:2]
    f = N.linalg.norm(
        ell*axis_lengths,axis=1)

    e0 = -ell.T*d[2]*c1
    e = N.vstack((e0,f))


    _ = dot(e.T,axes).T