Beispiel #1
0
def stack(data, correlations, dt=-1, filters=None, period=24 * 3600, shift=None, onefile=False, yearfiles=False):
    #t1 = t1.__class__(t1.date)
    #t2 = t2.__class__(t2.date)
    log.info('Stack correlations: %s' % util.parameters())
    print 'Stack correlations... '
    if filters is None:
        filters = (None,)
    stack = Stream()
    last_year = None
    for correlation in ProgressBar()(correlations):
        for filter_ in filters:
            try:
                st = read(data.getX(correlation, '*', filter=filter_, period=period) + '.QHD')
            except Exception as err:
                log.warning('Could not load file, because:/n%s' % str(err))
            else:
                print correlation
                for some_traces in streamtimegen(st, dt=dt, start=None, shift=shift):
                    tr = some_traces.calculate('mean')
                    stack.append(tr)
                    this_year = (some_traces[0].stats.starttime).year
                    if last_year is None:
                        last_year = this_year
                    #if yearfiles and (some_traces[0].stats.starttime + period).julday == 1 and len(stack) > 0:
                    if yearfiles and this_year != last_year and len(stack) > 0:
                        data.writeX(stack, correlation, time=some_traces[0].stats.starttime - 365 * 24 * 3600, filter_=filter_, period=period, stack=(dt, shift))
                        last_year = this_year
                        stack = Stream()
                if not onefile:
                    if yearfiles:
                        time = some_traces[0].stats.starttime
                    else:
                        time = None
                    if len(stack) > 0:
                        data.writeX(stack, correlation, time=time, filter=filter_, period=period, stack=(dt, shift))
                    last_year = None
                    stack = Stream()

    if onefile:
        data.writeX(stack, ('all', 'all'), time=None, filter=filters[0], period=period, stack=(dt, shift))
from sito.data import IPOC
from obspy.core import UTCDateTime as UTC
import matplotlib.pyplot as plt
from sito.util.main import streamtimegen
from sito.stream import Stream
from progressbar import ProgressBar

data = IPOC()
t_day = UTC('2008-01-01')
station = 'PB01'

stream = data.getRawStreamFromClient(
    t_day, t_day + 24 * 3600, station, component='Z')
stream.setHI('filter', '')
stream.demean()
stream.filter2(0.5, 5)
stream.trim2(0, 5 * 3600)

auto = Stream()
for st in streamtimegen(stream, dt=60, start=None, shift=30, use_slice=True):
    tr = st[0].copy()
    tr.addZeros(60)
    tr.acorr(60)
    auto.append(tr)

print auto
auto.plotXcorr()
stream.plot(type='dayplot')

plt.show()
import matplotlib.pyplot as plt
from sito.util.main import streamtimegen
from sito.stream import Stream
from progressbar import ProgressBar

data = IPOC()
t_day = UTC('2008-01-01')
station = 'PB01'

stream = data.getRawStreamFromClient(t_day,
                                     t_day + 24 * 3600,
                                     station,
                                     component='Z')
stream.setHI('filter', '')
stream.demean()
stream.filter2(0.5, 5)
stream.trim2(0, 5 * 3600)

auto = Stream()
for st in streamtimegen(stream, dt=60, start=None, shift=30, use_slice=True):
    tr = st[0].copy()
    tr.addZeros(60)
    tr.acorr(60)
    auto.append(tr)

print auto
auto.plotXcorr()
stream.plot(type='dayplot')

plt.show()