Exemplo n.º 1
0
def calcTTTAdv_cube(Config,
                    station,
                    Origin,
                    flag,
                    arrayname,
                    Xcorrshift,
                    Refshift,
                    phase,
                    flag_rpe=False):

    cfg = ConfigObj(dict=Config)
    if flag_rpe is True:
        dimX = cfg.Int('dimx_emp')
        dimY = cfg.Int('dimy_emp')
        dimZ = cfg.Int('dimz_emp')
    else:
        dimX = cfg.Int('dimx')
        dimY = cfg.Int('dimy')
        dimZ = cfg.Int('dimz')

    orig_depth = float(Origin['depth'])

    start, stop, step = cfg.String('depths').split(',')
    start = orig_depth + float(start)
    stop = orig_depth + float(stop)
    depths = np.linspace(start, stop, num=dimZ)

    gridspacing = cfg.config_geometry.gridspacing
    traveltime_model = cfg_yaml.config.traveltime_model

    o_lat = float(Origin['lat'])
    o_lon = float(Origin['lon'])

    oLator = o_lat + dimX / 2
    oLonor = o_lon + dimY / 2
    oLatul = 0
    oLonul = 0
    o_dip = 80.
    plane = False

    TTTGridMap = {}
    LMINMAX = []
    GridArray = {}
    locStation = Location(station.lat, station.lon)
    sdelta = loc2degrees(Location(o_lat, o_lon), locStation)
    Phase = cake.PhaseDef(phase)
    path = palantiri.__path__
    model = cake.load_model(path[0] + '/data/' + traveltime_model)
    for depth in depths:
        o_depth = depth
        for i in xrange(dimX):
            oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing

            if i == 0:
                Latul = oLatul
            o = 0
            for j in xrange(dimY):
                oLonul = o_lon - (
                    (dimY - 1) / 2) * gridspacing + j * gridspacing

                if o == 0 and j == 0:
                    Lonul = oLonul
                de = loc2degrees(Location(oLatul, oLonul), locStation)
                arrivals = model.arrivals([de, de],
                                          phases=Phase,
                                          zstart=o_depth * km)
                try:
                    ttime = arrivals[0].t
                except Exception:
                    try:
                        arrivals = model.arrivals([de, de],
                                                  phases=Phase,
                                                  zstart=o_depth * km,
                                                  zstop=o_depth * km,
                                                  refine=True)
                        ttime = arrivals[0].t
                    except Exception:
                        arrivals = model.arrivals([de, de],
                                                  phases=Phase,
                                                  zstart=o_depth * km - 2.5,
                                                  zstop=o_depth * km + 2.5,
                                                  refine=True)
                        ttime = arrivals[0].t

                GridArray[(i, j, depth)] = GridElem(oLatul, oLonul, o_depth,
                                                    ttime, de)
                LMINMAX.append(ttime)

                if ttime == 0:
                    raise Exception("\033[31mILLEGAL: phase definition\033[0m")

    mint = min(LMINMAX)
    maxt = max(LMINMAX)
    TTTGridMap[station.getName()] = TTTGrid(o_depth, mint, maxt, Latul, Lonul,
                                            oLator, oLonor, GridArray)
    k = MinTMaxT(mint, maxt)

    if flag_rpe is True:
        Basic.dumpToFile(str(flag) + '-ttt_emp.pkl', TTTGridMap)
        Basic.dumpToFile('minmax-emp' + str(flag) + '.pkl', k)
        Basic.dumpToFile('station-emp' + str(flag) + '.pkl', station)
    else:
        Basic.dumpToFile(str(flag) + '-ttt.pkl', TTTGridMap)
        Basic.dumpToFile('minmax-' + str(flag) + '.pkl', k)
        Basic.dumpToFile('station-' + str(flag) + '.pkl', station)
