Browse Source

mt.MomentTensor: add getter methods for east-north-up system

master
Wasja Bloch 2 weeks ago
parent
commit
71ecbcf77a
2 changed files with 29 additions and 8 deletions
  1. +14
    -0
      src/moment_tensor.py
  2. +15
    -8
      test/base/test_moment_tensor.py

+ 14
- 0
src/moment_tensor.py View File

@ -761,6 +761,13 @@ class MomentTensor(Object):
return self._to_up_south_east.T * self._m * self._to_up_south_east
def m_east_north_up(self):
'''
Get moment tensor in east-north-up convention as 3x3 matrix.
'''
return self._to_east_north_up.T * self._m * self._to_east_north_up
def m6_up_south_east(self):
'''Get moment tensor in up-south-east convention as a six-element array.
@ -768,6 +775,13 @@ class MomentTensor(Object):
'''
return to6(self.m_up_south_east())
def m6_east_north_up(self):
'''Get moment tensor in east-north-up convention as a six-element array.
:returns: ``(mee, mnn, muu, men, meu, mnu)``
'''
return to6(self.m_east_north_up())
def m_plain_double_couple(self):
'''Get plain double couple with same scalar moment as moment tensor.'''
rotmat1 = self._rotmats[0]


+ 15
- 8
test/base/test_moment_tensor.py View File

@ -74,17 +74,24 @@ class MomentTensorTestCase(unittest.TestCase):
self.assertSame(sdr[1], (18., 18., 112.), 1., 'chile fail 2')
def testENU(self):
m = num.matrix(
m_enu = num.matrix(
[[0.66, 0.53, -0.18],
[0.53, -0.70, -0.35],
[-0.18, -0.36, 0.04]], dtype=num.float)
m_enu = MomentTensor(m_east_north_up=m)
self.assertEqual(m[0, 0], m_enu.m()[1, 1])
self.assertEqual(m[1, 1], m_enu.m()[0, 0])
self.assertEqual(m[2, 2], m_enu.m()[2, 2])
self.assertEqual(m[0, 1], m_enu.m()[0, 1])
self.assertEqual(m[0, 2], -m_enu.m()[1, 2])
self.assertEqual(m[1, 2], -m_enu.m()[0, 2])
m = MomentTensor(m_east_north_up=m_enu)
self.assertEqual(m_enu[0, 0], m.m()[1, 1])
self.assertEqual(m_enu[1, 1], m.m()[0, 0])
self.assertEqual(m_enu[2, 2], m.m()[2, 2])
self.assertEqual(m_enu[0, 1], m.m()[0, 1])
self.assertEqual(m_enu[0, 2], -m.m()[1, 2])
self.assertEqual(m_enu[1, 2], -m.m()[0, 2])
self.assertEqual(m_enu[0, 0], m.m6_east_north_up()[0])
self.assertEqual(m_enu[1, 1], m.m6_east_north_up()[1])
self.assertEqual(m_enu[2, 2], m.m6_east_north_up()[2])
self.assertEqual(m_enu[0, 1], m.m6_east_north_up()[3])
self.assertEqual(m_enu[0, 2], m.m6_east_north_up()[4])
self.assertEqual(m_enu[1, 2], m.m6_east_north_up()[5])
self.assertSame(m_enu, m.m_east_north_up(), 1e-3, 'testENU fail')
def testIO(self):
m1 = MomentTensor(dip=90.)


Loading…
Cancel
Save