Esempio n. 1
0
def readWaveformsPyrocko_restituted(stationlist, w, EventPath, Origin,
                                    desired):
    Wdict = OrderedDict()
    if desired is 'Z':
        try:
            traces = io.load(EventPath + '/data/traces_rotated.mseed')
        except Exception:
            traces = io.load(EventPath + '/data/traces_restituted.mseed')
    else:
        traces = io.load(EventPath + '/data/traces_rotated.mseed')

    obspy_compat.plant()
    traces_dict = []
    for tr in traces:
        for il in stationlist:
            tr_name = str(tr.network + '.' + tr.station + '.' + tr.location +
                          '.')
            if (tr_name == str(il) and tr.channel[-1] == desired) or (
                    tr_name == str(il)[:-3] and tr.channel[-1] == desired):
                st = obspy.Stream()
                es = obspy_compat.to_obspy_trace(tr)
                st.extend([es])
                traces_dict.append(tr)
                Wdict[il.getName()] = st

    return Wdict
    def readWaveformsPicker_pyrocko(self, station, tw, Origin, ttime, cfg_yaml):

        obspy_compat.plant()
        cfg = ConfigObj(dict=self.Config)
        if cfg_yaml.config_data.quantity == 'displacement':
            try:
                traces = io.load(self.EventPath+'/data/traces_rotated.mseed')
            except:
                traces = io.load(self.EventPath+'/data/traces_restituted.mseed')
        else:
            traces = io.load(self.EventPath+'/data/traces_velocity.mseed')
        for tr in traces:
            tr_name = str(tr.network+'.'+tr.station+'.'+tr.location+'.'
                                    + tr.channel[:3])
            if tr_name == str(station)[:-2] or tr_name == str(station)[:]:
                traces_station = tr
                es = obspy_compat.to_obspy_trace(traces_station)

                st = obspy.Stream()
                st.extend([es])
                stream = ''

                if station.loc == '--':
                    station.loc = ''

                if len(st.get_gaps()) > 0:
                    st.merge(method=0, fill_value='interpolate',
                             interpolation_samples=0)
                stream = self.filterWaveform(st, cfg_yaml)

                stream.trim(tw['xcorrstart'], tw['xcorrend'])
                return stream

        else:
            pass
    def readWaveformsCross_pyrocko(self, station, tw, ttime):
        obspy_compat.plant()
        cfg = ConfigObj(dict=self.Config)

        t2 = UTCDateTime(self.Origin.time)
        if cfg.quantity() == 'displacement':
            try:
                traces = io.load(self.EventPath + '/data/traces_rotated.mseed')
            except Exception:
                traces = io.load(self.EventPath +
                                 '/data/traces_restituted.mseed')
        else:
            traces = io.load(self.EventPath + '/data/traces_velocity.mseed')

        found = False
        while found is False:
            for tr in traces:
                tr_name = str(tr.network + '.' + tr.station + '.' +
                              tr.location + '.' + tr.channel[:3])

                if tr_name == str(station)[:-2] or tr_name == str(station)[:]:
                    traces_station = tr
                    es = obspy_compat.to_obspy_trace(traces_station)
                    streamData = station.net + '.' + station.sta + '.'\
                                             + station.loc + '.'\
                                             + station.comp\
                                             + '.D.'\
                                             + str(t2.year) + '.'\
                                             + str("%03d" % t2.julday)

                    st = obspy.Stream()
                    st.extend([es])
                    stream = ''
                    snr = ''
                    if station.loc == '--':
                        station.loc = ''

                    if len(st.get_gaps()) > 0:
                        st.merge(method=0,
                                 fill_value='interpolate',
                                 interpolation_samples=0)
                    snr_trace = traces_station.chop(tmin=traces_station.tmin,
                                                    tmax=traces_station.tmin +
                                                    ttime - 20.,
                                                    inplace=False)
                    snr = num.var(snr_trace.ydata)
                    stream = self.filterWaveform(st)

                    xname = os.path.join(self.AF, (streamData + '_all.mseed'))
                    stream.write(xname, format='MSEED')
                    stream.trim(tw['xcorrstart'], tw['xcorrend'])
                    found = True
                    return stream, snr

        if found is False:
            print('Waveform missing!', tr_name, str(station))
Esempio n. 4
0
    def test_load(self):
        fpath = common.test_data_file('test1.cube')

        traces_h = io.load(fpath, getdata=False, format='detect')
        traces_d = io.load(fpath, getdata=True, format='detect')

        mimas = [(30572, 87358), (46168, 80639), (53107, 73119)]

        for tr_h, tr_d, (mi, ma) in zip(traces_h, traces_d, mimas):
            assert tr_h.tmin == tr_d.tmin
            assert tr_h.tmax == tr_d.tmax
            assert tr_d.ydata.min() == mi
            assert tr_d.ydata.max() == ma
Esempio n. 5
0
    def call(self):
        """Main work routine of the snuffling."""

        self.cleanup()

        view = self.get_viewer()
        pile = self.get_pile()

        tmin, tmax = view.get_time_range()
        if self.useevent:
            markers = view.selected_markers()
            if len(markers) != 1:
                self.fail("Exactly one marker must be selected.")
            marker = markers[0]
            if not isinstance(marker, EventMarker):
                self.fail("An event marker must be selected.")

            ev = marker.get_event()

            lat, lon = ev.lat, ev.lon
        else:
            lat, lon = self.lat, self.lon

        data = iris_ws.ws_station(
            lat=lat, lon=lon, minradius=self.minradius, maxradius=self.maxradius, timewindow=(tmin, tmax), level="chan"
        )

        stations = iris_ws.grok_station_xml(data, tmin, tmax)
        networks = set([s.network for s in stations])

        t2s = util.time_to_str
        dir = self.tempdir()
        fns = []
        for net in networks:
            nstations = [s for s in stations if s.network == net]
            selection = sorted(iris_ws.data_selection(nstations, tmin, tmax))
            if selection:
                for x in selection:
                    logger.info("Adding data selection: %s.%s.%s.%s %s - %s" % (tuple(x[:4]) + (t2s(x[4]), t2s(x[5]))))

                try:
                    d = iris_ws.ws_bulkdataselect(selection)
                    fn = pjoin(dir, "data-%s.mseed" % net)
                    f = open(fn, "w")
                    f.write(d)
                    f.close()
                    fns.append(fn)

                except urllib2.HTTPError:
                    pass

        all_traces = []
        for fn in fns:
            try:
                traces = list(io.load(fn))

                all_traces.extend(traces)

            except io.FileLoadError, e:
                logger.warning("File load error, %s" % e)