Exemplo n.º 2
0
def calcTTTAdvTauP(Config,
                   station,
                   Origin,
                   flag,
                   Xcorrshift=None,
                   Refshift=None,
                   flag_rpe=False):

    cfg = ConfigObj(dict=Config)
    if flag_rpe is False:
        dimX = cfg.Int('dimx')
        dimY = cfg.Int('dimy')
    else:
        dimX = cfg.Int('dimx_emp')
        dimY = cfg.Int('dimy_emp')
    gridspacing = cfg.config_geometry.gridspacing
    print('done this')
    o_lat = float(Origin['lat'])
    o_lon = float(Origin['lon'])
    o_depth = float(Origin['depth'])

    oLator = o_lat + dimX / 2
    oLonor = o_lon + dimY / 2
    oLatul = 0
    oLonul = 0

    TTTGridMap = {}
    LMINMAX = []
    GridArray = {}
    locStation = Location(station.lat, station.lon)

    sdelta = loc2degrees(Location(o_lat, o_lon), locStation)
    Logfile.add('TTT PROCESS %d STATION: %s --> DELTA: %f' %
                (flag, station.getName(), sdelta))

    inputpath = str(flag) + '-' + station.getName() + ".input"
    outputpath = str(flag) + '-' + station.getName() + ".output"
    errorpath = str(flag) + '-' + station.getName() + '.error'

    fobjinput = open(inputpath, 'w')

    fobjinput.write('s\n')
    fobjinput.write(('%s %s\n') % (station.lat, station.lon))
    fobjinput.write('h\n')
    fobjinput.write(('%s\n') % (o_depth))

    for i in xrange(dimX):
        oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing

        for j in xrange(dimY):
            oLonul = o_lon - ((dimY - 1) / 2) * gridspacing + j * gridspacing

            fobjinput.write('e\n')
            fobjinput.write(('%s %s\n') % (oLatul, oLonul))
    # endfor

    fobjinput.close()

    cmd = ('taup_time -ph P -mod ak135 -time -o %s < %s > %s') % (
        outputpath, inputpath, errorpath)
    p = subprocess.Popen(cmd,
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    p.wait()

    L = []
    output = open(outputpath, 'r')
    'OUTPUT: ', outputpath

    for k in output:
        k = k.split()

        if len(k) == 1:
            tt = k[0].replace('\n', '')
            tt = float(tt) - float(Xcorrshift[station.getName()].shift)
            L.append(tt)

    output.close()

    z = 0

    for i in xrange(dimX):
        oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing

        if z == 0 and i == 0:
            Latul = oLatul
        o = 0

        for j in xrange(dimY):
            oLonul = o_lon - ((dimY - 1) / 2) * gridspacing + j * gridspacing

            if o == 0 and j == 0:
                Lonul = oLonul

            de = loc2degrees(Location(oLatul, oLonul), locStation)
            time = L[i * dimX + j]

            GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, time, de)
            LMINMAX.append(time)

    mint = float(min(LMINMAX))
    maxt = float(max(LMINMAX))
    k = MinTMaxT(mint, maxt)

    TTTGridMap[station.getName()] = TTTGrid(o_depth, mint, maxt, Latul, Lonul,
                                            oLator, oLonor, GridArray)

    #tttname = str(flag)+'-ttt.pkl'
    #Basic.dumpToFile(tttname, TTTGridMap)
    #Basic.dumpToFile('minmax-'+str(flag)+'.pkl', k)
    if flag_rpe is True:
        Basic.dumpToFile(str(flag) + '-ttt_emp.pkl', TTTGridMap)
        Basic.dumpToFile('minmax-emp' + str(flag) + '.pkl', k)
        Basic.dumpToFile('station-emp' + str(flag) + '.pkl', station)
    else:
        Basic.dumpToFile(str(flag) + '-ttt.pkl', TTTGridMap)
        Basic.dumpToFile('minmax-' + str(flag) + '.pkl', k)
        Basic.dumpToFile('station-' + str(flag) + '.pkl', station)
    try:
        os.remove(inputpath)
        os.remove(outputpath)
        os.remove(errorpath)

    except:
        Logfile.exception('cannot delete files')
