Example #1
0
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

    if traditional_layout:
        lon,lat = stereonet_math.cart2sph(_[2],_[0],-_[1])
    else:
        lon,lat = stereonet_math.cart2sph(-_[1],_[0],_[2])
    return list(zip(lon,lat))
Example #2
0
def error_ellipse(axes, covariance_matrix, **kwargs):
    level = kwargs.pop('level',1)
    traditional_layout = kwargs.pop('traditional_layout',True)

    d = N.sqrt(covariance_matrix)

    ell = ellipse(**kwargs)
    # Bundle of vectors surrounding nominal values
    bundle = dot(ell, d[:2])
    res = d[2]*level

    # Switch hemispheres if PCA is upside-down
    # Normal vector is always correctly fit
    if axes[2,2] > 0:
        res *= -1

    normal = vector(0,0,1)

    _ = normal + bundle

    if traditional_layout:
        lon,lat = stereonet_math.cart2sph(_[2],_[0],_[1])
    else:
        lon,lat = stereonet_math.cart2sph(-_[1],_[0],_[2])

    return list(zip(lon,lat))
Example #3
0
 def test_round_trip(self):
     for x in np.arange(-1, 1.1, 0.1):
         for y in np.arange(-1, 1.1, 0.1):
             for z in np.arange(-1, 1.1, 0.1):
                 if np.allclose([x, y, z], [0, 0, 0]):
                     continue
                 xyz2 = smath.sph2cart(*smath.cart2sph(x, y, z))
                 xyz2 /= np.linalg.norm(xyz2)
                 xyz1 = np.array([x, y, z]) / np.linalg.norm([x, y, z])
                 assert np.allclose(xyz1, xyz2)
 def test_round_trip(self):
     for x in np.arange(-1, 1.1, 0.1):
         for y in np.arange(-1, 1.1, 0.1):
             for z in np.arange(-1, 1.1, 0.1):
                 if np.allclose([x, y, z], [0, 0, 0]):
                     continue
                 xyz2 = smath.sph2cart(*smath.cart2sph(x, y, z))
                 xyz2 /= np.linalg.norm(xyz2)
                 xyz1 = np.array([x, y, z]) / np.linalg.norm([x, y, z])
                 assert np.allclose(xyz1, xyz2)
Example #5
0
def plane_errors(axes, covariance_matrix, sheet='upper',**kwargs):
    """
    kwargs:
    traditional_layout  boolean [True]
        Lay the stereonet out traditionally, with north at the pole of
        the diagram. The default is a more natural and intuitive visualization
        with vertical at the pole and the compass points of strike around the equator.
        Thus, longitude at the equator represents strike and latitude represents
        apparent dip at that azimuth.
    """

    level = kwargs.pop('level',1)
    traditional_layout = kwargs.pop('traditional_layout',True)

    d = N.sqrt(covariance_matrix)

    ell = ellipse(**kwargs)
    bundle = dot(ell, d[:2])
    res = d[2]*level

    # Switch hemispheres if PCA is upside-down
    # Normal vector is always correctly fit
    #if traditional_layout:
    #if axes[2,2] > 0:

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

    if sheet == 'upper':
        bundle += res
    elif sheet == 'lower':
        bundle -= res

    _ = dot(bundle,axes).T

    if traditional_layout:
        lon,lat = stereonet_math.cart2sph(_[2],_[0],_[1])
    else:
        lon,lat = stereonet_math.cart2sph(-_[1],_[0],_[2])

    return list(zip(lon,lat))
Example #6
0
    def test_offset_back_to_rake(self):
        for strike, dip, rake in self.data:
            # Displace the line perpendicular to the plane...
            line = smath.sph2cart(*smath.rake(strike, dip, rake))
            norm = smath.sph2cart(*smath.pole(strike, dip))
            line = np.array(line) + 0.5 * np.array(norm)

            # Project the "displaced" line back onto the plane...
            lon, lat = smath.cart2sph(*line)
            plunge, bearing = smath.geographic2plunge_bearing(lon, lat)
            newrake = smath.project_onto_plane(strike, dip, plunge, bearing)
            assert np.allclose(rake, newrake)
    def test_offset_back_to_rake(self):
        for strike, dip, rake in self.data:
            # Displace the line perpendicular to the plane...
            line = smath.sph2cart(*smath.rake(strike, dip, rake))
            norm = smath.sph2cart(*smath.pole(strike, dip))
            line = np.array(line) + 0.5 * np.array(norm)

            # Project the "displaced" line back onto the plane...
            lon, lat = smath.cart2sph(*line)
            plunge, bearing = smath.geographic2plunge_bearing(lon, lat)
            newrake = smath.project_onto_plane(strike, dip, plunge, bearing)
            assert np.allclose(rake, newrake)
Example #8
0
 def test_sph2cart_conversion_and_inverse(self):
     for _, (lon, lat) in self.data:
         x, y, z = smath.sph2cart(lon, lat)
         lon1, lat1 = smath.cart2sph(x, y, z)
         assert np.allclose([lon, lat], [lon1, lat1])
Example #9
0
 def test_cart2sph_conversion_and_inverse(self):
     for (x, y, z), _ in self.data:
         lon, lat = smath.cart2sph(x, y, z)
         x1, y1, z1 = smath.sph2cart(lon, lat)
         assert np.allclose([x, y, z], [x1, y1, z1])
Example #10
0
 def test_cart2sph(self):
     for (x, y, z), (lon, lat) in self.data:
         assert np.allclose(smath.cart2sph(x, y, z), [lon, lat])
Example #11
0
def to_stereonet(lon,lat):
    x,y,z = stereonet_math.sph2cart(lon,lat)
    return stereonet_math.cart2sph(-z,x,y)
Example #12
0
def from_stereonet(lon,lat):
    x,y,z = stereonet_math.sph2cart(lon,lat)
    return stereonet_math.cart2sph(y,z,-x)
 def test_sph2cart_conversion_and_inverse(self):
     for _, (lon, lat) in self.data:
         x,y,z = smath.sph2cart(lon, lat)
         lon1, lat1 = smath.cart2sph(x,y,z)
         assert np.allclose([lon, lat], [lon1, lat1])
 def test_cart2sph_conversion_and_inverse(self):
     for (x,y,z), _ in self.data:
         lon, lat = smath.cart2sph(x,y,z)
         x1, y1, z1 = smath.sph2cart(lon, lat)
         assert np.allclose([x,y,z], [x1, y1, z1])
 def test_cart2sph(self):
     for (x,y,z), (lon, lat) in self.data:
         assert np.allclose(smath.cart2sph(x, y, z), [lon, lat])
Example #16
0
 def test_cov_eig(self):
     x, y, z = 3 * [np.linspace(-1, 1, 10)]
     lon, lat = cart2sph(x, y, z)
     vals, vecs = mplstereonet.cov_eig(lon, lat)
     p = vecs[:,-1]
     assert np.allclose([p[0], p[0], p[0]], p)
Example #17
0
 def test_cov_eig(self):
     x, y, z = 3 * [np.linspace(-1, 1, 10)]
     lon, lat = cart2sph(x, y, z)
     vals, vecs = mplstereonet.cov_eig(lon, lat)
     p = vecs[:, -1]
     assert np.allclose([p[0], p[0], p[0]], p)