Ejemplo n.º 1
0
def calc_temp():
    station = "PB12"
    channel = "WKI"
    from sito.data import IPOC

    ipoc = IPOC()
    stream = ipoc.getChannelFromClient("2006-01-01", "2012-01-01", station=station, channel=channel)
    stream2 = stream.copy()
    day = stream[0].stats.starttime
    day2 = UTC(day.year, day.month, day.day)
    if day2 < day:
        day = day2 + 24 * 3600
    stream2.trim(day, day + 24 * 3600)
    stream2.merge()
    data = []
    while day < stream[-1].stats.endtime:
        st = stream.slice(day, day + 24 * 3600)
        st.merge()
        if len(st) == 0 or len(st[0].data) < 8640:
            print "skip %s" % day.date
            day = day + 24 * 3600
            continue
        a = st[0].data[:8640]
        if channel == "WKI":
            a = a / 100.0
            a = np.ma.masked_outside(a, 0, 50)
        elif channel == "WDI":
            a = a / 10000.0
            a = np.ma.masked_outside(a, 0, 5)
        else:
            a = np.ma.masked_outside(a, 0, 100)
        a = np.ma.masked_invalid(a)
        data.append(a)
        day = day + 24 * 3600
    # from IPython import embed
    # embed()
    stream2[0].data = np.ma.mean(data, axis=0)
    stream2.write(path + "/climate/%s_%s" % (station, channel), "Q")
    stream2.plot(method="full")
    plt.show()
Ejemplo n.º 2
0
def calc_strong_motion_Toco():
    t = UTC('2007-11-14')
    data = IPOC()
    channel = 'BHZ'
    acs = {}
    vels = {}

    for station in 'PB01 PB02 PB03 PB04 PB05 PB06 PB07 PB08 PATCX HMBCX PSGCX MNMCX'.split(
    ):
        for channel in ('BLZ', 'BHZ'):
            try:
                ms = data.getChannelFromClient(
                    t - 60,
                    t + 24 * 3600 + 60,
                    network='GE' if station == 'LVC' else 'CX',
                    location='10' if station == 'LVC' else '',
                    station=station,
                    channel=channel)
            except Exception as ex:
                print station, channel, 'sucks'
                continue
            for tr in ms:
                if tr.stats.endtime - tr.stats.starttime < 1000:
                    ms.remove(tr)
                    continue
                tr.trim(tr.stats.starttime + 10, tr.stats.endtime - 10)
                tr.stats.filter = ''
                tr.detrend()
                tr.filter('highpass', freq=0.2)
                tr.trim(tr.stats.starttime + 10, tr.stats.endtime - 10)
            ms.merge(fill_value=0)
            if len(ms) == 0:
                continue
            maxi = float(np.max(np.abs(ms[0].data)))
            if 'BH' in channel:
                vels[station] = maxi / 629145000.0 * 100
            elif 'BL' in channel:
                acs[station] = maxi / 427566.942
    with open(GM_TOCO, 'w') as f:
        yaml.dump({'vels': vels, 'acs': acs}, f, default_flow_style=False)
Ejemplo n.º 3
0
def calc_strong_motion_Toco():
    t = UTC('2007-11-14')
    data = IPOC()
    channel = 'BHZ'
    acs = {}
    vels = {}

    for station in 'PB01 PB02 PB03 PB04 PB05 PB06 PB07 PB08 PATCX HMBCX PSGCX MNMCX'.split():
        for channel in ('BLZ', 'BHZ'):
            try:
                ms = data.getChannelFromClient(t - 60, t + 24 * 3600 + 60,
                                               network='GE' if station == 'LVC' else 'CX',
                                               location='10' if station == 'LVC' else '',
                                               station=station, channel=channel)
            except Exception as ex:
                print station, channel, 'sucks'
                continue
            for tr in ms:
                if tr.stats.endtime - tr.stats.starttime < 1000:
                    ms.remove(tr)
                    continue
                tr.trim(tr.stats.starttime + 10, tr.stats.endtime - 10)
                tr.stats.filter = ''
                tr.detrend()
                tr.filter('highpass', freq=0.2)
                tr.trim(tr.stats.starttime + 10, tr.stats.endtime - 10)
            ms.merge(fill_value=0)
            if len(ms) == 0:
                continue
            maxi = float(np.max(np.abs(ms[0].data)))
            if 'BH' in channel:
                vels[station] = maxi / 629145000.0 * 100
            elif 'BL' in channel:
                acs[station] = maxi / 427566.942
    with open(GM_TOCO, 'w') as f:
        yaml.dump({'vels': vels, 'acs':acs}, f, default_flow_style=False)
from sito.util.main import streamdaygen
import pylab as plt

stations = 'PB01'  # PB04 PB06 PB07 PB08 PB09 PB10 PB11 PB12 PB16'
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))
import pylab as plt

stations = 'PB01'  # PB04 PB06 PB07 PB08 PB09 PB10 PB11 PB12 PB16'
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)