Exemplo n.º 3
0
def calcTTTAdv(cfg,
               station,
               Origin,
               flag,
               arrayname,
               Xcorrshift,
               Refshift,
               phase,
               flag_rpe=False):

    if flag_rpe is True:
        dimX = cfg.config_geometry.dimx_emp
        dimY = cfg.config_geometry.dimy_emp
    else:
        dimX = cfg.config_geometry.dimx
        dimY = cfg.config_geometry.dimy

    gridspacing = cfg.config_geometry.gridspacing
    o_lat = float(Origin['lat'])
    o_lon = float(Origin['lon'])
    o_depth = float(Origin['depth'])

    oLator = o_lat + dimX / 2
    oLonor = o_lon + dimY / 2
    oLatul = 0
    oLonul = 0
    o_dip = 80.
    plane = False

    TTTGridMap = {}
    LMINMAX = []
    GridArray = {}
    locStation = Location(station.lat, station.lon)
    sdelta = loc2degrees(Location(o_lat, o_lon), locStation)
    Phase = cake.PhaseDef(phase)
    path = palantiri.__path__
    traveltime_model = cfg.config.traveltime_model
    model = cake.load_model(path[0] + '/data/' + traveltime_model)
    z = 0
    if plane is True:
        depth = np.linspace(0., 40., num=dimY)
        for i in xrange(70):
            oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing
            if z == 0 and i == 0:
                Latul = oLatul
            o = 0
            start_time = time.clock()

            for j in xrange(40):
                oLonul = o_lon - (
                    (dimY - 1) /
                    2) * gridspacing + j * gridspacing / np.cos(o_dip)
                if o == 0 and j == 0:
                    Lonul = oLonul
                de = loc2degrees(Location(oLatul, oLonul), locStation)
                arrivals = model.arrivals([de, de],
                                          phases=Phase,
                                          zstart=depth[j] * km,
                                          zstop=0.)
            try:
                ttime = arrivals[0].t
            except Exception:
                try:
                    arrivals = model.arrivals([de, de],
                                              phases=Phase,
                                              zstart=depth[j] * km - 2.5,
                                              zstop=depth[j] * km + 2.5,
                                              refine=True)
                    ttime = arrivals[0].t
                except Exception:
                    tt = obs_TravelTimes(de, o_depth)
                    for k in tt:
                        if k['phase_name'] == 'P' or k['phase_name'] == (
                                '%sdiff') % (Config[phasename]):
                            ttime = k['time']
                        print("Something wrong with phase arrival, too large\
                             distances choosen?")

                GridArray[(i, j)] = GridElem(oLatul, oLonul, depth[j], ttime,
                                             de)
                LMINMAX.append(ttime)

                if ttime == 0:
                    raise Exception("\033[31mILLEGAL: phase definition\033[0m")
    else:
        for i in xrange(dimX):
            oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing

            if z == 0 and i == 0:
                Latul = oLatul
            o = 0
            for j in xrange(dimY):
                oLonul = o_lon - (
                    (dimY - 1) / 2) * gridspacing + j * gridspacing

                if o == 0 and j == 0:
                    Lonul = oLonul
                de = loc2degrees(Location(oLatul, oLonul), locStation)
                arrivals = model.arrivals([de, de],
                                          phases=Phase,
                                          zstart=o_depth * km)
                try:
                    ttime = arrivals[0].t
                except:
                    try:
                        arrivals = model.arrivals([de, de],
                                                  phases=Phase,
                                                  zstart=o_depth * km,
                                                  zstop=o_depth * km,
                                                  refine=True)
                        ttime = arrivals[0].t
                    except:
                        arrivals = model.arrivals([de, de],
                                                  phases=Phase,
                                                  zstart=o_depth * km - 2.5,
                                                  zstop=o_depth * km + 2.5,
                                                  refine=True)
                        ttime = arrivals[0].t

                GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, ttime,
                                             de)
                LMINMAX.append(ttime)
                if ttime == 0:
                    raise Exception("\033[31mILLEGAL: phase definition\033[0m")

    mint = min(LMINMAX)
    maxt = max(LMINMAX)
    TTTGridMap[station.getName()] = TTTGrid(o_depth, mint, maxt, Latul, Lonul,
                                            oLator, oLonor, GridArray)
    k = MinTMaxT(mint, maxt)

    if flag_rpe is True:
        Basic.dumpToFile(str(flag) + '-ttt_emp.pkl', TTTGridMap)
        Basic.dumpToFile('minmax-emp' + str(flag) + '.pkl', k)
        Basic.dumpToFile('station-emp' + str(flag) + '.pkl', station)
    else:
        Basic.dumpToFile(str(flag) + '-ttt.pkl', TTTGridMap)
        Basic.dumpToFile('minmax-' + str(flag) + '.pkl', k)
        Basic.dumpToFile('station-' + str(flag) + '.pkl', station)