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 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)
def test_MT2Axes(self): """ Tests mt2axes. """ # http://en.wikipedia.org/wiki/File:USGS_sumatra_mts.gif mt = MomentTensor((0.91, -0.89, -0.02, 1.78, -1.55, 0.47), 0) (T, N, P) = mt2axes(mt) self.assertAlmostEqual(T.val, 2.52461359) self.assertAlmostEqual(T.dip, 55.33018576) self.assertAlmostEqual(T.strike, 49.53656116) self.assertAlmostEqual(N.val, 0.08745048) self.assertAlmostEqual(N.dip, 7.62624529) self.assertAlmostEqual(N.strike, 308.37440488) self.assertAlmostEqual(P.val, -2.61206406) self.assertAlmostEqual(P.dip, 33.5833323) self.assertAlmostEqual(P.strike, 213.273886)
def test_MT2Axes(self): """ Tests mt2axes. """ # http://en.wikipedia.org/wiki/File:USGS_sumatra_mts.gif mt = MomentTensor((0.91, -0.89, -0.02, 1.78, -1.55, 0.47), 0) (T, N, P) = mt2axes(mt) self.assertAlmostEqual(T.val, 2.52461359) self.assertAlmostEqual(T.dip, 55.33018576) self.assertAlmostEqual(T.strike, 49.53656116) self.assertAlmostEqual(N.val, 0.08745048) self.assertAlmostEqual(N.dip, 7.62624529) self.assertAlmostEqual(N.strike, 308.37440488) self.assertAlmostEqual(P.val, -2.61206406) self.assertAlmostEqual(P.dip, 33.5833323) self.assertAlmostEqual(P.strike, 213.273886)
def test_mt2axes(self): """ Tests mt2axes. """ # https://en.wikipedia.org/wiki/File:USGS_sumatra_mts.gif mt = MomentTensor((0.91, -0.89, -0.02, 1.78, -1.55, 0.47), 0) (t, n, p) = mt2axes(mt) assert round(abs(t.val - 2.52461359), 7) == 0 assert round(abs(t.dip - 55.33018576), 7) == 0 assert round(abs(t.strike - 49.53656116), 7) == 0 assert round(abs(n.val - 0.08745048), 7) == 0 assert round(abs(n.dip - 7.62624529), 7) == 0 assert round(abs(n.strike - 308.37440488), 7) == 0 assert round(abs(p.val - -2.61206406), 7) == 0 assert round(abs(p.dip - 33.5833323), 7) == 0 assert round(abs(p.strike - 213.273886), 7) == 0
# Surface 0 0 0 # Timing and location information # hr min sec lat lon depth mb Ms # MLI 18 7 31.30 51.43 -175.56 33.0 5.4 5.4 # CMT 18 7 34.20 51.47 -175.41 32.2 # Error 0.30 0.03 0.05 2.0 # Assumed half duration: 3.3 # Mechanism information # Exponent for moment tensor: 24 units: dyne-cm # Mrr Mtt Mpp Mrt Mrp Mtp # CMT 4.810 -4.523 -0.287 4.885 3.476 -2.651 # Error 0.133 0.201 0.132 0.373 0.279 0.158 # Mw = 5.9 Scalar Moment = 8.01e+24 # Fault plane: strike=255 dip=22 slip=107 # Fault plane: strike=56 dip=69 slip=83 # Eigenvector: eigenvalue: 7.58 plunge: 65 azimuth: 315 # Eigenvector: eigenvalue: 0.88 plunge: 6 azimuth: 59 # Eigenvector: eigenvalue: -8.45 plunge: 24 azimuth: 152 mt_test = bb.MomentTensor([4.810, -4.523, -0.287, 4.885, 3.476, -2.651], 24) # eigval, eigvct = np.linalg.eig(mt_test.mt) # print(eigval) works # print(eigvct) works print(bb.mt2axes(mt_test) [0].dip) # bb.mt2axes(mt_test).strike, bb.mt2axes(mt_test).val)
def main(): parser = argparse.ArgumentParser( description='Ternary plot to display the type pf mechanism') group_input = parser.add_mutually_exclusive_group(required=False) group_input.add_argument( '-c', '--cmtfile', help='Give a file at the CMTSOLUTION format from the Global CMT catalog' ) group_input.add_argument( '--mt', help= 'Give the moment tensor in the following order: Mrr,Mtt,Mpp,Mrt,Mrp,Mtp', nargs=6, type=float, metavar=("Mrr", "Mtt", "Mpp", "Mrt", "Mrp", "Mtp")) group_input.add_argument('--np', help='Give nodal plane angle (strike,dip,slip)', nargs=3, type=float, metavar=("strike", "dip", "slip")) parser.add_argument('--infile', help='read input file with several moment tensor') parser.add_argument('--debug', help='debug mode', action='store_true') parser.add_argument('-o', '--output', help='save figure (png, svg, eps, pdf)') args = parser.parse_args() if args.infile: fm = read_foc_mec_file(args.infile) print fm if args.cmtfile: cmtfile = args.cmtfile cmt_dict = parse_cmt(cmtfile) Mrr = float(cmt_dict['Mrr']) Mtt = float(cmt_dict['Mtt']) Mpp = float(cmt_dict['Mpp']) Mrt = float(cmt_dict['Mrt']) Mrp = float(cmt_dict['Mrp']) Mtp = float(cmt_dict['Mtp']) elif args.mt: Mrr = args.mt[0] Mtt = args.mt[1] Mpp = args.mt[2] Mrt = args.mt[3] Mrp = args.mt[4] Mtp = args.mt[5] elif args.np: Mrr, Mtt, Mpp, Mrt, Mrp, Mtp = sdrToMt(args.np[0], args.np[1], args.np[2]) M = MomentTensor((Mrr, Mtt, Mpp, Mrt, Mrp, Mtp), 0) # principal axes (T, N, P) = mt2axes(M) if args.debug: print "Moment tensor: \n Mrr :",Mrr, \ "\n Mtt :",Mtt, \ "\n Mpp :",Mpp, \ "\n Mrt :",Mrt, \ "\n Mrp :",Mrp, \ "\n Mtp :",Mtp print "PRINCIPAL AXES:" print "T axis: VAL = ", round(T.val), " PLG = ", round( T.dip), "AZM = ", round(T.strike) print "N axis: VAL = ", round(N.val), " PLG = ", round( N.dip), "AZM = ", round(N.strike) print "P axis: VAL = ", round(P.val), " PLG = ", round( P.dip), "AZM = ", round(P.strike) x = sin(T.dip * degtorad) y = sin(N.dip * degtorad) z = sin(P.dip * degtorad) data = np.array([[y, z, x]]) tri = ternaryDiagram() tri.background() tri.plot_data(data, M) if args.output: plt.savefig(output, bbox_inches='tight') else: plt.show()
mtt = -is2 * (sin(dip) * cos(rake) * sin(2 * strike) + sin(2 * dip) * sin(rake) * sin(strike)**2) mpp = is2 * (sin(dip) * cos(rake) * sin(2 * strike) - sin(2 * dip) * sin(rake) * cos(strike)**2) mtp = -is2 * (sin(dip) * cos(rake) * cos(2 * strike) + 0.5 * sin(2 * dip) * sin(rake) * sin(2 * strike)) mrp = is2 * (cos(dip) * cos(rake) * sin(strike) - cos(2 * dip) * sin(rake) * cos(strike)) mrt = -is2 * (cos(dip) * cos(rake) * cos(strike) + cos(2 * dip) * sin(rake) * sin(strike)) mt = MomentTensor((mrr, mtt, mpp, mrt, mrp, mtp), 0) # principal axes (T, N, P) = mt2axes(mt) # output print " " print "MOMENT TENSOR:" print "MRR = ", mrr print "MTT = ", mtt print "MPP = ", mpp print "MTP = ", mtp print "MRP = ", mrp print "MRT = ", mrt print " " print "PRINCIPAL AXES:" print "T axis: VAL = ", round(T.val), " PLG = ", round(T.dip), "AZM = ", round( T.strike)
# Eigenvector: eigenvalue: 7.58 plunge: 65 azimuth: 315 # Eigenvector: eigenvalue: 0.88 plunge: 6 azimuth: 59 # Eigenvector: eigenvalue: -8.45 plunge: 24 azimuth: 152 mt = MomentTensor([4.810, -4.523, -0.287, 4.885, 3.476, -2.651], 24) 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
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