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)
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_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 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)
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)
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)))
def sph2cart(lat,lon): _ = stereonet_math.sph2cart(lat,lon) #val = N.array(_).flatten() val = N.roll(_,-1) val[:-1] *= -1 return val
def vec(latlon): lat, lon = latlon _ = M.sph2cart(lat, lon) val = N.array(_).flatten() val = N.roll(val,-1) return val * _trans_arr
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_sph2cart(self): for (x, y, z), (lon, lat) in self.data: assert np.allclose(smath.sph2cart(lon, lat), [x, y, z])
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)
def to_stereonet(lon,lat): x,y,z = stereonet_math.sph2cart(lon,lat) return stereonet_math.cart2sph(-z,x,y)
def from_stereonet(lon,lat): x,y,z = stereonet_math.sph2cart(lon,lat) return stereonet_math.cart2sph(y,z,-x)
def test_sph2cart(self): for (x,y,z), (lon, lat) in self.data: assert np.allclose(smath.sph2cart(lon, lat), [x, y, z])
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])