def rotateToGCP(self):

    tr=self.copy()

    #begin loop over data stream
    for i in range(len(tr)-1):
      # split channel
      li0 = list(tr[i+0].stats['channel'])
      li1 = list(tr[i+1].stats['channel'])

      # chech if station and part 1 of channel is identical and location
      if li0[0] == li1[0] and li0[1] == li1[1] \
         and tr[i+0].stats['station']  == tr[i+1].stats['station']\
         and tr[i+0].stats['location'] == tr[i+1].stats['location']:

         rch = li0[0] + li0[1] + 'R'
         tch = li0[0] + li0[1] + 'T'

         

         # if yes 3 possibility: EN, NE , pass
         if li0[2]=="E" and li1[2]=="N":
            #baz
            baz = tr[i].stats['baz']
            if tr[i+0].stats['npts'] == tr[i+1].stats['npts']:
               # rotate 0-1
               (tr[i+1].data,tr[i+0].data) = rotate_NE_RT(tr[i+1].data,tr[i+0].data,baz)
               tr[i+0].stats['channel']=tch
               tr[i+1].stats['channel']=rch
               i=i+1
            else:
               print "Can't rotate ",tr[i+0].stats['station'],tr[i+0].stats['channel'], " and ", \
                      tr[i+1].stats['station'],tr[i+1].stats['channel'] 

         elif li0[2]=="N" and li1[2]=="E":
            #baz
            baz = tr[i].stats['baz']
            if tr[i+0].stats['npts'] == tr[i+1].stats['npts']:
#              # rotate 1-0
               (tr[i+0].data,tr[i+1].data) = rotate_NE_RT(tr[i+0].data,tr[i+1].baz)
               tr[i+1].stats['channel']=tch
               tr[i+0].stats['channel']=rch
               i=i+1
            else:
               print "Can't rotate ",tr[i+0].stats['station'],tr[i+0].stats['channel'], " and ", \
                      tr[i+1].stats['station'],tr[i+1].stats['channel'] 

         else:
            pass 

    return tr
示例#2
0
 def test_rotate_NE_RTVsPitsa(self):
     """
     Test horizontal component rotation against PITSA.
     """
     # load test files
     # no with due to py 2.6
     f = gzip.open(os.path.join(self.path, 'rjob_20051006_n.gz'))
     data_n = np.loadtxt(f)
     f.close()
     f = gzip.open(os.path.join(self.path, 'rjob_20051006_e.gz'))
     data_e = np.loadtxt(f)
     f.close()
     #test different angles, one from each sector
     for angle in [30, 115, 185, 305]:
         # rotate traces
         datcorr_r, datcorr_t = rotate_NE_RT(data_n, data_e, angle)
         # load pitsa files
         f = gzip.open(os.path.join(self.path,
                                    'rjob_20051006_r_%sdeg.gz' %
                                    angle))
         data_pitsa_r = np.loadtxt(f)
         f.close()
         f = gzip.open(os.path.join(self.path,
                                    'rjob_20051006_t_%sdeg.gz' %
                                    angle))
         data_pitsa_t = np.loadtxt(f)
         f.close()
         # Assert.
         self.assertTrue(np.allclose(datcorr_r, data_pitsa_r, rtol=1E-3,
                                     atol=1E-5))
         self.assertTrue(np.allclose(datcorr_t, data_pitsa_t, rtol=1E-3,
                                     atol=1E-5))
示例#3
0
 def test_rotate_NE_RTVsPitsa(self):
     """
     Test horizontal component rotation against PITSA.
     """
     # load test files
     # no with due to py 2.6
     f = gzip.open(os.path.join(self.path, 'rjob_20051006_n.gz'))
     data_n = np.loadtxt(f)
     f.close()
     f = gzip.open(os.path.join(self.path, 'rjob_20051006_e.gz'))
     data_e = np.loadtxt(f)
     f.close()
     # test different angles, one from each sector
     for angle in [30, 115, 185, 305]:
         # rotate traces
         datcorr_r, datcorr_t = rotate_NE_RT(data_n, data_e, angle)
         # load pitsa files
         f = gzip.open(
             os.path.join(self.path, 'rjob_20051006_r_%sdeg.gz' % angle))
         data_pitsa_r = np.loadtxt(f)
         f.close()
         f = gzip.open(
             os.path.join(self.path, 'rjob_20051006_t_%sdeg.gz' % angle))
         data_pitsa_t = np.loadtxt(f)
         f.close()
         # Assert.
         self.assertTrue(
             np.allclose(datcorr_r, data_pitsa_r, rtol=1E-3, atol=1E-5))
         self.assertTrue(
             np.allclose(datcorr_t, data_pitsa_t, rtol=1E-3, atol=1E-5))
