示例#1
0
 def cos_distance(self, strike1, dip1, strike2, dip2):
     """Angular distance betwen the poles of two planes."""
     xyz1 = sph2cart(*mplstereonet.pole(strike1, dip1))
     xyz2 = sph2cart(*mplstereonet.pole(strike2, dip2))
     r1, r2 = np.linalg.norm(xyz1), np.linalg.norm(xyz2)
     dot = np.dot(np.squeeze(xyz1), np.squeeze(xyz2)) / r1 / r2
     return np.abs(np.degrees(np.arccos(dot)))
示例#2
0
 def cos_distance(self, strike1, dip1, strike2, dip2):
     """Angular distance betwen the poles of two planes."""
     xyz1 = sph2cart(*mplstereonet.pole(strike1, dip1))
     xyz2 = sph2cart(*mplstereonet.pole(strike2, dip2))
     r1, r2 = np.linalg.norm(xyz1), np.linalg.norm(xyz2)
     dot = np.dot(np.squeeze(xyz1), np.squeeze(xyz2)) / r1 / r2
     return np.abs(np.degrees(np.arccos(dot)))
 def test_cos_distance(self):
     for lon in range(0, 370, 10):
         for lat in range(-90, 100, 10):
             lon1, lat1 = np.radians([lon, lat])
             lon2, lat2 = smath.antipode(lon1, lat1)
             xyz1 = smath.sph2cart(lon1, lat1)
             xyz2 = smath.sph2cart(lon2, lat2)
             mag = np.linalg.norm(np.cross(xyz1, xyz2))
             assert np.allclose(0, mag)
示例#4
0
 def test_cos_distance(self):
     for lon in range(0, 370, 10):
         for lat in range(-90, 100, 10):
             lon1, lat1 = np.radians([lon, lat])
             lon2, lat2 = smath.antipode(lon1, lat1)
             xyz1 = smath.sph2cart(lon1, lat1)
             xyz2 = smath.sph2cart(lon2, lat2)
             mag = np.linalg.norm(np.cross(xyz1, xyz2))
             assert np.allclose(0, mag)
示例#5
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)
示例#7
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)
示例#9
0
 def compare_strikedip(self, strike1, dip1, strike2, dip2):
     """Avoids ambiguities in strike/dip convention when dip is 0 or 90."""
     convert = lambda a, b: sph2cart(*mplstereonet.pole(a, b))
     x1, y1, z1 = convert(strike1, dip1)
     x2, y2, z2 = convert(strike2, dip2)
     rtol, atol = 1e-7, 1e-7
     try:
         assert np.allclose([x1, y1, z1], [x2, y2, z2], rtol, atol)
     except AssertionError:
         # Antipode is also acceptable in this case....
         assert np.allclose([x1, y1, z1], [-x2, -y2, -z2], rtol, atol)
示例#10
0
 def compare_strikedip(self, strike1, dip1, strike2, dip2):
     """Avoids ambiguities in strike/dip convention when dip is 0 or 90."""
     convert = lambda a, b: sph2cart(*mplstereonet.pole(a, b))
     x1, y1, z1 = convert(strike1, dip1)
     x2, y2, z2 = convert(strike2, dip2)
     rtol, atol = 1e-7, 1e-7
     try:
         assert np.allclose([x1, y1, z1], [x2, y2, z2], rtol, atol)
     except AssertionError:
         # Antipode is also acceptable in this case....
         assert np.allclose([x1, y1, z1], [-x2, -y2, -z2], rtol, atol)
示例#11
0
 def compare_plungebearing(self, plunge1, azi1, plunge2, azi2):
     """Avoids ambiguities in plunge/bearing convention when dip is 0 or 90."""
     convert = lambda a, b: sph2cart(*mplstereonet.line(a, b))
     x1, y1, z1 = convert(plunge1, azi1)
     x2, y2, z2 = convert(plunge2, azi2)
     rtol, atol = 1e-7, 1e-7
     try:
         assert np.allclose([x1, y1, z1], [x2, y2, z2], rtol, atol)
     except AssertionError:
         # Antipode is also acceptable in this case....
         assert np.allclose([x1, y1, z1], [-x2, -y2, -z2], rtol, atol)
示例#12
0
 def compare_plungebearing(self, plunge1, azi1, plunge2, azi2):
     """Avoids ambiguities in plunge/bearing convention when dip is 0 or 90."""
     convert = lambda a, b: sph2cart(*mplstereonet.line(a, b))
     x1, y1, z1 = convert(plunge1, azi1)
     x2, y2, z2 = convert(plunge2, azi2)
     rtol, atol = 1e-7, 1e-7
     try:
         assert np.allclose([x1, y1, z1], [x2, y2, z2], rtol, atol)
     except AssertionError:
         # Antipode is also acceptable in this case....
         assert np.allclose([x1, y1, z1], [-x2, -y2, -z2], rtol, atol)
示例#13
0
    def pdf(coords):
        lon,lat = coords

        I = lat
        D = lon# + N.pi/2
        #D,I = _rotate(N.degrees(D),N.degrees(I),90)

        # Bingham is given in spherical coordinates of inclination
        # and declination in radians

        # From USGS bingham statistics reference

        xhat = N.array(sph2cart(lon,lat)).T

        #return F*expm(dot(xhat.T, M, N.diag(Z), M.T, xhat))

        return 1/(F*N.exp(dot(xhat.T, M, N.diag(Z), M.T, xhat)))
示例#14
0
def sph2cart(lat,lon):
    _ = stereonet_math.sph2cart(lat,lon)
    #val = N.array(_).flatten()
    val = N.roll(_,-1)
    val[:-1] *= -1
    return val
示例#15
0
 def vec(latlon):
     lat, lon = latlon
     _ = M.sph2cart(lat, lon)
     val = N.array(_).flatten()
     val = N.roll(val,-1)
     return val * _trans_arr
示例#16
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])
示例#17
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])
示例#18
0
 def test_sph2cart(self):
     for (x, y, z), (lon, lat) in self.data:
         assert np.allclose(smath.sph2cart(lon, lat), [x, y, z])
示例#19
0
def compare_lonlat(lon1, lat1, lon2, lat2):
    """Avoid ambiguities in strike/dip or lon/lat conventions."""
    x1, y1, z1 = smath.sph2cart(lon1, lat1)
    x2, y2, z2 = smath.sph2cart(lon2, lat2)
    assert np.allclose([x1, y1, z1], [x2, y2, z2], atol=1e-7)
示例#20
0
def compare_lonlat(lon1, lat1, lon2, lat2):
    """Avoid ambiguities in strike/dip or lon/lat conventions."""
    x1, y1, z1 = smath.sph2cart(lon1, lat1)
    x2, y2, z2 = smath.sph2cart(lon2, lat2)
    assert np.allclose([x1, y1, z1], [x2, y2, z2], atol=1e-7)
示例#21
0
def to_stereonet(lon,lat):
    x,y,z = stereonet_math.sph2cart(lon,lat)
    return stereonet_math.cart2sph(-z,x,y)
示例#22
0
def from_stereonet(lon,lat):
    x,y,z = stereonet_math.sph2cart(lon,lat)
    return stereonet_math.cart2sph(y,z,-x)
示例#23
0
 def test_sph2cart(self):
     for (x,y,z), (lon, lat) in self.data:
         assert np.allclose(smath.sph2cart(lon, lat), [x, y, z])
示例#24
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])
示例#25
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])