コード例 #1
0
ファイル: stereonet.py プロジェクト: davenquinn/Attitude
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))
コード例 #2
0
ファイル: stereonet.py プロジェクト: davenquinn/Attitude
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))
コード例 #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)
コード例 #4
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)
コード例 #5
0
ファイル: stereonet.py プロジェクト: davenquinn/Attitude
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))
コード例 #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)
コード例 #7
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)
コード例 #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])
コード例 #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])
コード例 #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])
コード例 #11
0
ファイル: rotations.py プロジェクト: davenquinn/Attitude
def to_stereonet(lon,lat):
    x,y,z = stereonet_math.sph2cart(lon,lat)
    return stereonet_math.cart2sph(-z,x,y)
コード例 #12
0
ファイル: rotations.py プロジェクト: davenquinn/Attitude
def from_stereonet(lon,lat):
    x,y,z = stereonet_math.sph2cart(lon,lat)
    return stereonet_math.cart2sph(y,z,-x)
コード例 #13
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])
コード例 #14
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])
コード例 #15
0
 def test_cart2sph(self):
     for (x,y,z), (lon, lat) in self.data:
         assert np.allclose(smath.cart2sph(x, y, z), [lon, lat])
コード例 #16
0
ファイル: test_analysis.py プロジェクト: ivn888/mplstereonet
 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)
コード例 #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)