示例#4
0
 def test_rotate_NE_RT_NE(self):
     """
     Rotating there and back with the same back-azimuth should not change
     the data.
     """
     # load the data
     data_n = np.loadtxt(os.path.join(self.path, 'rjob_20051006_n.gz'))
     data_e = np.loadtxt(os.path.join(self.path, 'rjob_20051006_e.gz'))
     # Use double precision to get more accuracy for testing.
     data_n = np.require(data_n, "float64")
     data_e = np.require(data_e, "float64")
     ba = 33.3
     new_n, new_e = rotate_NE_RT(data_n, data_e, ba)
     new_n, new_e = rotate_RT_NE(new_n, new_e, ba)
     self.assertTrue(np.allclose(data_n, new_n, rtol=1E-7, atol=1E-12))
     self.assertTrue(np.allclose(data_e, new_e, rtol=1E-7, atol=1E-12))
示例#5
0
 def test_rotate_NE_RT_NE(self):
     """
     Rotating there and back with the same back-azimuth should not change
     the data.
     """
     # load the data
     data_n = np.loadtxt(os.path.join(self.path, 'rjob_20051006_n.gz'))
     data_e = np.loadtxt(os.path.join(self.path, 'rjob_20051006_e.gz'))
     # Use double precision to get more accuracy for testing.
     data_n = np.require(data_n, "float64")
     data_e = np.require(data_e, "float64")
     ba = 33.3
     new_n, new_e = rotate_NE_RT(data_n, data_e, ba)
     new_n, new_e = rotate_RT_NE(new_n, new_e, ba)
     self.assertTrue(np.allclose(data_n, new_n, rtol=1E-7, atol=1E-12))
     self.assertTrue(np.allclose(data_e, new_e, rtol=1E-7, atol=1E-12))
示例#6
0
 def test_rotate_NE_RTVsPitsa(self):
     """
     Test horizontal component rotation against PITSA.
     """
     # load test files
     file = os.path.join(self.path, 'rjob_20051006_n.gz')
     f = gzip.open(file)
     data_n = np.loadtxt(f)
     f.close()
     file = os.path.join(self.path, 'rjob_20051006_e.gz')
     f = gzip.open(file)
     data_e = np.loadtxt(f)
     f.close()
     #test different angles, one from each sector
     for angle in [30, 115, 185, 305]:
         # rotate traces
         datcorr_r, datcorr_t = rotate_NE_RT(data_n, data_e, angle)
         # load pitsa files
         file = os.path.join(self.path, 'rjob_20051006_r_%sdeg.gz' % angle)
         f = gzip.open(file)
         data_pitsa_r = np.loadtxt(f)
         f.close()
         file = os.path.join(self.path, 'rjob_20051006_t_%sdeg.gz' % angle)
         f = gzip.open(file)
         data_pitsa_t = np.loadtxt(f)
         f.close()
         # calculate normalized rms
         rms = np.sqrt(np.sum((datcorr_r - data_pitsa_r) ** 2) /
                       np.sum(data_pitsa_r ** 2))
         rms += np.sqrt(np.sum((datcorr_t - data_pitsa_t) ** 2) /
                        np.sum(data_pitsa_t ** 2))
         rms /= 2.0
         #from pylab import figure,plot,legend,show
         #figure()
         #plot(datcorr_r,label="R ObsPy")
         #plot(data_pitsa_r,label="R PITSA")
         #plot(datcorr_t,label="T ObsPy")
         #plot(data_pitsa_t,label="T PITSA")
         #legend()
         #show()
         self.assertEqual(rms < 1.0e-5, True)