Esempio n. 6
0
    def testReadSeisan(self):
        fpath = common.test_data_file('test.seisan_waveform')
        i = 0
        for tr in io.load(fpath, format='seisan'):
            i += 1

        assert i == 39
Esempio n. 7
0
    def testReadGSE1(self):
        fpath = common.test_data_file('test1.gse1')
        i = 0
        for tr in io.load(fpath, format='detect'):
            i += 1

        assert i == 19
Esempio n. 8
0
def FileFormatConversion_NoStack():

    print('Convert the file format from SAC into MiniSEED:')
    for f in tqdm(glob(join(middle_save, year + '*', 'No.*', '*.SAC_RESP'))):
        cmd = "saclst nzyear nzjday nzhour nzmin nzsec nzmsec b e f %s" % (f)
        junk, kzyy, kzjd, kzhou, kzmin, kzsec, kzmsec, b, e = os.popen(
            cmd).read().split()
        kztime = UTCDateTime(year=int(kzyy),
                             julday=int(kzjd),
                             hour=int(kzhou),
                             minute=int(kzmin),
                             second=int(kzsec),
                             microsecond=(int(kzmsec) * 1000))
        btime = kztime + float(b)
        etime = kztime + float(e)
        byear = btime.year
        bmon = btime.month
        bday = btime.day
        bhour = btime.hour
        bmin = btime.minute
        bsec = btime.second
        eyear = etime.year
        emon = etime.month
        eday = etime.day
        ehour = etime.hour
        emin = etime.minute
        esec = etime.second
        traces = io.load(f, format='sac')
        out_filename = f + '.mseed'
        io.save(traces, out_filename)
        number = basename(f).split('.')[1]
        net = basename(f).split('.')[2]
        sta = basename(f).split('.')[3]
        cha = basename(f).split('.')[5]
        y = basename(f).split('.')[0][0:4]
        jday = basename(f).split('.')[0][4:7]
        name = 'waveform_%s_%s__%s_%d-%02d-%02d_%02d-%02d-%02d_%d-%02d-%02d_%02d-%02d-%02d_%s_%s.mseed' % (
            net, sta, cha, byear, bmon, bday, bhour, bmin, bsec, eyear, emon,
            eday, ehour, emin, esec, number, jday)
        cmd = 'mv %s %s' % (out_filename, name)
        os.system(cmd)

    print('Reattribute the MiniSEED files according to the excitation time:')
    for f in glob(join(dire, '*.mseed')):
        filename = basename(f)
        datetime = filename.split('_')[5].split('-')[0] + filename.split(
            '_')[10].split('.')[0]
        sequence = filename.split('_')[9]
        exit_flag = False
        for d in glob(join(middle_save, year + '*')):
            date = basename(d)
            for dd in glob(join(d, 'No.*')):
                seq = basename(dd).split('.')[1]
                if int(datetime) == int(date) and int(sequence) == int(seq):
                    cmd = 'mv %s %s' % (f, dd)
                    os.system(cmd)
                    exit_flag = True
                    break
            if exit_flag:
                break
Esempio n. 9
0
    def testReadGSE1(self):
        fpath = common.test_data_file('test1.gse1')
        i = 0
        for tr in io.load(fpath, format='detect'):
            i += 1

        assert i == 19
Esempio n. 10
0
    def testReadSeisan(self):
        fpath = common.test_data_file('test.seisan_waveform')
        i = 0
        for tr in io.load(fpath, format='seisan'):
            i += 1

        assert i == 39
Esempio n. 11
0
    def test_load(self):
        fpath = common.test_data_file('test1.cube')

        traces_h = io.load(fpath, getdata=False, format='detect')
        traces_d = io.load(fpath, getdata=True, format='detect')

        mimas = [
            (30572, 87358),
            (46168, 80639),
            (53107, 73119)]

        for tr_h, tr_d, (mi, ma) in zip(traces_h, traces_d, mimas):
            assert tr_h.tmin == tr_d.tmin
            assert tr_h.tmax == tr_d.tmax
            assert tr_d.ydata.min() == mi
            assert tr_d.ydata.max() == ma
Esempio n. 12
0
    def testReadKan(self):
        fpath = common.test_data_file('01.kan')
        i = 0
        for tr in io.load(fpath, format='kan'):
            i += 1

        assert i == 1
Esempio n. 13
0
    def load_headers(self, mtime=None):
        logger.debug('loading headers from file: %s' % self.abspath)
        if mtime is None:
            self.mtime = os.stat(self.abspath)[8]

        def kgen(tr):
            return (tr.mtime, tr.tmin, tr.tmax) + tr.nslc_id

        self.remove(self.traces)
        ks = set()
        for tr in io.load(self.abspath,
                          format=self.format,
                          getdata=False,
                          substitutions=self.substitutions):

            k = kgen(tr)
            if k not in ks:
                ks.add(k)
                self.traces.append(tr)
                tr.file = self

        self.add(self.traces)

        self.data_loaded = False
        self.data_use_count = 0
def restitute_evalresp(tr_fn):
    traces = io.load(tr_fn)
    out_traces = []
    for tr in traces:
        try:
            try:
                evalresp = trace.Evalresp(respfile=evalresps['%s.%s'%(tr.station, tr.channel)],
                                          nslc_id=tr.nslc_id,
                                          target='dis')

            except KeyError:
                print 'skip ', '.'.join(tr.nslc_id[1:])
                continue

            if tr.station=='nkc' or tr.station=='zhc':
                t_taper = 30
                f_taper = (0.05, 0.08, 50., 75.),     # frequency domain taper in [hz]
            else:
                t_taper = 5.
                f_taper = (0.3, 0.6, 50., 75.),     # frequency domain taper in [hz]

            displacement =  tr.transfer(
                t_taper,                       # rise and fall of time domain taper in [s]
                *f_taper,     # frequency domain taper in [hz]
                transfer_function=evalresp, 
                invert=True)

        except trace.TraceTooShort:
            continue
        out_traces.append(displacement)
    tr_fn = tr_fn.replace(inputdir, outputdir)
    print tr_fn
    io.save(out_traces, tr_fn)

    del traces
