Beispiel #1
0
def rfani():
    parser = argparse.ArgumentParser(description="Estimate crustal anisotropy with a Joint inversion method. See Liu and Niu (2012) in detail.")
    parser.add_argument('rfpath', type=str, help="Path to PRFs")
    parser.add_argument('-t', help="Time window for searching Pms from tb to te", metavar='tb/te', required=True)
    parser.add_argument('-c', help="List file in text format for saving results, defaults to ./rfani.dat",
                        default="rfani.dat", metavar="list_file_name")
    parser.add_argument('-l', help="Half length of time window cut around Pms phase, defaults to 3s",
                        default=3, metavar="half_time_length", type=float)
    parser.add_argument('-r', help='Ray-parameter for moveout correction, defaults to 0.06 s/km',
                        default=0.06, metavar="rayp")
    parser.add_argument('-m', help='velocity model for moveout correction. \'iasp91\', \'prem\''
                        'and \'ak135\' is valid for internal model. Specify path to velocity model for the customized model.' 
                        'The format is the same as in Taup, but the depth should be monotonically increasing, defaults to \'iasp91\'',
                        default='iasp91', metavar="velocity_model")
    parser.add_argument('-o', dest='outpath', help="Directory to the image, defaults to current directory.", default='./')
    parser.add_argument('-p', help="If plot RFs stacked by back-azimuth, defaults to \'False\'",
                        dest="isplot", action='store_true', default=False)
    parser.add_argument('-w', help="Weights of 3 anisotropic methods (order by R cosine energy, R cross-correlation and T energy), defaults to 0.4/0.4/0.2",
                        dest='weight', default='0.4/0.4/0.2', metavar='w1/w2/w3')
    arg = parser.parse_args()
    weights = np.array(arg.weight.split('/')).astype(float)
    timewin = np.array(arg.t.split('/')).astype(float)
    rfsta = RFStation(arg.rfpath)
    bf, bt = rfsta.jointani(timewin[0], timewin[1], tlen=arg.l, weight=weights)
    with open(arg.c, 'a+') as fid:
        fid.write('{}\t{:.3f}\t{:.3f}\t{:.2f}\t{:.2f}\t{:.2f}\t{:.2f}\n'.format(
                  rfsta.staname, rfsta.stla, rfsta.stlo, bf[0], bt[0], bf[1], bt[1]))
    if arg.isplot:
        rfsta.ani.plot_stack_baz(outpath=arg.outpath)
    rfsta.ani.plot_polar(outpath=arg.outpath)
Beispiel #2
0
def makedata3d(cpara, velmod3d, log=setuplog(), raytracing3d=True):
    mod3d = Mod3DPerturbation(velmod3d, cpara.depth_axis, velmod=cpara.velmod)
    sta_info = Station(cpara.stalist)
    if cpara.rayp_lib is not None:
        srayp = np.load(cpara.rayp_lib)
    else:
        srayp = None
    RFdepth = []
    for i in range(sta_info.stla.shape[0]):
        rfdep = {}
        evt_lst = join(cpara.rfpath, sta_info.station[i],
                       sta_info.station[i] + 'finallist.dat')
        stadatar = RFStation(evt_lst, only_r=True)
        stadatar.stel = sta_info.stel[i]
        stadatar.stla = sta_info.stla[i]
        stadatar.stlo = sta_info.stlo[i]
        if stadatar.prime_phase == 'P':
            sphere = True
        else:
            sphere = False
        log.RF2depthlog.info('the {}th/{} station with {} events'.format(
            i + 1, sta_info.stla.shape[0], stadatar.ev_num))
        if raytracing3d:
            pplat_s, pplon_s, pplat_p, pplon_p, newtpds = psrf_3D_raytracing(
                stadatar, cpara.depth_axis, mod3d, srayp=srayp, sphere=sphere)
        else:
            pplat_s, pplon_s, pplat_p, pplon_p, raylength_s, raylength_p, tps = psrf_1D_raytracing(
                stadatar,
                cpara.depth_axis,
                srayp=srayp,
                sphere=sphere,
                phase=cpara.phase)
            newtpds = psrf_3D_migration(pplat_s, pplon_s, pplat_p, pplon_p,
                                        raylength_s, raylength_p, tps,
                                        cpara.depth_axis, mod3d)
        amp3d, end_index = time2depth(stadatar, cpara.depth_axis, newtpds)
        rfdep['station'] = sta_info.station[i]
        rfdep['stalat'] = sta_info.stla[i]
        rfdep['stalon'] = sta_info.stlo[i]
        rfdep['depthrange'] = cpara.depth_axis
        # rfdep['events'] = _convert_str_mat(stadatar.event)
        rfdep['bazi'] = stadatar.bazi
        rfdep['rayp'] = stadatar.rayp
        # rfdep['phases'] = _convert_str_mat(stadatar.phase)
        rfdep['moveout_correct'] = amp3d
        rfdep['piercelat'] = pplat_s
        rfdep['piercelon'] = pplon_s
        rfdep['stopindex'] = end_index
        RFdepth.append(rfdep)
    np.save(cpara.depthdat, RFdepth)
