# Path: attitude/geom/util.py
# def dot(*matrices):
#     return reduce(N.dot, matrices)
# 
# Path: attitude/error/ellipse.py
# def ellipse(center,covariance_matrix,level=1, n=1000):
#     """Returns error ellipse in slope-azimuth space"""
#     # singular value decomposition
#     U, s, rotation_matrix = N.linalg.svd(covariance_matrix)
#     # semi-axes (largest first)
# 
#     saxes = N.sqrt(s)*level ## If the _area_ of a 2s ellipse is twice that of a 1s ellipse
#     # If the _axes_ are supposed to be twice as long, then it should be N.sqrt(s)*width
# 
#     u = N.linspace(0, 2*N.pi, n)
#     data = N.column_stack((saxes[0]*N.cos(u), saxes[1]*N.sin(u)))
#     # rotate data
#     return N.dot(data, rotation_matrix)+ center


import numpy as N
from ..geom.util import dot
from ..error.ellipse import ellipse
from hashlib import sha1
class BaseOrientation(object):
    """
    Abstract class to define common methods used by
    other orientation classes (e.g. reconstructed
    orientations, pca orientations)
    """
    disabled = False

    def dip_direction(self, uncertainties=False):
        s,d = self.strike_dip()
        s+=90
        if uncertainties:
            return (s,d),self.errors()
        return (s,d)

    def gradient(self, uncertainties=False):
        return self.azimuth,self.slope

    def errors(self):
        return tuple(N.degrees(i) for i in self.standard_errors()[:2])

    @property
    def rotated_covariance(self):
        r = rotation(self.azimuth)
        return dot(r.T,self.covariance_matrix,r)

    def standard_errors(self):
        return N.sqrt(N.diagonal(self.rotated_covariance))

    def _ellipse(self,level):

# Path: attitude/geom/util.py
# def dot(*matrices):
#     return reduce(N.dot, matrices)
# 
# Path: attitude/error/ellipse.py
# def ellipse(center,covariance_matrix,level=1, n=1000):
#     """Returns error ellipse in slope-azimuth space"""
#     # singular value decomposition
#     U, s, rotation_matrix = N.linalg.svd(covariance_matrix)
#     # semi-axes (largest first)
# 
#     saxes = N.sqrt(s)*level ## If the _area_ of a 2s ellipse is twice that of a 1s ellipse
#     # If the _axes_ are supposed to be twice as long, then it should be N.sqrt(s)*width
# 
#     u = N.linspace(0, 2*N.pi, n)
#     data = N.column_stack((saxes[0]*N.cos(u), saxes[1]*N.sin(u)))
#     # rotate data
#     return N.dot(data, rotation_matrix)+ center


# Path: attitude/orientation/base.py
import numpy as N
from ..geom.util import dot
from ..error.ellipse import ellipse
from hashlib import sha1

class BaseOrientation(object):
    """
    Abstract class to define common methods used by
    other orientation classes (e.g. reconstructed
    orientations, pca orientations)
    """
    disabled = False

    def dip_direction(self, uncertainties=False):
        s,d = self.strike_dip()
        s+=90
        if uncertainties:
            return (s,d),self.errors()
        return (s,d)

    def gradient(self, uncertainties=False):
        return self.azimuth,self.slope

    def errors(self):
        return tuple(N.degrees(i) for i in self.standard_errors()[:2])

    @property
    def rotated_covariance(self):
        r = rotation(self.azimuth)
        return dot(r.T,self.covariance_matrix,r)

    def standard_errors(self):
        return N.sqrt(N.diagonal(self.rotated_covariance))

    def _ellipse(self,level):

        return ellipse(