Example #1
0
 def test_rotate_NE_RTVsPitsa(self):
     """
     Test horizontal component rotation against PITSA.
     """
     # load test files
     with gzip.open(os.path.join(self.path, 'rjob_20051006_n.gz')) as f:
         data_n = np.loadtxt(f)
     with gzip.open(os.path.join(self.path, 'rjob_20051006_e.gz')) as f:
         data_e = np.loadtxt(f)
     # 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
         with gzip.open(
                 os.path.join(self.path,
                              'rjob_20051006_r_%sdeg.gz' % angle)) as f:
             data_pitsa_r = np.loadtxt(f)
         with gzip.open(
                 os.path.join(self.path,
                              'rjob_20051006_t_%sdeg.gz' % angle)) as f:
             data_pitsa_t = np.loadtxt(f)
         # 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))
Example #2
0
 def test_rotate_NE_RTVsPitsa(self):
     """
     Test horizontal component rotation against PITSA.
     """
     # load test files
     with gzip.open(os.path.join(self.path, 'rjob_20051006_n.gz')) as f:
         data_n = np.loadtxt(f)
     with gzip.open(os.path.join(self.path, 'rjob_20051006_e.gz')) as f:
         data_e = np.loadtxt(f)
     # 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
         with gzip.open(os.path.join(self.path,
                                     'rjob_20051006_r_%sdeg.gz' %
                                     angle)) as f:
             data_pitsa_r = np.loadtxt(f)
         with gzip.open(os.path.join(self.path,
                                     'rjob_20051006_t_%sdeg.gz' %
                                     angle)) as f:
             data_pitsa_t = np.loadtxt(f)
         # 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))
def rotater(tr_N, tr_E):
    """
    Rotates horizontal components of a seismogram.
    """
    az, ba = azbackaz(tr_N)
    try:
        return az, rotate_NE_RT(tr_N.data, tr_E.data, ba)[1]
    except Exception, e:
        print 'ERROR %s.%s.%s.%s: %s vs %s %s' %(tr_N.stats.network, 
                tr_N.stats.station, tr_N.stats.location, 
                tr_N.stats.channel, tr_N.stats.npts, tr_E.stats.npts, e)
        return False, tr_N.data
Example #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
     with gzip.open(os.path.join(self.path, 'rjob_20051006_n.gz')) as f:
         data_n = np.loadtxt(f)
     with gzip.open(os.path.join(self.path, 'rjob_20051006_e.gz')) as f:
         data_e = np.loadtxt(f)
     # Use double precision to get more accuracy for testing.
     data_n = np.require(data_n, np.float64)
     data_e = np.require(data_e, np.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))
Example #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
     with gzip.open(os.path.join(self.path, 'rjob_20051006_n.gz')) as f:
         data_n = np.loadtxt(f)
     with gzip.open(os.path.join(self.path, 'rjob_20051006_e.gz')) as f:
         data_e = np.loadtxt(f)
     # Use double precision to get more accuracy for testing.
     data_n = np.require(data_n, np.float64)
     data_e = np.require(data_e, np.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))
Example #6
0
def rotate_tr(tr_n, tr_e, **kwargs):
    '''
    Rotate trace from NE to RT coordinates
    '''
    tr_r = tr_n.copy()
    tr_t = tr_n.copy()

    r, t = rotate_NE_RT(tr_n.data, tr_e.data, tr_n.stats.sac['baz'])

    tr_r.data = r
    tr_t.data = t

    tr_r.stats.location = tr_n.stats.sac['gcarc']
    tr_t.stats.location = tr_n.stats.sac['gcarc']

    tr_r.stats.azimuth = tr_n.stats.sac['az']
    tr_t.stats.azimuth = tr_t.stats.sac['az']

    tr_r.stats.channel = 'BHR'
    tr_t.stats.channel = 'BHT'

    return tr_r, tr_t
Example #7
0
def rotate_tr(tr_n, tr_e, **kwargs):
    """
    Rotate trace from NE to RT coordinates
    """
    tr_r = tr_n.copy()
    tr_t = tr_n.copy()

    r, t = rotate_NE_RT(tr_n.data, tr_e.data, tr_n.stats.sac["baz"])

    tr_r.data = r
    tr_t.data = t

    tr_r.stats.location = tr_n.stats.sac["gcarc"]
    tr_t.stats.location = tr_n.stats.sac["gcarc"]

    tr_r.stats.azimuth = tr_n.stats.sac["az"]
    tr_t.stats.azimuth = tr_t.stats.sac["az"]

    tr_r.stats.channel = "BHR"
    tr_t.stats.channel = "BHT"

    return tr_r, tr_t
Example #8
0
            ss = sdsname.split('.')
            sdsshort = ('%s.%s') % (ss[0], ss[1])
            if shortname == sdsshort:
                print 'JUHU', station, j
                st = read(j)
                tr = st[0]
                if fnmatch.fnmatch(tr.stats.channel, '*E'):
                    e = tr.data
                    print 'E COMP'
                if fnmatch.fnmatch(tr.stats.channel, '*N'):
                    n = tr.data
                    print 'N COMP'

        if len(n) == len(e):

            z = rotate.rotate_NE_RT(n, e, bazi)  #return r and t data array

            tmr = Trace(z[0])
            tmr.stats.network = tr.stats.network
            tmr.stats.station = tr.stats.station
            tmr.stats.sampling_rate = tr.stats.sampling_rate
            tmr.stats.channel = 'R'
            tmr.stats.starttime = UTCDateTime(tr.stats.starttime)
            tmr.stats._format = 'MSEED'

            pr = os.path.join(os.path.join('/', *j.split('/')[:-2]), 'R.D')
            os.makedirs(pr)
            print 'PR ', pr
            jd = "%03d" % tmr.stats.starttime.julday
            n = ('%s.%s.%s.%s.%s.%s') % (
                tmr.stats.network, tmr.stats.station, tmr.stats.location,
Example #9
0
            try:
                st_E = read(ls_E[i], format='SAC')[0]
                st_N = read(os.path.join(add_ev, 'BH',
                                         'dis.%s.%s.%sN'
                                         % (st_E.stats.station,
                                            st_E.stats.location,
                                            st_E.stats.channel[:-1])),
                            format='SAC')[0]

                (dist, azi, bazi) = gps2DistAzimuth(st_E.stats.sac.evla,
                                                    st_E.stats.sac.evlo,
                                                    st_E.stats.sac.stla,
                                                    st_E.stats.sac.stlo)

                (tr_data_R, tr_data_T) = rotate.rotate_NE_RT(st_N.data,
                                                             st_E.data,
                                                             bazi)

                tr_R = st_N.copy()
                tr_T = st_N.copy()

                tr_R.data = tr_data_R
                tr_R.stats.channel = 'BHR'
                tr_T.data = tr_data_T
                tr_T.stats.channel = 'BHT'
                #tr_R.write(os.path.join(add_ev, 'BH',
                #                        'dis.%s.%s.%s'
                #                        % (tr_R.stats.station,
                #                           tr_R.stats.location,
                #                           tr_R.stats.channel)),
                #           format='SAC')