def __calc_t_i(P0, P1, lat, lon, proj): """ Calculate t_i distance. See Spudich and Chiou OFR 2015-1028. This is the distance measured normal to strike from the i-th segment. Values on the hanging-wall are positive and those on the foot-wall are negative. :param P0: Point object, representing the first top-edge vertex of a rupture quadrilateral. :param P1: Point object, representing the second top-edge vertex of a rupture quadrilateral. :param lat: A numpy array of latitudes. :param lon: A numpy array of longitudes. :param proj: An orthographic projection from openquake.hazardlib.geo.utils.get_orthographic_projection. :returns: Array of size N of distances (in km) from input points to rupture surface. """ # projected coordinates are in km p0x, p0y = proj(P0.x, P0.y) p1x, p1y = proj(P1.x, P1.y) # Unit vector pointing normal to strike t_i_hat = Vector(p1y - p0y, -(p1x - p0x), 0).norm() # Convert sites to Cartesian sx, sy = proj(lon, lat) sx1d = np.reshape(sx, (-1,)) sy1d = np.reshape(sy, (-1,)) # Vectors from P0 to sites r = np.zeros([len(sx1d), 2]) r[:, 0] = sx1d - p0x r[:, 1] = sy1d - p0y # Dot product gives t_i t_i = np.sum(t_i_hat.getArray()[0:2] * r, axis=1) shp = t_i.shape if len(shp) == 1: t_i.shape = (shp[0], 1) t_i = np.fliplr(t_i) return t_i
def __calc_u_i(P0, P1, lat, lon, proj): """ Calculate u_i distance. See Spudich and Chiou OFR 2015-1028. This is the distance along strike from the first vertex (P0) of the i-th segment. :param P0: Point object, representing the first top-edge vertex of a rupture quadrilateral. :param P1: Point object, representing the second top-edge vertex of a rupture quadrilateral. :param lat: A numpy array of latitude. :param lon: A numpy array of longitude. :param proj: An orthographic projection from openquake.hazardlib.geo.utils.get_orthographic_projection. :returns: Array of size lat.shape of distances (in km). """ # projected coordinates are in km p0x, p0y = proj(P0.x, P0.y) p1x, p1y = proj(P1.x, P1.y) # Unit vector pointing along strike u_i_hat = Vector(p1x - p0x, p1y - p0y, 0).norm() # Convert sites to Cartesian sx, sy = proj(lon, lat) sx1d = np.reshape(sx, (-1,)) sy1d = np.reshape(sy, (-1,)) # Vectors from P0 to sites r = np.zeros([len(sx1d), 2]) r[:, 0] = sx1d - p0x r[:, 1] = sy1d - p0y # Dot product gives t_i u_i = np.sum(u_i_hat.getArray()[0:2] * r, axis=1) shp = u_i.shape if len(shp) == 1: u_i.shape = (shp[0], 1) u_i = np.fliplr(u_i) return u_i
def __calc_t_i(P0, P1, lat, lon, proj): """ Calculate t_i distance. See Spudich and Chiou OFR 2015-1028. This is the distance measured normal to strike from the i-th segment. Values on the hanging-wall are positive and those on the foot-wall are negative. :param P0: Point object, representing the first top-edge vertex of a fault quadrilateral. :param P1: Point object, representing the second top-edge vertex of a fault quadrilateral. :param lat: A numpy array of latitudes. :param lon: A numpy array of longitudes. :param proj: An orthographic projection from openquake.hazardlib.geo.utils.get_orthographic_projection. :returns: Array of size N of distances (in km) from input points to rupture surface. """ # projected coordinates are in km p0x, p0y = proj(P0.x, P0.y) p1x, p1y = proj(P1.x, P1.y) # Unit vector pointing normal to strike t_i_hat = Vector(p1y - p0y, -(p1x - p0x), 0).norm() # Convert sites to Cartesian sx, sy = proj(lon, lat) sx1d = np.reshape(sx, (-1, )) sy1d = np.reshape(sy, (-1, )) # Vectors from P0 to sites r = np.zeros([len(sx1d), 2]) r[:, 0] = sx1d - p0x r[:, 1] = sy1d - p0y # Dot product gives t_i t_i = np.sum(t_i_hat.getArray()[0:2] * r, axis=1) shp = t_i.shape if len(shp) == 1: t_i.shape = (shp[0], 1) t_i = np.fliplr(t_i) return t_i
def __calc_u_i(P0, P1, lat, lon, proj): """ Calculate u_i distance. See Spudich and Chiou OFR 2015-1028. This is the distance along strike from the first vertex (P0) of the i-th segment. :param P0: Point object, representing the first top-edge vertex of a fault quadrilateral. :param P1: Point object, representing the second top-edge vertex of a fault quadrilateral. :param lat: A numpy array of latitude. :param lon: A numpy array of longitude. :param proj: An orthographic projection from openquake.hazardlib.geo.utils.get_orthographic_projection. :returns: Array of size lat.shape of distances (in km). """ # projected coordinates are in km p0x, p0y = proj(P0.x, P0.y) p1x, p1y = proj(P1.x, P1.y) # Unit vector pointing along strike u_i_hat = Vector(p1x - p0x, p1y - p0y, 0).norm() # Convert sites to Cartesian sx, sy = proj(lon, lat) sx1d = np.reshape(sx, (-1, )) sy1d = np.reshape(sy, (-1, )) # Vectors from P0 to sites r = np.zeros([len(sx1d), 2]) r[:, 0] = sx1d - p0x r[:, 1] = sy1d - p0y # Dot product gives t_i u_i = np.sum(u_i_hat.getArray()[0:2] * r, axis=1) shp = u_i.shape if len(shp) == 1: u_i.shape = (shp[0], 1) u_i = np.fliplr(u_i) return u_i
def test(): print('Testing Vector class...') a = Vector(1, 1, 1) b = Vector(2, 2, 2) c = Vector(1, 1, 1) np.testing.assert_almost_equal(a.getArray(), np.array([1, 1, 1])) assert a == c alen = a.mag() np.testing.assert_almost_equal(alen, 1.73205, decimal=5) anorm = a.norm() bnorm = b.norm() assert anorm == bnorm acrossb = a.cross(b) assert acrossb == Vector(0, 0, 0) adotb = a.dot(b) assert adotb == 6 aplusb = a + b print('Passed Vector class tests.')