Exemple #1
0
    def signoise(self, Waveform, ttime, path):

        st = str(self.Origin.time)[:-1]
        ponset = UTCDateTime(st) + ttime

        winnoise_start = Waveform.stats.starttime + 20
        winnoise_end = ponset - 10
        winsig_start = ponset - 2
        winsig_end = ponset + 10

        try:
            winnoise = read(path,
                            format="MSEED",
                            starttime=winnoise_start,
                            endtime=winnoise_end,
                            nearest_sample=True)
            winsig = read(path,
                          format="MSEED",
                          starttime=winsig_start,
                          endtime=winsig_end,
                          nearest_sample=True)
        except Exception:
            Logfile.exception('signoise')

        psignal = abs(winsig.max()[0])
        pnoise = abs(winnoise.max()[0])

        signoise = float(psignal) / float(pnoise)

        return signoise
Exemple #2
0
def readURL(url, tmpFile=None):

    lines = []

    try:
        datasource = urlopen(url)

        while True:
            line = datasource.readline()

            if line == '':
                break
            lines.append(line)

        if len(lines) == 0:
            Logfile.error('Cannot read from URL:', url)
            lines = []

        Logfile.add(str(len(lines)) + ' lines read from URL:', url)

        if tmpFile:
            writeTextFile(tmpFile, lines)

    except:
        Logfile.exception('readURL')

    return lines
def filterBestSolution(solution):

    evp  = os.path.join('/',*solution.path.split('/')[:-2])
    C= Config(evp)
    Conf = C.parseConfig('config')
    cfg  = ConfigObj(dict=Conf)

    SL   = []
    M= []
    fobj = open(os.path.join(solution.path, 'event.stations'),'r')

    for s in fobj:
       try:
           line = s.split()
           net,sta,loc,comp = line[0].split('.')

           slat= line[1]
           slon= line[2]
           smember = line[3]

           M.append(smember)
           SL.append(Station(net,sta,loc,comp,lat=slat,lon=slon,member=smember))

       except:
           Logfile.exception('filterBestSolution', '<' + s + '>')
           continue

    fobj.close()

    M = list(set(M))

    Logfile.add('number of clusters ' + str(len(M)),
                 'number of stations ' + str(len(SL)))

    kd = obs_kilometer2degrees(cfg.Distance('intraclusterdistance'))
    Logfile.add('icd ' + str(kd))

    maxdist = -1

    for i in SL:
        counter = 0

        for k in SL:
            if i.member == '8' and k.member == '8':
               if i.getName() != k.getName():
                  delta = loc2degrees(i, k)

                  if delta > maxdist:
                      maxdist = delta

                  if delta < kd:
                      counter +=1

        print(i, 'less then allowd ', counter)

    print('masxdist ', maxdist)
Exemple #4
0
def formatStrings(strings, format1):

    result = []

    try:
        for i in range(len(strings)):
            result.append(format1 % (strings[i]))

    except Exception:
        Logfile.exception('formatStrings', 'Illegal format', abortProg=True)

    return result
Exemple #5
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')