Esempio n. 15
0
    def load_data(self, force=False):
        file_changed = False
        if not self.data_loaded or force:
            logger.debug('loading data from file: %s' % self.abspath)
            
            for itr, tr in enumerate(io.load(self.abspath, format=self.format, getdata=True, substitutions=self.substitutions)):
                if itr < len(self.traces):
                    xtr = self.traces[itr]
                    if xtr.mtime != tr.mtime or xtr.tmin != tr.tmin or xtr.tmax != tr.tmax:
                        logger.debug('file may have changed since last access (trace number %i has changed): %s' % (itr, self.abspath))
                        self.remove(xtr)
                        self.traces.remove(xtr)
                        xtr.file = None
                        self.traces.append(tr)
                        self.add(tr)
                        tr.file = self
                        file_changed = True
                    else:
                        xtr.ydata = tr.ydata

                else:
                    self.traces.add(tr)
                    self.add(tr)
                    logger.debug('file may have changed since last access (new trace found): %s' % self.abspath)
                    file_changed = True
            self.data_loaded = True
        return file_changed
Esempio n. 16
0
    def testWriteRead(self):
        now = time.time()
        n = 10
        deltat = 0.1
        
        networks = [ rn(2) for i in range(5) ]
        
        traces1 = [ trace.Trace(rc(networks), rn(4), rn(2), rn(3), tmin=now+i*deltat*n*2, deltat=deltat, ydata=num.arange(n, dtype=num.int32), mtime=now)
            for i in range(3) ]
            
        tempdir = tempfile.mkdtemp()

        for format in ('mseed', 'sac', 'yaff'):
            fns = io.save(traces1, pjoin(tempdir, '%(network)s_%(station)s_%(location)s_%(channel)s'), format=format)

            for fn in fns:
                assert io.detect_format(fn) == format

            traces2 = []
            for fn in fns:
                traces2.extend(io.load(fn, format='detect'))
                
            for tr in traces1:
                assert tr in traces2, 'failed for format %s' % format
                
            for fn in fns:
                os.remove(fn)

        shutil.rmtree(tempdir)
Esempio n. 17
0
    def load_headers(self, mtime=None):
        logger.debug('loading headers from file: %s' % self.abspath)
        if mtime is None:
            self.mtime = os.stat(self.abspath)[8]

        def kgen(tr):
            return (tr.mtime, tr.tmin, tr.tmax) + tr.nslc_id

        self.remove(self.traces)
        ks = set()
        for tr in io.load(self.abspath,
                          format=self.format,
                          getdata=False,
                          substitutions=self.substitutions):

            k = kgen(tr)
            if k not in ks:
                ks.add(k)
                self.traces.append(tr)
                tr.file = self

        self.add(self.traces)

        self.data_loaded = False
        self.data_use_count = 0
Esempio n. 18
0
    def testReadKan(self):
        fpath = common.test_data_file('01.kan')
        i = 0
        for tr in io.load(fpath, format='kan'):
            i += 1

        assert i == 1
Esempio n. 19
0
    def call(self):
        '''Main work routine of the snuffling.'''
        
        self.cleanup()

        view = self.get_viewer()
        pile = self.get_pile()

        tmin, tmax = view.get_time_range()
        if self.useevent:
            markers = view.selected_markers()
            if len(markers) != 1:
                self.fail('Exactly one marker must be selected.')
            marker = markers[0]
            if not isinstance(marker, EventMarker):
                self.fail('An event marker must be selected.')

            ev = marker.get_event()
            
            lat, lon = ev.lat, ev.lon
        else:
            lat, lon = self.lat, self.lon
        
        print lat, lon, self.minradius, self.maxradius, util.time_to_str(tmin), util.time_to_str(tmax)

        data = iris_ws.ws_station(lat=lat, lon=lon, minradius=self.minradius, maxradius=self.maxradius, 
                                                     timewindow=(tmin,tmax), level='chan' )
        stations = iris_ws.grok_station_xml(data, tmin, tmax)
        networks = set( [ s.network for s in stations ] )
        
        dir = self.tempdir()
        fns = []
        for net in networks:
            nstations = [ s for s in stations if s.network == net ]
            selection = sorted(iris_ws.data_selection( nstations, tmin, tmax ))
            if selection:
                for x in selection:
                    print x
                
                try:
                    d = iris_ws.ws_bulkdataselect(selection)
                    fn = pjoin(dir,'data-%s.mseed' % net) 
                    f = open(fn, 'w')
                    f.write(d)
                    f.close()
                    fns.append(fn)
                except urllib2.HTTPError:
                    pass

        newstations = []
        for sta in stations:
            if not view.has_station(sta):
                print sta
                newstations.append(sta)

        view.add_stations(newstations)
        for fn in fns:
            traces = list(io.load(fn))
            self.add_traces(traces)
Esempio n. 20
0
    def testReadGcf(self):
        fpath = common.test_data_file('test.gcf')

        i = 0
        for tr in io.load(fpath, format='gcf'):
            i += 1

        assert i == 1
Esempio n. 21
0
    def testReadSEGY(self):
        fpath = common.test_data_file('test2.segy')
        i = 0
        for tr in io.load(fpath, format='segy'):
            assert tr.meta['orfield_num'] == 1111
            i += 1

        assert i == 24
Esempio n. 22
0
    def testReadCSS(self):
        wfpath = common.test_data_file('test_css1.w')  # noqa
        fpath = common.test_data_file('test_css.wfdisc')
        i = 0
        for tr in io.load(fpath, format='css'):
            i += 1

        assert i == 1
Esempio n. 23
0
 def testMSeedRecordLength(self, tr):
     for exp in range(8, 20):
         with NTF(prefix='pyrocko') as f:
             tempfn = f.name
             io.save(tr, tempfn, record_length=2**exp)
             assert os.stat(tempfn).st_size / 2**exp % 1. == 0.
             tr2 = io.load(tempfn)[0]
             assert tr == tr2
Esempio n. 24
0
    def testReadCSS(self):
        wfpath = common.test_data_file('test_css1.w')  # noqa
        fpath = common.test_data_file('test_css.wfdisc')
        i = 0
        for tr in io.load(fpath, format='css'):
            i += 1

        assert i == 1
Esempio n. 25
0
    def testReadSEGY(self):
        fpath = common.test_data_file('test2.segy')
        i = 0
        for tr in io.load(fpath, format='segy'):
            assert tr.meta['orfield_num'] == 1111
            i += 1

        assert i == 24
Esempio n. 26
0
    def testReadGcf(self):
        fpath = common.test_data_file('test.gcf')

        i = 0
        for tr in io.load(fpath, format='gcf'):
            i += 1

        assert i == 1