Beispiel #3
0
def main():
    parser = argparse.ArgumentParser(
        description="Plot R(Q)&T components for P receiver functions (PRFs)")
    parser.add_argument('rfpath',
                        help='Path to PRFs with a \'finallist.dat\' in it',
                        type=str,
                        default=None)
    parser.add_argument('-e',
                        help='Enlargement factor, defaults to 3',
                        dest='enf',
                        type=float,
                        default=3,
                        metavar='enf')
    parser.add_argument(
        '-o',
        help='Output path without file name, defaults to current path',
        dest='output',
        default='./',
        type=str,
        metavar='outpath')
    parser.add_argument(
        '-t',
        help=
        'Specify figure format. f = \'.pdf\', g = \'.png\', defaults to \'g\'',
        dest='format',
        default='g',
        type=str,
        metavar='f|g')
    parser.add_argument('-x',
                        help='The max time scale in sec, defaults to 30s',
                        default=30,
                        type=float,
                        metavar='max_time')
    arg = parser.parse_args()
    if arg.format not in ('f', 'g'):
        raise ValueError('Error: The format must be in \'f\' and \'g\'')
    rfsta = RFStation(arg.rfpath)
    plotrt(rfsta,
           enf=arg.enf,
           out_path=arg.output,
           outformat=arg.format,
           xmax=arg.x)
Beispiel #4
0
def main():
    parser = argparse.ArgumentParser(description="Plot R&T receiver functions")
    parser.add_argument('rfpath',
                        help='Path to PRFs with a \'finallist.dat\' in it',
                        type=str)
    parser.add_argument('-e',
                        help='Enlargement factor, defaults to 6',
                        dest='enf',
                        type=float,
                        default=6,
                        metavar='enf')
    parser.add_argument(
        '-o',
        help='Output path without file name, defaults to current path',
        dest='output',
        default='./',
        type=str,
        metavar='outpath')
    parser.add_argument(
        '-t',
        help=
        'Specify figure format. f = \'.pdf\', g = \'.png\', defaults to \'g\'',
        dest='format',
        default='g',
        type=str,
        metavar='f|g')
    parser.add_argument('-x',
                        help='The max time scale in sec, defaults to 85s',
                        default=85,
                        type=float,
                        metavar='max_time')

    arg = parser.parse_args()
    if arg.format not in ('f', 'g'):
        parser.error('Error: The format must be in \'f\' and \'g\'')
    elif arg.format == 'g':
        fmt = 'png'
    elif arg.format == 'f':
        fmt = 'pdf'
    rfsta = RFStation(arg.rfpath)
    plotr(rfsta, arg.output, enf=arg.enf, xlim=[-2, arg.x], format=fmt)
Beispiel #5
0
def rfharmo():
    parser = argparse.ArgumentParser('Harmonic decomposition for extracting anisotropic and isotropic features from the radial and transverse RFs')
    parser.add_argument('rfpath', type=str, help="Path to PRFs")
    parser.add_argument('-t', help="Time window from tb to te for triming RFs, NOTE: do not insert space before this argument, defaults to -2/10",
                        metavar='tb/te', default='-2/10')
    parser.add_argument('-s', help="Resample RFs with sampling interval of dt", metavar='dt', default=None, type=float)
    parser.add_argument('-o', help="Specify output path for saving constant component.", metavar='outpath', default=None, type=str)
    parser.add_argument('-p', help='Figure output path, defaults to ./', metavar='figure_path', default='./', type=str)
    args = parser.parse_args()
    rfsta = RFStation(args.rfpath)
    if args.s is not None:
        rfsta.resample(args.s)
    twin = [float(v) for v in args.t.split('/')]
    rfsta.harmonic(twin[0], twin[1])
    if args.o is not None:
        rfsta.harmo.write_constant(args.o)
    rfsta.harmo.plot(outpath=args.p)
