Beispiel #1
0
def stack_day(data, correlations, dt=-1, start=None, onefile=False):
    #t1 = t1.__class__(t1.date)
    #t2 = t2.__class__(t2.date)
    log.info('Stack day correlations: %s' % util.parameters())
    if start is not None:
        dt_log = '%s-%s' % (dt, start)
    else:
        dt_log = dt
    stack = Stream()
    for correlation in correlations:
        try:
            days = read(data.getXDay(correlation, '*') + '.QHD')
        except Exception as err:
            log.warning('Could not load file, because:/n%s' % str(err))
        else:
            for somedays in streamdaygen(days, dt=dt, start=start):
                tr = somedays.calculate('mean')
                stack.append(tr)
            if not onefile:
                data.writeXDayStack(stack, correlation, dt_log)
                stack = Stream()
    if onefile:
        data.writeXDayStack(stack, ('all', 'all'), dt_log)
channels = 'WKI WDI WII'
#channels = 'WDI_10'
datafile = '/home/richter/Data/climate/2006-2012_%s_%s.npz'
output = '/home/richter/Results/IPOC/climate/%s.pdf'
calculate = False
show = False

if calculate:
    ipoc = IPOC()
    for station in stations.split():
        for channel in channels.split():
            stream = ipoc.getChannelFromClient('2006-01-01', '2013-01-01',
                                               station=station, channel=channel)
            data = []
            dates = []
            for day in streamdaygen(stream):
                day.merge()
                data.append(np.mean(day[0].data))
                st = day[0].stats.starttime
                et = day[0].stats.endtime
                dates.append(st + (et - st) / 2.)
            np.savez(datafile % (station, channel), dates=dates, data=data)
else:
    #http://stackoverflow.com/questions/7733693/matplotlib-overlay-plots-with-different-scales
    fig, ax = plt.subplots()
    axes = [ax, ax.twinx(), ax.twinx()]
    fig.subplots_adjust(right=0.75)
    axes[-1].spines['right'].set_position(('axes', 1.2))
    axes[-1].set_frame_on(True)
    axes[-1].patch.set_visible(False)
    #colors = ('green', 'red', 'blue')
datafile = '/home/richter/Data/climate/2006-2012_%s_%s.npz'
output = '/home/richter/Results/IPOC/climate/%s.pdf'
calculate = False
show = False

if calculate:
    ipoc = IPOC()
    for station in stations.split():
        for channel in channels.split():
            stream = ipoc.getChannelFromClient('2006-01-01',
                                               '2013-01-01',
                                               station=station,
                                               channel=channel)
            data = []
            dates = []
            for day in streamdaygen(stream):
                day.merge()
                data.append(np.mean(day[0].data))
                st = day[0].stats.starttime
                et = day[0].stats.endtime
                dates.append(st + (et - st) / 2.)
            np.savez(datafile % (station, channel), dates=dates, data=data)
else:
    #http://stackoverflow.com/questions/7733693/matplotlib-overlay-plots-with-different-scales
    fig, ax = plt.subplots()
    axes = [ax, ax.twinx(), ax.twinx()]
    fig.subplots_adjust(right=0.75)
    axes[-1].spines['right'].set_position(('axes', 1.2))
    axes[-1].set_frame_on(True)
    axes[-1].patch.set_visible(False)
    #colors = ('green', 'red', 'blue')