Esempio n. 27
0
    def readWaveformsPicker_pyrocko(self, station, tw, Origin, ttime):

        obspy_compat.plant()
        cfg = ConfigObj(dict=self.Config)
        t2 = UTCDateTime(self.Origin.time)
        sdspath = os.path.join(self.EventPath, 'data')
        if cfg.quantity() == 'displacement':
            traces = io.load(self.EventPath + '/data/traces_restituted.mseed')
        else:
            traces = io.load(self.EventPath + '/data/traces.mseed')
        for tr in traces:
            tr_name = str(tr.network + '.' + tr.station + '.' + tr.location +
                          '.' + tr.channel[:3])
            if tr_name == str(station):
                traces_station = tr

                es = obspy_compat.to_obspy_trace(traces_station)
                streamData = station.net + '.' + station.sta + '.' + station.loc + '.' + station.comp + '.D.' + str(
                    t2.year) + '.' + str("%03d" % t2.julday)

                entry = os.path.join(sdspath, station.net, station.sta,
                                     station.comp + '.D', streamData)

                #stl = es.trim(starttime=tw['start'], endtime=tw['end'])
                st = obspy.Stream()
                st.extend([es])
                stream = ''
                snr = ''

                if station.loc == '--':
                    station.loc = ''

                if len(st.get_gaps()) > 0:
                    st.merge(method=0,
                             fill_value='interpolate',
                             interpolation_samples=0)
                #snr  = self.signoise(st[0], ttime, entry)
                stream = self.filterWaveform(st)

                xname = os.path.join(self.AF, (streamData + '_all.mseed'))
                stream.trim(tw['xcorrstart'], tw['xcorrend'])
                return stream

            else:
                pass
Esempio n. 28
0
    def test_ahfull_kiwi(self):
        setup = load(
            filename=common.test_data_file('test_ahfull_kiwi_setup.yaml'))
        trs_ref = io.load(
            common.test_data_file('test_ahfull_kiwi_traces.mseed'))

        for i, s in enumerate(setup.setups):
            d3d = math.sqrt(s.x[0]**2 + s.x[1]**2 + s.x[2]**2)

            tlen = d3d / s.vs * 2

            n = int(num.round(tlen / s.deltat))

            out_x = num.zeros(n)
            out_y = num.zeros(n)
            out_z = num.zeros(n)

            ahfullgreen.add_seismogram(s.vp, s.vs, s.density, 1000000.0,
                                       1000000.0, s.x, s.f, s.m6,
                                       'displacement', s.deltat, 0., out_x,
                                       out_y, out_z, ahfullgreen.Gauss(s.tau))

            trs = []
            for out, comp in zip([out_x, out_y, out_z], 'NED'):
                tr = trace.Trace('',
                                 'S%03i' % i,
                                 'P',
                                 comp,
                                 deltat=s.deltat,
                                 tmin=0.0,
                                 ydata=out)

                trs.append(tr)

            trs2 = []

            for cha in 'NED':

                t1 = g(trs, 'S%03i' % i, cha)
                t2 = g(trs_ref, 'S%03i' % i, cha)

                tmin = max(t1.tmin, t2.tmin)
                tmax = min(t1.tmax, t2.tmax)

                t1 = t1.chop(tmin, tmax, inplace=False)
                t2 = t2.chop(tmin, tmax, inplace=False)

                trs2.append(t2)

                d = 2.0 * num.sum((t1.ydata - t2.ydata)**2) / \
                    (num.sum(t1.ydata**2) + num.sum(t2.ydata**2))

                if d >= 0.02:
                    print(d)
                    # trace.snuffle([t1, t2])

                assert d < 0.02
Esempio n. 29
0
 def testMSeedRecordLength(self):
     c = '12'
     tr = trace.Trace(c, c, c, c, ydata=num.zeros(10))
     for exp in range(8, 20):
         tempfn = tempfile.mkstemp()[1]
         io.save(tr, tempfn, record_length=2**exp)
         assert os.stat(tempfn).st_size == 2**exp
         tr2 = io.load(tempfn)[0]
         assert tr2.data_len() == 10
         assert num.all(tr2.get_ydata() == 0.0)
    def test_ahfull_kiwi(self):
        setup = load(filename=common.test_data_file(
            'test_ahfull_kiwi_setup.yaml'))
        trs_ref = io.load(common.test_data_file(
            'test_ahfull_kiwi_traces.mseed'))

        for i, s in enumerate(setup.setups):
            d3d = math.sqrt(s.x[0]**2 + s.x[1]**2 + s.x[2]**2)

            tlen = d3d / s.vs * 2

            n = int(num.round(tlen / s.deltat))

            out_x = num.zeros(n)
            out_y = num.zeros(n)
            out_z = num.zeros(n)

            ahfullgreen.add_seismogram(
                s.vp, s.vs, s.density, 1000000.0, 1000000.0, s.x, s.f, s.m6,
                'displacement',
                s.deltat, 0.,
                out_x, out_y, out_z,
                ahfullgreen.Gauss(s.tau))

            trs = []
            for out, comp in zip([out_x, out_y, out_z], 'NED'):
                tr = trace.Trace(
                    '', 'S%03i' % i, 'P', comp,
                    deltat=s.deltat, tmin=0.0, ydata=out)

                trs.append(tr)

            trs2 = []

            for cha in 'NED':

                t1 = g(trs, 'S%03i' % i, cha)
                t2 = g(trs_ref, 'S%03i' % i, cha)

                tmin = max(t1.tmin, t2.tmin)
                tmax = min(t1.tmax, t2.tmax)

                t1 = t1.chop(tmin, tmax, inplace=False)
                t2 = t2.chop(tmin, tmax, inplace=False)

                trs2.append(t2)

                d = 2.0 * num.sum((t1.ydata - t2.ydata)**2) / \
                    (num.sum(t1.ydata**2) + num.sum(t2.ydata**2))

                if d >= 0.02:
                    print(d)
                    # trace.snuffle([t1, t2])

                assert d < 0.02