Beispiel #6
0
def makedata(cpara, velmod3d=None, modfolder1d=None, log=setuplog()):
    ismod1d = False
    if velmod3d is not None:
        if isinstance(velmod3d, str):
            velmod = velmod3d
        else:
            raise ValueError('Path to 3d velocity model should be in str')
    elif modfolder1d is not None:
        if isinstance(modfolder1d, str):
            if exists(modfolder1d):
                ismod1d = True
            else:
                raise FileNotFoundError(
                    'No such folder of {}'.format(modfolder1d))
        else:
            ValueError('Path to 1d velocity model files should be in str')
    else:
        ismod1d = True

    # cpara = ccppara(cfg_file)
    sta_info = Station(cpara.stalist)
    RFdepth = []
    for i in range(sta_info.stla.shape[0]):
        rfdep = {}
        evt_lst = join(cpara.rfpath, sta_info.station[i],
                       sta_info.station[i] + 'finallist.dat')
        stadatar = RFStation(evt_lst, only_r=True)
        stadatar.stel = sta_info.stel[i]
        stadatar.stla = sta_info.stla[i]
        stadatar.stlo = sta_info.stlo[i]
        log.RF2depthlog.info('the {}th/{} station with {} events'.format(
            i + 1, sta_info.stla.shape[0], stadatar.ev_num))
        piercelat = np.zeros([stadatar.ev_num, cpara.depth_axis.shape[0]])
        piercelon = np.zeros([stadatar.ev_num, cpara.depth_axis.shape[0]])
        if stadatar.prime_phase == 'P':
            sphere = True
        else:
            sphere = False
        if ismod1d:
            if modfolder1d is not None:
                velmod = _load_mod(modfolder1d, sta_info.station[i])
            else:
                velmod = cpara.velmod
        PS_RFdepth, end_index, x_s, _ = psrf2depth(stadatar,
                                                   cpara.depth_axis,
                                                   velmod=velmod,
                                                   srayp=cpara.rayp_lib,
                                                   sphere=sphere,
                                                   phase=cpara.phase)
        for j in range(stadatar.ev_num):
            piercelat[j], piercelon[j] = latlon_from(sta_info.stla[i],
                                                     sta_info.stlo[i],
                                                     stadatar.bazi[j],
                                                     rad2deg(x_s[j]))
        rfdep['station'] = sta_info.station[i]
        rfdep['stalat'] = sta_info.stla[i]
        rfdep['stalon'] = sta_info.stlo[i]
        rfdep['depthrange'] = cpara.depth_axis
        # rfdep['events'] = _convert_str_mat(stadatar.event)
        rfdep['bazi'] = stadatar.bazi
        rfdep['rayp'] = stadatar.rayp
        # rfdep['phases'] = stadatar.phase[i]
        rfdep['moveout_correct'] = PS_RFdepth
        rfdep['piercelat'] = piercelat
        rfdep['piercelon'] = piercelon
        rfdep['stopindex'] = end_index
        RFdepth.append(rfdep)
    # savemat(cpara.depthdat, {'RFdepth': RFdepth})
    np.save(cpara.depthdat, RFdepth)
Beispiel #7
0
def test_sub04():
    rfs = RFStation('ex-rfani/SC.LTA')
    rfs.resample(0.1)
    plotr(rfs, outpath='./', xlim=[-2, 80], key='bazi', enf=6, format='pdf')
    plotrt(rfs, enf=3, out_path='./', key='bazi', outformat='g', xmax=30)
Beispiel #8
0
def test_sub03():
    rfs = RFStation('ex-rfani/SC.LTA')
    rfs.resample(0.1)
    rfs.harmonic(-2, 12)
    rfs.harmo.write_constant()
    rfs.harmo.plot()
Beispiel #9
0
def test_sub02():
    rfs = RFStation('ex-rfani/SC.LTA')
    rfs.moveoutcorrect()
    rfs.psrf2depth()
    rfs.psrf_1D_raytracing()
    rfs.slantstack()
Beispiel #10
0
def test_sub01():
    rfs = RFStation('ex-rfani/SC.LTA')
    rfs.jointani(3, 8, tlen=3.5, stack_baz_val=10, weight=[0.4, 0.4, 0.2])