Пример #1
0
def time_binned(station, start, end, dif=0.5, expr=None):
    log.info('Create time binned plot')
    util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_bin_time.txt')
    filename = 'bin_time_%s_%s_dif%s' % (station, expr, dif)
    file_ = data.rf_results_dir + filename
    try:
        binned = read(file_ + '.QHD')
    except:
        binsx = np.linspace(start, end, int((end - start) / dif + 1))
        bins = [
            UTCDateTime(int(i // 1), 1, 1) + (i % 1) * 24 * 60 * 60 *
            (365 + calendar.isleap(int(i // 1))) for i in binsx
        ]
        stream = read_rf().select(station=station, component='Q', expr=expr)
        stream.trim2(-10, 50)
        binned = stream.getBinnedStream(bins, header='starttime')
        binned.write(file_, 'Q')
    fig = binned.plotRF(topcolor=top2,
                        fig=getFig(),
                        botcolor=bot2,
                        plotinfo=['sum', 'starttime'],
                        plotlabel=['time', 'count', 'year'],
                        show=show)
    fig.savefig(plotdir + filename + '.eps')
    plt.close(fig)
Пример #2
0
def create_interval_plot(expr):
    """ automatically create eps pictures for receiver functions

    use only an azimuth interval and compare sorting after azimuth and time"""
    log.info('***** Create interval plots')
    util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_interval_plots.txt')
    stream_all = read_rf()
    for station in data.stations.keys():
        stream = stream_all.select(station=station, expr=expr)
        stream.sort(['azi', 'component'])
        pi = ['dist', 'azi']
        pl = ['time (s)', u'dist (°)', u'azi (°)']
        fig = getFig()
        fig = stream.plotRF(-5, 35, showsum=False, show=show, fig=fig, scale=5, sumscale=50, plotinfo=pi, plotlabel=pl, topcolor=top2, botcolor=bot2)
        fig.savefig(plotdir + 'rf_%s_%s_sorted_azi_Q.eps' % (station, expr))
        plt.close(fig)
        fig2 = getFig()
        fig2 = stream.plotRF(-5, 35, showsum=False, show=show, fig=fig2, scale=5, sumscale=50, component='T', plotinfo=pi, plotlabel=pl, topcolor=top2, botcolor=bot2)
        fig2.savefig(plotdir + 'rf_%s_%s_sorted_azi_T.eps' % (station, expr))
        plt.close(fig2)
        pi = ['starttime', 'azi']
        pl = ['time (s)', 'year', u'azi (°)']

        stream.sort(['starttime', 'component'])
        fig3 = getFig()
        fig3 = stream.plotRF(-5, 35, showsum=False, show=show, fig=fig3, scale=5, sumscale=50, plotinfo=pi, plotlabel=pl, topcolor=top2, botcolor=bot2)
        fig3.savefig(plotdir + 'rf_%s_%s_sorted_time_Q.eps' % (station, expr))
        plt.close(fig3)
        fig4 = getFig()
        fig4 = stream.plotRF(-5, 35, showsum=False, show=show, fig=fig4, scale=5, sumscale=50, component='T', plotinfo=pi, plotlabel=pl, topcolor=top2, botcolor=bot2)
        fig4.savefig(plotdir + 'rf_%s_%s_sorted_time_Q.eps' % (station, expr))
        plt.close(fig4)
Пример #3
0
def profile_pp_binned(stations, bin, header='plon', expr=None, xlim=None):  #, scale=0.2 @ReservedAssignment
    """ PP profile """
    log.info('***** Create piercing point binned plot')
    util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_profile_pp.txt')
    filename = 'profile_pp_%s_%s_dif%s' % (stations, expr, bin[1] - bin[0])
    file_ = data.rf_results_dir + filename
    try:
        stream = read(file_ + '.QHD')
    except:
        stream_all = read_rf()
        stream = stream_all.select(component='Q', expr=expr).getBinnedStream(bin, header=header)
        stream.write(file_, 'Q')
    plot = stream.plotProfile(-2, 21, scale=bin[1] - bin[0], xaxis='plon', xlabel='longitude of piercing points', plotinfo=(), figtitle='profile')
    ax = plot.fig.axes[0]
    if xlim:
        ax.set_xlim(xlim)
    # second ax with depth
    ax2 = ax.twinx()
    h = np.array((0, 50, 100, 150, 200))
    h2 = np.arange(20) * 10
    t = util.depth2time(h)
    myLocator = mpl.ticker.FixedLocator(t)
    myMinorLocator = mpl.ticker.FixedLocator(util.depth2time(h2))
    myFormatter = mpl.ticker.FixedFormatter([str(i) for i in h])
    ax2.yaxis.set_major_locator(myLocator)
    ax2.yaxis.set_minor_locator(myMinorLocator)
    ax2.yaxis.set_major_formatter(myFormatter)
    ax2.set_ylim(ax.get_ylim())
    ax2.set_ylabel('depth (km)')
    plt.show()
    #plot.fig.savefig(plotdir + filename + '.eps')    #st2.plotProfile(-2, 21, scale=0.05, xaxis = 'plon')
    #plot.fig.savefig(plotdir + filename + '.png')
    plt.close(plot.fig)
Пример #4
0
def pick_events(window=(-100, 500), filter=(0.033, 2.), phase='P', new_sampling_rate=20):  #@ReservedAssignment
    logfile = os.path.dirname(data.rf_events) + '/log_pick_events_%s.txt'
    util.checkDir(logfile)
    util.setRootLogger(logfile=logfile % '', logdebugfile=logfile % '_debug')
    log.info('***** Pick events: %s' % util.parameters())
    mod_data.eventPicker(data, component='all', phase=phase, window=window,
                     filter=filter, new_sampling_rate=new_sampling_rate)
Пример #5
0
def pick_events(
        window=(-100, 500), filter=(0.033, 2.), phase='P',
        new_sampling_rate=20):  #@ReservedAssignment
    logfile = os.path.dirname(data.rf_events) + '/log_pick_events_%s.txt'
    util.checkDir(logfile)
    util.setRootLogger(logfile=logfile % '', logdebugfile=logfile % '_debug')
    log.info('***** Pick events: %s' % util.parameters())
    mod_data.eventPicker(data,
                         component='all',
                         phase=phase,
                         window=window,
                         filter=filter,
                         new_sampling_rate=new_sampling_rate)
Пример #6
0
def profile_pp_binned(stations,
                      bin,
                      header='plon',
                      expr=None,
                      xlim=None):  #, scale=0.2 @ReservedAssignment
    """ PP profile """
    log.info('***** Create piercing point binned plot')
    util.setRootLogger(logdebugfile=data.rf_results_dir +
                       'a_log_profile_pp.txt')
    filename = 'profile_pp_%s_%s_dif%s' % (stations, expr, bin[1] - bin[0])
    file_ = data.rf_results_dir + filename
    try:
        stream = read(file_ + '.QHD')
    except:
        stream_all = read_rf()
        stream = stream_all.select(component='Q',
                                   expr=expr).getBinnedStream(bin,
                                                              header=header)
        stream.write(file_, 'Q')
    plot = stream.plotProfile(-2,
                              21,
                              scale=bin[1] - bin[0],
                              xaxis='plon',
                              xlabel='longitude of piercing points',
                              plotinfo=(),
                              figtitle='profile')
    ax = plot.fig.axes[0]
    if xlim:
        ax.set_xlim(xlim)
    # second ax with depth
    ax2 = ax.twinx()
    h = np.array((0, 50, 100, 150, 200))
    h2 = np.arange(20) * 10
    t = util.depth2time(h)
    myLocator = mpl.ticker.FixedLocator(t)
    myMinorLocator = mpl.ticker.FixedLocator(util.depth2time(h2))
    myFormatter = mpl.ticker.FixedFormatter([str(i) for i in h])
    ax2.yaxis.set_major_locator(myLocator)
    ax2.yaxis.set_minor_locator(myMinorLocator)
    ax2.yaxis.set_major_formatter(myFormatter)
    ax2.set_ylim(ax.get_ylim())
    ax2.set_ylabel('depth (km)')
    plt.show()
    #plot.fig.savefig(plotdir + filename + '.eps')    #st2.plotProfile(-2, 21, scale=0.05, xaxis = 'plon')
    #plot.fig.savefig(plotdir + filename + '.png')
    plt.close(plot.fig)
Пример #7
0
def time_binned(station, start, end, dif=0.5, expr=None):
    log.info('Create time binned plot')
    util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_bin_time.txt')
    filename = 'bin_time_%s_%s_dif%s' % (station, expr, dif)
    file_ = data.rf_results_dir + filename
    try:
        binned = read(file_ + '.QHD')
    except:
        binsx = np.linspace(start, end, int((end - start) / dif + 1))
        bins = [UTCDateTime(int(i // 1), 1, 1) + (i % 1) * 24 * 60 * 60 * (365 + calendar.isleap(int(i // 1))) for i in binsx]
        stream = read_rf().select(station=station, component='Q', expr=expr)
        stream.trim2(-10, 50)
        binned = stream.getBinnedStream(bins, header='starttime')
        binned.write(file_, 'Q')
    fig = binned.plotRF(topcolor=top2, fig=getFig(), botcolor=bot2, plotinfo=['sum', 'starttime'], plotlabel=['time', 'count', 'year'], show=show)
    fig.savefig(plotdir + filename + '.eps')
    plt.close(fig)
Пример #8
0
def calculate_rf(year='*', pp=False, rotateLQT=True, deconvolvef=False):
    logfile = data.rf_results_dir + 'a_log%s.txt'
    util.checkDir(logfile)
    util.setRootLogger(logfile=logfile % '', logdebugfile=logfile % '_debug')
    log.info('***** Calculate RF')
    for station in data.stations.keys():
        stream = read(data.rf_events % (station, year + '.QHD'))
        if pp:
            stream.setPhase('PP')
        stream.pspier(60, data.stations)
        log.info('number of events: %s' % (len(stream) // 3))
        #stream.filter2(0.033, 2.)
        stream.trim2(-20, 100, relative='ponset')
        stream.sort(('event.id', 'station', 'component'))
        stream.check()
        stream.setHI('mark', False)
        if rotateLQT:
            stream.rotateZNE2LQT(-5, 15, usetheo=True)
            stream.afarm(signoise=2.0, remove=True)
        else:
            #stream.rotateZNE2LQT(-5, 15, usetheo=True)
            #stream.afarm(signoise=2.0, remove=True)
            #stream.trim2(-20, 100, relative='ponset')
            #stream.rotateLQT2ZNE(usetheo=True)
            stream.rotateNE2RT()
        #stream.afarm(signoise=2.0, remove=True)
        #stream.trim2(-25, 100, relative='ponset')

        # log.info('number of events after first farm: %s' % (len(stream)//3))
        # util.ipshell()
        #stream.receiverf(water=0.005, gauss=5, tshift=20, pad=0,
        #                 window='tukey', start=-10, end=30, where='ponset', lenslope=5)
        if deconvolvef:
            stream.receiverf()
        else:
            stream.receivert()
        #stream.receiverSH(-10, 80, 1)
        #stream.afarm('rf', signoise=2., signoiseQ=1., maxL=1 / 1.5, sigQ=False, broad=True, remove=False)
        #stream.afarm('rf', signoise=False, signoiseQ=False, maxL=False, sigQ=False, broad=False, remove=False)
        #log.info('number of events after second farm: %s' % (len(stream)//3))

        stream.write(data.rf_results % (station, '') + 'nomout', 'Q')
        #stream.writey(data.rf_results % (station, '%s') + '_nomout', 'Q')
        print stream.getReasons()
Пример #9
0
def calculate_rf(year='*', pp=False, rotateLQT=True, deconvolvef=False):
    logfile = data.rf_results_dir + 'a_log%s.txt'
    util.checkDir(logfile)
    util.setRootLogger(logfile=logfile % '', logdebugfile=logfile % '_debug')
    log.info('***** Calculate RF')
    for station in data.stations.keys():
        stream = read(data.rf_events % (station, year + '.QHD'))
        if pp:
            stream.setPhase('PP')
        stream.pspier(60, data.stations)
        log.info('number of events: %s' % (len(stream) // 3))
        #stream.filter2(0.033, 2.)
        stream.trim2(-20, 100, relative='ponset')
        stream.sort(('event.id', 'station', 'component'))
        stream.check()
        stream.setHI('mark', False)
        if rotateLQT:
            stream.rotateZNE2LQT(-5, 15, usetheo=True)
            stream.afarm(signoise=2.0, remove=True)
        else:
            #stream.rotateZNE2LQT(-5, 15, usetheo=True)
            #stream.afarm(signoise=2.0, remove=True)
            #stream.trim2(-20, 100, relative='ponset')
            #stream.rotateLQT2ZNE(usetheo=True)
            stream.rotateNE2RT()
        #stream.afarm(signoise=2.0, remove=True)
        #stream.trim2(-25, 100, relative='ponset')

        # log.info('number of events after first farm: %s' % (len(stream)//3))
        # util.ipshell()
        #stream.receiverf(water=0.005, gauss=5, tshift=20, pad=0,
        #                 window='tukey', start=-10, end=30, where='ponset', lenslope=5)
        if deconvolvef:
            stream.receiverf()
        else:
            stream.receivert()
        #stream.receiverSH(-10, 80, 1)
        #stream.afarm('rf', signoise=2., signoiseQ=1., maxL=1 / 1.5, sigQ=False, broad=True, remove=False)
        #stream.afarm('rf', signoise=False, signoiseQ=False, maxL=False, sigQ=False, broad=False, remove=False)
        #log.info('number of events after second farm: %s' % (len(stream)//3))

        stream.write(data.rf_results % (station, '') + 'nomout', 'Q')
        #stream.writey(data.rf_results % (station, '%s') + '_nomout', 'Q')
        print stream.getReasons()
Пример #10
0
def profile(stations, expr=None):
    """ plots summation trace for all stations """
    log.info('***** Create profile plots')
    util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_profile.txt')
    filename = 'sum_%s_%s' % (stations, expr)
    file_ = data.rf_results_dir + filename
    try:
        sum_stream = read(file_ + '.QHD')
    except:
        stream = read_rf()
        sum_stream = Stream()
        for station in stations.split():
            temp = stream.select(station=station, component='Q', expr=expr)
            sum_stream += temp.simpleStack()
        sum_stream.write(file_, 'Q')
    plot = sum_stream.plotProfile(-2, 21, scale=5)
    plot.fig.savefig(plotdir + filename + '.eps')
    plot.fig.savefig(plotdir + filename + '.png')
    plt.close(plot.fig)
Пример #11
0
def mout(station='*', year='*'):
    log.info('***** Move Out correction')
    global rf_stream
    logfile = data.rf_results_dir + 'a_mout_log%s.txt'
    util.checkDir(logfile)
    util.setRootLogger(logfile=logfile % '', logdebugfile=logfile % '_debug')
    rf_stream = read(data.rf_results % (station, year) + 'nomout.QHD')
    if False:
        st2 = rf_stream.copy()
        st2.moveout(phase='Ppps')
        st2.trim2(-20, 100)
        st2.write(data.rf_results % '_Ppps', 'Q')
        st3 = rf_stream.copy()
        st3.moveout(phase='Ppss')
        st3.trim2(-20, 100)
        st3.write(data.rf_results % '_Ppss', 'Q')
    rf_stream.moveout(phase='Ps')
    #rf_stream.trim2(-20, 100)
    rf_stream.writex(data.rf_results % ('%s', '') + 'mout', 'Q', years=False)
Пример #12
0
def profile(stations, expr=None):
    """ plots summation trace for all stations """
    log.info('***** Create profile plots')
    util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_profile.txt')
    filename = 'sum_%s_%s' % (stations, expr)
    file_ = data.rf_results_dir + filename
    try:
        sum_stream = read(file_ + '.QHD')
    except:
        stream = read_rf()
        sum_stream = Stream()
        for station in stations.split():
            temp = stream.select(station=station, component='Q', expr=expr)
            sum_stream += temp.simpleStack()
        sum_stream.write(file_, 'Q')
    plot = sum_stream.plotProfile(-2, 21, scale=5)
    plot.fig.savefig(plotdir + filename + '.eps')
    plot.fig.savefig(plotdir + filename + '.png')
    plt.close(plot.fig)
Пример #13
0
def mout(station='*', year='*'):
    log.info('***** Move Out correction')
    global rf_stream
    logfile = data.rf_results_dir + 'a_mout_log%s.txt'
    util.checkDir(logfile)
    util.setRootLogger(logfile=logfile % '', logdebugfile=logfile % '_debug')
    rf_stream = read(data.rf_results % (station, year) + 'nomout.QHD')
    if False:
        st2 = rf_stream.copy()
        st2.moveout(phase='Ppps')
        st2.trim2(-20, 100)
        st2.write(data.rf_results % '_Ppps', 'Q')
        st3 = rf_stream.copy()
        st3.moveout(phase='Ppss')
        st3.trim2(-20, 100)
        st3.write(data.rf_results % '_Ppss', 'Q')
    rf_stream.moveout(phase='Ps')
    #rf_stream.trim2(-20, 100)
    rf_stream.writex(data.rf_results % ('%s', '') + 'mout', 'Q', years=False)
Пример #14
0
def create_rf_plots(start= -5, end=22, years=None, components='LQT'):
    """ automatically create pictures for receiver functions """
    log.info('***** Create RF plots')
    util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_rf_plots.txt')
    stream = read_rf()
    if len(stream) == 0:
        return False
    if years == None:
        years = ['']
    for station in stream.getStationList():
        for year in years:
            stream_station = stream.select(station=station, expr='not st.mark')
            if year != '':
                stream_station = stream_station.select(expr='st.event.datetime.year==%s' % year)
                year = '_' + str(year)
            stream_station.sort('azi')
            if len(stream_station) < 3:
                continue
            ratio = len(stream_station) // 3 / 100. * 0.6
            if len(stream_station) // 3 < 150:
                ratio *= 1.8
            if len(stream_station) // 3 < 50:
                ratio *= 3 / 1.8
            fig = getFig(ratio=ratio)
            plot = stream_station.plotRF(start, end, show=show, fig=fig, scale=2, sumscale=10, component=components[1], topcolor=top, botcolor=bot, figtitle='station component', fancy_box=True)
            plot.fig.savefig(plotdir + 'rf_%s%s_%s.pdf' % (station, year, components[1]))
            plt.close(plot.fig)
            fig2 = getFig(ratio=ratio)
            plot = stream_station.plotRF(start, end, show=show, fig=fig2, scale=2, sumscale=10, component=components[2], topcolor=top, botcolor=bot, figtitle='station component', fancy_box=True)
            plot.fig.savefig(plotdir + 'rf_%s%s_%s.pdf' % (station, year, components[2]))
            plt.close(plot.fig)
            fig3 = getFig(ratio=ratio)
            plot = stream_station.plotRF(start, end, show=show, fig=fig3, scale=0.9, sumscale=2, component=components[0], topcolor=top, botcolor=bot, figtitle='station component', fancy_box=True)
            plot.fig.savefig(plotdir + 'rf_%s%s_%s.pdf' % (station, year, components[0]))
            plt.close(plot.fig)
    return True
Пример #15
0
def create_interval_plot(expr):
    """ automatically create eps pictures for receiver functions

    use only an azimuth interval and compare sorting after azimuth and time"""
    log.info('***** Create interval plots')
    util.setRootLogger(logdebugfile=data.rf_results_dir +
                       'a_log_interval_plots.txt')
    stream_all = read_rf()
    for station in data.stations.keys():
        stream = stream_all.select(station=station, expr=expr)
        stream.sort(['azi', 'component'])
        pi = ['dist', 'azi']
        pl = ['time (s)', u'dist (°)', u'azi (°)']
        fig = getFig()
        fig = stream.plotRF(-5,
                            35,
                            showsum=False,
                            show=show,
                            fig=fig,
                            scale=5,
                            sumscale=50,
                            plotinfo=pi,
                            plotlabel=pl,
                            topcolor=top2,
                            botcolor=bot2)
        fig.savefig(plotdir + 'rf_%s_%s_sorted_azi_Q.eps' % (station, expr))
        plt.close(fig)
        fig2 = getFig()
        fig2 = stream.plotRF(-5,
                             35,
                             showsum=False,
                             show=show,
                             fig=fig2,
                             scale=5,
                             sumscale=50,
                             component='T',
                             plotinfo=pi,
                             plotlabel=pl,
                             topcolor=top2,
                             botcolor=bot2)
        fig2.savefig(plotdir + 'rf_%s_%s_sorted_azi_T.eps' % (station, expr))
        plt.close(fig2)
        pi = ['starttime', 'azi']
        pl = ['time (s)', 'year', u'azi (°)']

        stream.sort(['starttime', 'component'])
        fig3 = getFig()
        fig3 = stream.plotRF(-5,
                             35,
                             showsum=False,
                             show=show,
                             fig=fig3,
                             scale=5,
                             sumscale=50,
                             plotinfo=pi,
                             plotlabel=pl,
                             topcolor=top2,
                             botcolor=bot2)
        fig3.savefig(plotdir + 'rf_%s_%s_sorted_time_Q.eps' % (station, expr))
        plt.close(fig3)
        fig4 = getFig()
        fig4 = stream.plotRF(-5,
                             35,
                             showsum=False,
                             show=show,
                             fig=fig4,
                             scale=5,
                             sumscale=50,
                             component='T',
                             plotinfo=pi,
                             plotlabel=pl,
                             topcolor=top2,
                             botcolor=bot2)
        fig4.savefig(plotdir + 'rf_%s_%s_sorted_time_Q.eps' % (station, expr))
        plt.close(fig4)
Пример #16
0
def create_rf_plots(start=-5, end=22, years=None, components='LQT'):
    """ automatically create pictures for receiver functions """
    log.info('***** Create RF plots')
    util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_rf_plots.txt')
    stream = read_rf()
    if len(stream) == 0:
        return False
    if years == None:
        years = ['']
    for station in stream.getStationList():
        for year in years:
            stream_station = stream.select(station=station, expr='not st.mark')
            if year != '':
                stream_station = stream_station.select(
                    expr='st.event.datetime.year==%s' % year)
                year = '_' + str(year)
            stream_station.sort('azi')
            if len(stream_station) < 3:
                continue
            ratio = len(stream_station) // 3 / 100. * 0.6
            if len(stream_station) // 3 < 150:
                ratio *= 1.8
            if len(stream_station) // 3 < 50:
                ratio *= 3 / 1.8
            fig = getFig(ratio=ratio)
            plot = stream_station.plotRF(start,
                                         end,
                                         show=show,
                                         fig=fig,
                                         scale=2,
                                         sumscale=10,
                                         component=components[1],
                                         topcolor=top,
                                         botcolor=bot,
                                         figtitle='station component',
                                         fancy_box=True)
            plot.fig.savefig(plotdir + 'rf_%s%s_%s.pdf' %
                             (station, year, components[1]))
            plt.close(plot.fig)
            fig2 = getFig(ratio=ratio)
            plot = stream_station.plotRF(start,
                                         end,
                                         show=show,
                                         fig=fig2,
                                         scale=2,
                                         sumscale=10,
                                         component=components[2],
                                         topcolor=top,
                                         botcolor=bot,
                                         figtitle='station component',
                                         fancy_box=True)
            plot.fig.savefig(plotdir + 'rf_%s%s_%s.pdf' %
                             (station, year, components[2]))
            plt.close(plot.fig)
            fig3 = getFig(ratio=ratio)
            plot = stream_station.plotRF(start,
                                         end,
                                         show=show,
                                         fig=fig3,
                                         scale=0.9,
                                         sumscale=2,
                                         component=components[0],
                                         topcolor=top,
                                         botcolor=bot,
                                         figtitle='station component',
                                         fancy_box=True)
            plot.fig.savefig(plotdir + 'rf_%s%s_%s.pdf' %
                             (station, year, components[0]))
            plt.close(plot.fig)
    return True