Esempio n. 31
0
def process(args, scenario_folder, n_tests=1, show=True):
    nstart = 8
    array_centers = []
    from .guesstimate_depth_v02 import PlotSettings, plot

    events = []
    stations = []
    mod = insheim_layered_model()

    for i in range(nstart, nstart+1):
        i = 8
        scenario_folder = "scenarios/"
        print("%s/scenario_%s/event.txt" % (scenario_folder, i))

        events.append(model.load_events("%s/scenario_%s/event.txt" % (scenario_folder, i))[0])
        stations.append(model.load_stations("%s/scenario_%s/stations.pf" % (scenario_folder, i)))
        traces = io.load(pjoin("%sscenario_%s/" % (scenario_folder, i), 'traces.mseed'))

        event = events[0]
        stations = stations[0]
        min_dist = min(
            [ortho.distance_accurate50m(s, event) for s in stations])
        max_dist = max(
            [ortho.distance_accurate50m(s, event) for s in stations])
        tmin = CakeTiming(phase_selection='first(p|P|PP)-10', fallback_time=0.001)
        tmax = CakeTiming(phase_selection='first(p|P|PP)+52', fallback_time=1000.)
        timing=(tmin, tmax)

        fns = ['.']


        array_id = "INS"


        settings_fn = pjoin("%sscenario_%s/" % (scenario_folder, i), 'plot_settings.yaml')
        settings = PlotSettings.from_argument_parser(args)

        if not settings.trace_filename:
            settings.trace_filename = pjoin("%sscenario_%s/" % (scenario_folder, i), 'beam.mseed')
        if not settings.station_filename:
            fn_array_center = pjoin("%sscenario_%s/" % (scenario_folder, i), 'array_center.pf')
            settings.station_filename = fn_array_center
            station = model.load_stations(fn_array_center)

            settings.store_id = 'landau_100hz'


        settings.event_filename = pjoin("%sscenario_%s/" % (scenario_folder, i), "event.txt")
        settings.save_as = pjoin("%sscenario_%s/" % (scenario_folder, i), "depth_%(array-id)s.png")
        plot(settings)
        if args.overwrite_settings:
            settings.dump(filename=settings_fn)
        if show is True:
            plt.show()
Esempio n. 32
0
    def test_to_obspy_trace(self):
        traces = io.load(common.test_data_file('test1.mseed'))
        for tr in traces:
            obs_tr = tr.to_obspy_trace()

            assert isinstance(obs_tr, obspy.Trace)
            assert obs_tr.data.size == tr.data_len()

            obs_stats = obs_tr.stats
            for attr in ('network', 'station', 'location', 'channel'):
                assert obs_stats.__getattr__(attr) == tr.__getattribute__(attr)
Esempio n. 33
0
    def testReadSUDS(self):
        fpath = common.test_data_file('test.suds')
        i = 0
        for tr in io.load(fpath, format='detect'):
            i += 1

        assert i == 251

        stations = suds.load_stations(fpath)

        assert len(stations) == 91
Esempio n. 34
0
    def testReadSUDS(self):
        fpath = common.test_data_file('test.suds')
        i = 0
        for tr in io.load(fpath, format='detect'):
            i += 1

        assert i == 251

        stations = suds.load_stations(fpath)

        assert len(stations) == 91
Esempio n. 35
0
    def readWaveformsPicker_colos(self, station, tw, Origin, ttime):

        obspy_compat.plant()
        pjoin = os.path.join
        Config = self.Config
        cfg = ConfigObj(dict=Config)
        Syn_in = self.Syn_in
        syn_in = SynthCfg(Syn_in)

        t2 = UTCDateTime(self.Origin.time)
        sdspath = os.path.join(self.EventPath, 'data')
        traces = io.load(cfg.colosseo_scenario_yml()[:-12] + 'scenario.mseed')

        for tr in traces:
            tr_name = str(tr.network + '.' + tr.station + '.' + tr.location +
                          '.' + tr.channel[:3])
            if tr_name == str(station):
                traces_station = tr

                es = obspy_compat.to_obspy_trace(traces_station)
                streamData = station.net + '.' + station.sta + '.' + station.loc + '.' + station.comp + '.D.' + str(
                    t2.year) + '.' + str("%03d" % t2.julday)

                entry = os.path.join(sdspath, station.net, station.sta,
                                     station.comp + '.D', streamData)

                #stl = es.trim(starttime=tw['start'], endtime=tw['end'])
                st = obspy.Stream()
                st.extend([es])
                stream = ''
                snr = ''

                if station.loc == '--':
                    station.loc = ''

                if len(st.get_gaps()) > 0:
                    st.merge(method=0,
                             fill_value='interpolate',
                             interpolation_samples=0)
                #snr  = self.signoise(st[0], ttime, entry)
                snr_trace = traces_station.chop(tmin=traces_station.tmin,
                                                tmax=traces_station.tmin +
                                                ttime - 20.,
                                                inplace=False)
                snr = num.var(snr_trace.ydata)
                stream = self.filterWaveform(st)

                xname = os.path.join(self.AF, (streamData + '_all.mseed'))
                stream.write(xname, format='MSEED')
                stream.trim(tw['xcorrstart'], tw['xcorrend'])
                return stream

            else:
                pass
Esempio n. 36
0
    def test_to_obspy_trace(self):
        traces = io.load(common.test_data_file('test1.mseed'))
        for tr in traces:
            obs_tr = tr.to_obspy_trace()

            assert isinstance(obs_tr, obspy.Trace)
            assert obs_tr.data.size == tr.data_len()

            obs_stats = obs_tr.stats
            for attr in ('network', 'station', 'location', 'channel'):
                assert obs_stats.__getattr__(attr) == tr.__getattribute__(attr)
Esempio n. 37
0
    def load_data(self, force=False):
        file_changed = False
        if not self.data_loaded or force:
            logger.debug('loading data from file: %s' % self.abspath)

            def kgen(tr):
                return (tr.mtime, tr.tmin, tr.tmax) + tr.nslc_id

            traces_ = io.load(self.abspath,
                              format=self.format,
                              getdata=True,
                              substitutions=self.substitutions)

            # prevent adding duplicate snippets from corrupt mseed files
            k_loaded = set()
            traces = []
            for tr in traces_:
                k = kgen(tr)
                if k not in k_loaded:
                    k_loaded.add(k)
                    traces.append(tr)

            k_current_d = dict((kgen(tr), tr) for tr in self.traces)
            k_current = set(k_current_d)
            k_new = k_loaded - k_current
            k_delete = k_current - k_loaded
            k_unchanged = k_current & k_loaded

            for tr in self.traces[:]:
                if kgen(tr) in k_delete:
                    self.remove(tr)
                    self.traces.remove(tr)
                    tr.file = None
                    file_changed = True

            for tr in traces:
                if kgen(tr) in k_new:
                    tr.file = self
                    self.traces.append(tr)
                    self.add(tr)
                    file_changed = True

            for tr in traces:
                if kgen(tr) in k_unchanged:
                    ctr = k_current_d[kgen(tr)]
                    ctr.ydata = tr.ydata

            self.data_loaded = True

        if file_changed:
            logger.debug('reloaded (file may have changed): %s' % self.abspath)

        return file_changed
