def fill_tensor_from_components(mrr, mtt, mpp, mrt, mrp, mtp, source='unknown', mtype='unknown'): """Fill in moment tensor parameters from moment tensor components. Args: strike (float): Strike from (assumed) first nodal plane (degrees). dip (float): Dip from (assumed) first nodal plane (degrees). rake (float): Rake from (assumed) first nodal plane (degrees). magnitude (float): Magnitude for moment tensor (not required if using moment tensor for angular comparisons.) Returns: dict: Fully descriptive moment tensor dictionary, including fields: - mrr,mtt,mpp,mrt,mrp,mtp Moment tensor components. - T T-axis values: - azimuth (degrees) - plunge (degrees) - N N-axis values: - azimuth (degrees) - plunge (degrees) - P P-axis values: - azimuth (degrees) - plunge (degrees) - NP1 First nodal plane values: - strike (degrees) - dip (degrees) - rake (degrees) - NP2 Second nodal plane values: - strike (degrees) - dip (degrees) - rake (degrees) """ tensor_params = { 'mrr': mrr, 'mtt': mtt, 'mpp': mpp, 'mrt': mrt, 'mrp': mrp, 'mtp': mtp } tensor_params['source'] = source tensor_params['type'] = mtype mt = MomentTensor(mrr, mtt, mpp, mrt, mrp, mtp, 1) tnp1 = mt2plane(mt) np1 = {'strike': tnp1.strike, 'dip': tnp1.dip, 'rake': tnp1.rake} tensor_params['NP1'] = np1.copy() strike2, dip2, rake2 = aux_plane(np1['strike'], np1['dip'], np1['rake']) np2 = {'strike': strike2, 'dip': dip2, 'rake': rake2} tensor_params['NP2'] = np2.copy() T, N, P = mt2axes(mt) tensor_params['T'] = {'azimuth': T.strike, 'value': T.val, 'plunge': T.dip} tensor_params['N'] = {'azimuth': N.strike, 'value': N.val, 'plunge': N.dip} tensor_params['P'] = {'azimuth': P.strike, 'value': P.val, 'plunge': P.dip} return tensor_params
def test_MT2Plane(self): """ Tests mt2plane. """ mt = MomentTensor((0.91, -0.89, -0.02, 1.78, -1.55, 0.47), 0) np = mt2plane(mt) self.assertAlmostEqual(np.strike, 129.86262672080011) self.assertAlmostEqual(np.dip, 79.022700906654734) self.assertAlmostEqual(np.rake, 97.769255185515192)
def test_mt2plane(self): """ Tests mt2plane. """ mt = MomentTensor((0.91, -0.89, -0.02, 1.78, -1.55, 0.47), 0) np = mt2plane(mt) assert round(abs(np.strike - 129.86262672080011), 7) == 0 assert round(abs(np.dip - 79.022700906654734), 7) == 0 assert round(abs(np.rake - 97.769255185515192), 7) == 0
def convert_to_antelope(M, cenloc): """ Convert Roberto's wphase output to antelope's moment tensor format. Plus calculate a few values based on the moment tensor. :param M: Moment tensor :param cenloc: The centroid location, (cenlat,cenlon,cendep) :return: antelope's moment tensor info in a dictionary. """ M2 = np.asarray(M)**2 m0 = np.sqrt(0.5*(M2[0]+M2[1]+M2[2])+M2[3]+M2[4]+M2[5]) mag = 2./3.*(np.log10(m0)-9.10) np1 = mt2plane(MomentTensor(M, 0)) np2 = aux_plane(np1.strike, np1.dip, np1.rake) results = model.AntelopeMomentTensor( tmpp=M[2], tmrp=M[4], tmrr=M[0], tmrt=M[3], tmtp=M[5], tmtt=M[1], scm=m0, drmag=mag, drmagt='Mww', drlat=cenloc[0], drlon=cenloc[1], drdepth=cenloc[2], str1=np1.strike, dip1=np1.dip, rake1=np1.rake, str2=np2[0], dip2=np2[1], rake2=np2[2], auth=settings.AUTHORITY, ) try: results.dc, results.clvd = decomposeMT(M) except Exception: import traceback logger.warning("Error computing DC/CLVD decomposition: %s", traceback.format_exc()) return results
def mt2parameters(MTx,M,gfscale): #Iso Mo MoIso = (MTx[0][0] + MTx[1][1] + MTx[2][2])/3 c = MomentTensor(MTx[2][2],MTx[0][0],MTx[1][1],MTx[0][2],-MTx[1][2],-MTx[0][1],gfscale) # Principal axes (T, N, P) = mt2axes(c) # Nodal planes np0 = mt2plane(c) np2 = aux_plane(np0.strike,np0.dip,np0.rake) # Convention rake: up-down if (np0.rake>180): np0.rake= np0.rake-360 if (np0.rake<-180): np0.rake= np0.rake+360 np1 = np.zeros(3.) np1 = [np0.strike,np0.dip,np0.rake] # Compute Eigenvectors and Eigenvalues # Seismic Moment and Moment Magnitude (EigVal, EigVec) = np.linalg.eig(MTx) b = copy.deepcopy(EigVal) b.sort() Mo = (abs(b[0]) + abs(b[2]))/2. Mw = math.log10(Mo)/1.5-10.73 # Compute double-couple, CLVD & iso d = copy.deepcopy(EigVal) d[0]=abs(d[0]) d[1]=abs(d[1]) d[2]=abs(d[2]) d.sort() eps=abs(d[0])/abs(d[2]) pcdc=100.0*(1.0-2.0*eps) pcclvd=200.0*eps pcdc=pcdc/100.0 pcclvd=pcclvd/100.0 pciso=abs(MoIso)/Mo pcsum=pcdc+pcclvd+pciso pcdc=100.0*pcdc/pcsum pcclvd=100.0*pcclvd/pcsum pciso=100.0*pciso/pcsum Pdc = pcdc Pclvd = pcclvd return (Mo, Mw, Pdc, Pclvd, EigVal, EigVec, T, N, P, np1, np2)
eigvals, eigvcts = np.linalg.eigh(np.array(mt.mt * 10**mt.exp, dtype=float)) print(eigvals) #[-8.45266194 7.57685043 0.87581151] print(eigvcts) #[[-0.40938256 0.90576372 -0.1095354 ] # [ 0.80215416 0.30012763 -0.51620937] # [ 0.43468912 0.29919139 0.84942915]] in columns t, b, p = princax(mt) print(t, b, p) print(bb.mt2axes(mt)[0].__dict__) # {'val': 7.58, 'strike': 315, 'dip': 64.9} print(bb.mt2axes(mt)[1].__dict__) # {'val': 0.88, 'strike': 58.7, 'dip': 6.29} print(bb.mt2axes(mt) [2].__dict__) # {'val': -8.45, 'strike': 151.55, 'dip': 24.2} print( bb.mt2plane(mt).__dict__) # {'strike': 56.34, 'dip': 69.45, 'rake': 83.28} print(bb.aux_plane(56.344996989653225, 69.45184548172541, 83.28228402625453)) #(254.8956832264013, 21.573156870706903, 107.33165895106156) strike, dip, slip aux plane M0 = sqrt(np.sum(eigvals**2) / 2) print('M0: ', M0) # 8.050565259657235 * 10 ** 24 Scalar Moment M_W = 2 / 3 * log(M0, 10) - 10.7 print(M_W) # 5.903884249895878 T, B, P = eigvals f_CLVD = abs(B) / max(abs(T), abs(P)) print(f_CLVD) # 0.10361369212705232 print(mt.fclvd)
def main(): parser = argparse.ArgumentParser( description= 'Draws a beachball of an earthquake focal mechanism given strike, dip, rake or the 6 components of the moment tensor' ) parser.add_argument( '--fm', help= 'Nodal plane (strike dip rake) or moment tensor (Mrr Mtt Mpp Mrt Mrp Mtp)', type=float, nargs='+') parser.add_argument('--dc', help='superpose the double couple component', action='store_true') parser.add_argument( '-c', '--color', help= 'Choose a color for the quadrant of tension (r,b,k,g,y...). Default color is red', default='r', type=str) parser.add_argument( '-o', '--output', help= 'Name of the output file (could be a png, ps, pdf,eps, and svg). Default is None', default=None, type=str) args = parser.parse_args() bb = BB(outputname=args.output, facecolor=args.color) NP = None if args.fm: if len(args.fm) == 6: print "Draw beachball from moment tensor" Mrr = args.fm[0] Mtt = args.fm[1] Mpp = args.fm[2] Mrt = args.fm[3] Mrp = args.fm[4] Mtp = args.fm[5] M = MomentTensor((Mrr, Mtt, Mpp, Mrt, Mrp, Mtp), 0) nod_planes = mt2plane(M) if args.dc: NP = (nod_planes.strike, nod_planes.dip, nod_planes.rake) s2, d2, r2 = aux_plane(nod_planes.strike, nod_planes.dip, nod_planes.rake) print "Moment tensor:", \ "\n Mrr :",Mrr, \ "\n Mtt :",Mtt, \ "\n Mpp :",Mpp, \ "\n Mrt :",Mrt, \ "\n Mrp :",Mrp, \ "\n Mtp :",Mtp print "NP1:", round(nod_planes.strike), round( nod_planes.dip), round(nod_planes.rake) print "NP2:", round(s2), round(d2), round(r2) elif len(args.fm) == 3: print "Draw beachball from nodal plane" # compute auxiliary plane s2, d2, r2 = aux_plane(args.fm[0], args.fm[1], args.fm[2]) print "NP1:", round(args.fm[0]), round(args.fm[1]), round( args.fm[2]) print "NP2:", round(s2), round(d2), round(r2) bb.draw(args.fm, NP=NP)
def fill_tensor_from_components(mrr, mtt, mpp, mrt, mrp, mtp, source='unknown', mtype='unknown'): """Fill in moment tensor parameters from moment tensor components. Args: strike (float): Strike from (assumed) first nodal plane (degrees). dip (float): Dip from (assumed) first nodal plane (degrees). rake (float): Rake from (assumed) first nodal plane (degrees). magnitude (float): Magnitude for moment tensor (not required if using moment tensor for angular comparisons.) Returns: dict: Fully descriptive moment tensor dictionary, including fields: - mrr,mtt,mpp,mrt,mrp,mtp Moment tensor components. - T T-axis values: - azimuth (degrees) - plunge (degrees) - N N-axis values: - azimuth (degrees) - plunge (degrees) - P P-axis values: - azimuth (degrees) - plunge (degrees) - NP1 First nodal plane values: - strike (degrees) - dip (degrees) - rake (degrees) - NP2 Second nodal plane values: - strike (degrees) - dip (degrees) - rake (degrees) """ tensor_params = {'mrr': mrr, 'mtt': mtt, 'mpp': mpp, 'mrt': mrt, 'mrp': mrp, 'mtp': mtp} tensor_params['source'] = source tensor_params['type'] = mtype mt = MomentTensor(mrr, mtt, mpp, mrt, mrp, mtp, 1) tnp1 = mt2plane(mt) np1 = {'strike': tnp1.strike, 'dip': tnp1.dip, 'rake': tnp1.rake} tensor_params['NP1'] = np1.copy() strike2, dip2, rake2 = aux_plane(np1['strike'], np1['dip'], np1['rake']) np2 = {'strike': strike2, 'dip': dip2, 'rake': rake2} tensor_params['NP2'] = np2.copy() T, N, P = mt2axes(mt) tensor_params['T'] = {'azimuth': T.strike, 'value': T.val, 'plunge': T.dip} tensor_params['N'] = {'azimuth': N.strike, 'value': N.val, 'plunge': N.dip} tensor_params['P'] = {'azimuth': P.strike, 'value': P.val, 'plunge': P.dip} return tensor_params