Esempio n. 38
0
    def testMSeedSTEIM(self, tr):
        with NTF(prefix='pyrocko') as f1:
            io.save(tr, f1.name, steim=1)
            tr1 = io.load(f1.name)[0]

            with NTF(prefix='pyrocko') as f2:
                io.save(tr, f2.name, steim=1)
                tr2 = io.load(f2.name)[0]

                # STEIM compression only affects int32
                if tr.ydata.dtype is num.int32:
                    assert op.getsize(f1.name) != op.getsize(f2.name)

        assert tr == tr1
        assert tr == tr2
        assert tr1 == tr2

        for steim in (0, 3):
            with NTF(prefix='pyrocko') as f:
                with self.assertRaises(FileSaveError):
                    io.save(tr, f.name, steim=steim)
Esempio n. 39
0
def readWaveformsPyrocko_restituted(stationlist, w, EventPath, Origin,
                                    desired):
    Wdict = OrderedDict()
    if desired is 'Z':
        try:
            traces = io.load(EventPath + '/data/traces_rotated.mseed')
        except Exception:
            traces = io.load(EventPath + '/data/traces_restituted.mseed')
    else:
        traces = io.load(EventPath + '/data/traces_rotated.mseed')

    traces_dict = []
    for tr in traces:
        for il in stationlist:
            tr_name = str(tr.network + '.' + tr.station + '.' + tr.location +
                          '.')
            if (tr_name == str(il) and tr.channel[-1] == desired) or (
                    tr_name == str(il)[:-3] and tr.channel[-1] == desired):

                Wdict[il.getName()] = tr

    return Wdict
Esempio n. 40
0
def add_white_noise(synthetic_traces, scale=2e-8, scale_spectral='False'):

    if scale_spectral == 'True':
        noise_refrence = io.load('bfo_150901_0411.bhz')
        scale = num.max(num.abs(noise_refrence.spectrum()))
    for tr in synthetic_traces:

        nsamples = len(tr.ydata)
        randdata = num.random.normal(size=nsamples) * num.min(abs(tr.ydata))
        white_noise = trace.Trace(deltat=tr.deltat,
                                  tmin=tr.tmin,
                                  ydata=randdata)
        tr.add(white_noise)
Esempio n. 41
0
def readWaveformsPyrocko(stationlist, w, EventPath, Origin, desired):
    Wdict = OrderedDict()
    traces = io.load(EventPath + '/data/traces_velocity.mseed')
    traces_dict = []
    for tr in traces:
        for il in stationlist:
            tr_name = str(tr.network + '.' + tr.station + '.' + tr.location +
                          '.')
            if (tr_name == str(il) and tr.channel[-1] == desired) or (
                    tr_name == str(il)[:-3] and tr.channel[-1] == desired):

                Wdict[il.getName()] = tr
    return Wdict
Esempio n. 42
0
    def load_data(self, force=False):
        file_changed = False
        if not self.data_loaded or force:
            logger.debug('loading data from file: %s' % self.abspath)

            def kgen(tr):
                return (tr.mtime, tr.tmin, tr.tmax) + tr.nslc_id

            traces_ = io.load(self.abspath, format=self.format, getdata=True,
                              substitutions=self.substitutions)

            # prevent adding duplicate snippets from corrupt mseed files
            k_loaded = set()
            traces = []
            for tr in traces_:
                k = kgen(tr)
                if k not in k_loaded:
                    k_loaded.add(k)
                    traces.append(tr)

            k_current_d = dict((kgen(tr), tr) for tr in self.traces)
            k_current = set(k_current_d)
            k_new = k_loaded - k_current
            k_delete = k_current - k_loaded
            k_unchanged = k_current & k_loaded

            for tr in self.traces[:]:
                if kgen(tr) in k_delete:
                    self.remove(tr)
                    self.traces.remove(tr)
                    tr.file = None
                    file_changed = True

            for tr in traces:
                if kgen(tr) in k_new:
                    tr.file = self
                    self.traces.append(tr)
                    self.add(tr)
                    file_changed = True

            for tr in traces:
                if kgen(tr) in k_unchanged:
                    ctr = k_current_d[kgen(tr)]
                    ctr.ydata = tr.ydata

            self.data_loaded = True

        if file_changed:
            logger.debug('reloaded (file may have changed): %s' % self.abspath)

        return file_changed
Esempio n. 43
0
    def load_headers(self, mtime=None):
        logger.debug('loading headers from file: %s' % self.abspath)
        if mtime is None:
            self.mtime = os.stat(self.abspath)[8]
        
        self.remove(self.traces)
        for tr in io.load(self.abspath, format=self.format, getdata=False, substitutions=self.substitutions):
            self.traces.append(tr)
            tr.file = self

        self.add(self.traces)

        self.data_loaded = False
        self.data_use_count = 0
Esempio n. 44
0
def gen_white_noise(synthetic_traces, scale=2e-8, scale_spectral='False'):

    if scale_spectral == 'True':
        noise_refrence = io.load('bfo_150901_0411.bhz')
        scale = num.max(num.abs(noise_refrence.spectrum()))
    synthetic_traces_empty = copy.deepcopy(synthetic_traces)
    for tr in synthetic_traces_empty:
        max_scale = num.max(tr.ydata)
        min_scale = num.min(tr.ydata)
        scale = num.random.uniform(min_scale, max_scale)
        nsamples = len(tr.ydata)
        tr.ydata = tr.ydata * 0.
        randdata = num.random.normal(size=nsamples) * scale
        tr.ydata = randdata

    return synthetic_traces_empty
    def readWaveformsCross_colesseo(self, station, tw, ttime, cfg_yaml):
        obspy_compat.plant()
        Config = self.Config
        cfg = ConfigObj(dict=Config)
        t2 = UTCDateTime(self.Origin.time)

        traces = io.load(cfg.colosseo_scenario_yml()[:-12]+'scenario.mseed')

        for tr in traces:
            tr_name = str(tr.network+'.'+tr.station+'.'+tr.location+'.'
                                    + tr.channel[:3])
            if tr_name == str(station):
                    traces_station = tr

                    es = obspy_compat.to_obspy_trace(traces_station)
                    streamData = station.net + '.' + station.sta + '.'\
                                             + station.loc + '.'\
                                             + station.comp + '.D.'\
                                             + str(t2.year) + '.'\
                                             + str("%03d" % t2.julday)

                    st = obspy.Stream()
                    st.extend([es])
                    stream = ''
                    snr = ''

                    if station.loc == '--':
                        station.loc = ''

                    if len(st.get_gaps()) > 0:
                        st.merge(method=0, fill_value='interpolate',
                                 interpolation_samples=0)
                    snr_trace = traces_station.chop(tmin=traces_station.tmin,
                                                    tmax=traces_station.tmin +
                                                    ttime-20.,
                                                    inplace=False)
                    snr = num.var(snr_trace.ydata)
                    stream = self.filterWaveform(st, cfg_yaml)

                    xname = os.path.join(self.AF, (streamData+'_all.mseed'))
                    stream.write(xname, format='MSEED')
                    stream.trim(tw['xcorrstart'], tw['xcorrend'])
                    return stream, snr

            else:
                pass
Esempio n. 46
0
    def load_headers(self, mtime=None):
        logger.debug('loading headers from file: %s' % self.abspath)
        if mtime is None:
            self.mtime = os.stat(self.abspath)[8]

        self.remove(self.traces)
        for tr in io.load(self.abspath,
                          format=self.format,
                          getdata=False,
                          substitutions=self.substitutions):
            self.traces.append(tr)
            tr.file = self

        self.add(self.traces)

        self.data_loaded = False
        self.data_use_count = 0
def restitute_pz(tr_fn):
    traces = io.load(tr_fn)
    out_traces = []
    for tr in traces:
        try:
            try:
                zeros, poles, constant = pz.read_sac_zpk(pole_zeros['%s.%s'%(tr.station, tr.channel)])

            except keyerror:
                print 'skip ', '.'.join(tr.nslc_id[1:])
                continue

            zeros.append(0.0j)

            digitizer_gain = 1e6    
            constant *= digitizer_gain

            # for the conversion of hz-> iw:
            nzeros = len(zeros)
            npoles = len(poles)
            constant *= (2*num.pi)**(npoles-nzeros)

            if tr.station=='nkc' or tr.station=='zhc':
                constant *= normalization_factors[tr.station]
                t_taper = 30
                f_taper = (0.05, 0.08, 50., 75.),     # frequency domain taper in [hz]
            else:
                t_taper = 5.
                f_taper = (0.3, 0.6, 50., 75.),     # frequency domain taper in [hz]

            print tr.station, constant
            pz_transfer = trace.polezeroresponse(zeros, poles, constant)
            displacement =  tr.transfer(
                t_taper,                       # rise and fall of time domain taper in [s]
                *f_taper,     # frequency domain taper in [hz]
                transfer_function=pz_transfer, 
                invert=true)

        except trace.tracetooshort:
            continue
        out_traces.append(displacement)
    tr_fn = tr_fn.replace(inputdir, outputdir)
    print tr_fn
    io.save(out_traces, tr_fn)

    del traces
Esempio n. 48
0
 def get_traces_pyrocko(self, x,z):
     fns = self.dump_traces(x,z, format='mseed')
     traces = []
     for igm, fn in enumerate(fns):
         ig = igm+1
         if fn:
             for tr in io.load(fn):
                 ix = 1 + int(round((x-self.firstx)/self.dx))
                 iz = 1 + int(round((z-self.firstz)/self.dz))
                 gridx = self.firstx + (ix-1)*self.dx
                 gridz = self.firstz + (iz-1)*self.dz
                 sx = util.base36encode(ix)
                 sz = util.base36encode(iz)
                 tr.meta = {'x':gridx, 'z':gridz, 'ig':ig}
                 tr.set_codes(network=sz, station=sx, channel='%i' % ig)
                 traces.append(tr)
                 
     return traces
Esempio n. 49
0
    def benchmark_load(self):
        mode = {
            0: 'get time range',
            1: 'get gps only',
            2: 'get samples'}

        fpath = common.test_data_file('test2.cube')
        for irep in range(2):
            for loadflag in (0, 1, 2):
                f = open(fpath, 'r')
                t0 = time.time()
                header, data_arrays, gps_tags, nsamples, bookmarks = \
                    datacube_ext.load(f.fileno(), loadflag, 0, -1, None)

                f.close()
                t1 = time.time()
                print '%s: %10.3f' % (mode[loadflag], t1 - t0)

            t0 = time.time()
            trs = io.load(fpath, format='datacube')
            t1 = time.time()
            print 'with interpolation: %10.3f' % (t1 - t0)
            del trs
Esempio n. 50
0
 def testMSeedDetect(self):
     fpath = common.test_data_file('test2.mseed')
     io.load(fpath, format='detect')
    def download(self, event, directory='array_data', timing=None, length=None,
                 want='all', force=False, prefix=False, dump_config=False,
                 get_responses=False):
        """:param want: either 'all' or ID as string or list of IDs as strings
        """
        use = []
        #ts = {}
        unit = 'M'
        if all([timing, length]) is None:
            raise Exception('Define one of "timing" and "length"')
        prefix = prefix or ''
        directory = pjoin(prefix, directory)
        if not os.path.isdir(directory):
            os.mkdir(directory)
        pzresponses = {}
        logger.info('download data: %s at %sN %sE' % (
            event.name, event.lat, event.lon))
        for site, array_data_provder in self.providers.items():
            logger.info('requesting data from site %s' % site)
            for array_id, codes in array_data_provder.items():
                if array_id not in want and want != ['all']:
                    continue
                sub_directory = pjoin(directory, array_id)
                logger.info("%s" % array_id)
                codes = array_data_provder[array_id]
                if not isinstance(codes, list):
                    codes = [codes]
                selection = [
                    c + tuple((event.time, event.time+1000.)) for c in codes]
                logger.debug('selection: %s' % selection)
                try:
                #    if site=='bgr':
                #        st = ws.station(url='http://eida.bgr.de/', selection=selection)
                #    else:
                #        st = ws.station(site=site, selection=selection)
                    st = ws.station(site=site, selection=selection)
                except ws.EmptyResult as e:
                    logging.error('No results: %s %s. skip' % (e, array_id))
                    continue
                except ValueError as e:
                    logger.error(e)
                    logger.error('...skipping...')
                    continue

                stations = st.get_pyrocko_stations()
                min_dist = min(
                    [ortho.distance_accurate50m(s, event) for s in stations])
                max_dist = max(
                    [ortho.distance_accurate50m(s, event) for s in stations])

                mod = cake.load_model(crust2_profile=(event.lat, event.lon))
                if length:
                    tstart = 0.
                    tend = length
                elif timing:
                    tstart = timing[0].t(mod, (event.depth, min_dist))
                    tend = timing[1].t(mod, (event.depth, max_dist))
                selection = [
                    c + tuple((event.time + tstart, event.time + tend)
                              ) for c in codes]
                try:
                    d = ws.dataselect(site=site, selection=selection)
                    store.remake_dir(sub_directory, force)
                    store.remake_dir(pjoin(sub_directory, 'responses'), force)
                    fn = pjoin(sub_directory, 'traces.mseed')
                    with open(fn, 'w') as f:
                        f.write(d.read())
                        f.close()
                    if get_responses:
                        trs = io.load(fn, getdata=False)
                        logger.info('Request responses from %s' % site)
                        if progressbar:
                            pb = progressbar.ProgressBar(maxval=len(trs)).start()
                        for i_tr, tr in enumerate(trs):
                            try:
                                st = ws.station(
                                    site=site, selection=selection, level='response')
                                pzresponse = st.get_pyrocko_response(
                                    nslc=tr.nslc_id,
                                    timespan=(tr.tmin, tr.tmax),
                                    fake_input_units=unit)
                                pzresponse.regularize()
                            except fdsnstation.NoResponseInformation as e:
                                logger.warn("no response information: %s" % e)
                                pzresponse = None
                                pass
                            except fdsnstation.MultipleResponseInformation as e:
                                logger.warn("MultipleResponseInformation: %s" % e)
                                pzresponse = None
                                pass
                            pzresponses[tr.nslc_id] = pzresponse
                            pzresponses[tr.nslc_id].dump(filename=pjoin(
                                sub_directory,
                                'responses',
                                'resp_%s.yaml' % '.'.join(tr.nslc_id)))
                            if progressbar:
                                pb.update(i_tr)
                        if progressbar:
                            pb.finish()
                    model.dump_stations(
                        stations, pjoin(sub_directory, 'stations.pf'))

                    if timing:
                        t = Timings(list(timing))
                        self.timings[array_id] = t
                    if array_id not in use and array_id not in self.use:
                        use.append(array_id)
                except ws.EmptyResult as e:
                    logging.error('%s on %s' % (e, array_id))

        self.use.extend(use)
Esempio n. 52
0
 def testReadSac2(self):
     fpath = common.test_data_file('test2.sac')
     tr = io.load(fpath, format='sac')[0]
     assert tr.location == ''
Esempio n. 53
0
    def call(self):
        '''Main work routine of the snuffling.'''

        self.cleanup()

        view = self.get_viewer()

        tmin, tmax = view.get_time_range()
        if self.useevent:
            markers = view.selected_markers()
            if len(markers) != 1:
                self.fail('Exactly one marker must be selected.')
            marker = markers[0]
            if not isinstance(marker, EventMarker):
                self.fail('An event marker must be selected.')

            ev = marker.get_event()

            lat, lon = ev.lat, ev.lon
        else:
            lat, lon = self.lat, self.lon

        site = self.datacenter.lower()
        try:
            kwargs = {}
            if site == 'iris':
                kwargs['matchtimeseries'] = True

            sx = fdsn_ws.station(
                site=site, latitude=lat, longitude=lon,
                minradius=self.minradius, maxradius=self.maxradius,
                startbefore=tmin, endafter=tmax, channel=self.channel_pattern,
                format='text', level='channel', includerestricted=False,
                **kwargs)

        except fdsn_ws.EmptyResult:
            self.fail('No stations matching given criteria.')

        stations = sx.get_pyrocko_stations()
        networks = set([s.network for s in stations])

        t2s = util.time_to_str
        dir = self.tempdir()
        fns = []
        for net in networks:
            nstations = [s for s in stations if s.network == net]
            selection = fdsn_ws.make_data_selection(nstations, tmin, tmax)
            if selection:
                for x in selection:
                    logger.info(
                        'Adding data selection: %s.%s.%s.%s %s - %s'
                        % (tuple(x[:4]) + (t2s(x[4]), t2s(x[5]))))

                try:
                    d = fdsn_ws.dataselect(site=site, selection=selection)
                    fn = pjoin(dir, 'data-%s.mseed' % net)
                    f = open(fn, 'w')
                    f.write(d.read())
                    f.close()
                    fns.append(fn)

                except fdsn_ws.EmptyResult:
                    pass

        all_traces = []
        for fn in fns:
            try:
                traces = list(io.load(fn))

                all_traces.extend(traces)

            except io.FileLoadError, e:
                logger.warning('File load error, %s' % e)
# write the incoming data stream to 'traces.mseed'
with open('traces.mseed', 'wb') as file:
    file.write(request_waveform.read())

# request meta data
request_response = fdsn.station(
    site='geofon', selection=selection, level='response')

# save the response in YAML and StationXML format
request_response.dump(filename='responses_geofon.yaml')
request_response.dump_xml(filename='responses_geofon.xml')

# Loop through retrieved waveforms and request meta information
# for each trace
traces = io.load('traces.mseed')
displacement = []
for tr in traces:
    polezero_response = request_response.get_pyrocko_response(
        nslc=tr.nslc_id,
        timespan=(tr.tmin, tr.tmax),
        fake_input_units='M')
    # *fake_input_units*: required for consistent responses throughout entire
    # data set

    # deconvolve transfer function
    restituted = tr.transfer(
        tfade=2.,
        freqlimits=(0.01, 0.1, 1., 2.),
        transfer_function=polezero_response,
        invert=True)
Esempio n. 55
0
from pyrocko import io

traces = io.load('test.mseed')
t = traces[0]
print 'original:', t

# extract a copy of a part of t
extracted = t.chop(t.tmin+10, t.tmax-10, inplace=False)
print 'extracted:', extracted

# in-place operation modifies t itself
t.chop(t.tmin+10, t.tmax-10)
print 'modified:', t
Esempio n. 56
0
WD = op.abspath(op.realpath(os.curdir))

os.chdir(mseed_path)

lo_mseeds  = glob.glob('*')

os.chdir(WD)

outpathname = 'corrected_traces'
outpath     = op.abspath(op.realpath(op.join('.',outpathname)))

if not op.exists(outpath):
    os.makedirs(outpath)

for F in lo_mseeds:
    in_fn  = op.abspath(op.realpath(op.join(mseed_path,F)))
    out_fn = op.abspath(op.realpath(op.join(outpath,F)))
    
    traces = io.load(in_fn)

    for tr in traces:
        stat = tr.station
        channel = tr.channel.upper()[-1]
        fac = ampl_dict[stat][channel] 
        tr.ydata = fac * tr.get_ydata() /10**9

        print F, stat, channel, fac
  
    io.save(traces,out_fn )
Esempio n. 57
0
 def testReadSac(self):
     fpath = common.test_data_file('test1.sac')
     tr = io.load(fpath, format='sac')[0]
     assert tr.meta['cmpaz'] == 0.0
     assert tr.meta['cmpinc'] == 0.0
Esempio n. 58
0
#!/usr/bin/env python

from pyrocko import io
import sys

for filename in sys.argv[1:]:
    traces = io.load(filename, format='sac')
    if filename.lower().endswith('.sac'):
        out_filename = filename[:-4] + '.mseed'
    else:
        out_filename = filename + '.mseed'

    io.save(traces, out_filename)