def cutSacByQuake(quake,staInfos,getFilename,comp=['BHE','BHN','BHZ'],\
    R=[-90,90,-180,180],outDir='SACCUT/',delta=0.01):
    time = quake.time
    YmdHMSj0 = tool.getYmdHMSj(UTCDateTime(time))
    YmdHMSj1 = tool.getYmdHMSj(UTCDateTime(time + 2 * 3600 + 10))
    tmpDir = outDir + str(int(time)) + '/'
    if not os.path.exists(tmpDir):
        os.mkdir(tmpDir)
    n = 3600 * 2 / delta
    for staInfo in staInfos:
        if staInfo['la']>=R[0] and \
            staInfo['la']<=R[1] and \
            staInfo['lo']>=R[2] and \
            staInfo['lo']<=R[3]:
            print(staInfo['net'] + staInfo['sta'])
            for c in comp:
                sacName = staInfo['net'] + staInfo['sta'] + c + '.SAC'
                fileNames=getFilename(staInfo['net'],staInfo['sta'],c,YmdHMSj0)\
                +getFilename(staInfo['net'],staInfo['sta'],c,YmdHMSj1)
                fileNames = list(set(fileNames))
                sacM = mergeSacByName(fileNames, delta0=delta)
                print(sacM)
                if not sacM == None:
                    try:
                        sacM.interpolate(int(1 / delta),
                                         starttime=time,
                                         npts=n)
                    except:
                        print('no data')
                        continue
                    else:
                        pass
                    sacM.write(tmpDir + sacName, format='SAC')
 def getSacFileNamesL(self, getFileName=originFileName):
     YmdHMSJ = getYmdHMSj(self.day)
     fNL = list()
     for comp in self.comp:
         fNL.append(getFileName(self.net, self.station,\
             comp, YmdHMSJ))
     return fNL
def preCmpAzLog(quakeL, file='/home/jiangyr/cmpaz/cmpAZ/example/eventLst'):
    with open(file, 'w+') as f:
        for quake in quakeL:
            print(os.path.basename(quake.filename))
            YmdHMSj = tool.getYmdHMSj(UTCDateTime(quake.time))
            Y = YmdHMSj
            line=Y['Y']+' '+Y['m']+' '+Y['d']+' '+Y['H']+' '+Y['M']+' '+Y['S']\
            +' '+str(quake.loc[0])+' '+str(quake.loc[1])+' '+str(quake.loc[2])+\
            ' '+str(quake.ml)+' hima '+Y['Y']+Y['m']+Y['d']+'_'+Y['H']+Y['M']+'\n'
            f.write(line)
Beispiel #4
0
def preEvent(quakeL, staInfos, filename='TOMODD/input/event.dat'):
    with open(filename, 'w+') as f:
        for i in range(len(quakeL)):
            quake = quakeL[i]
            ml = 0
            if quake.ml != None:
                if quake.ml > -2:
                    ml = quake.ml
            Y = getYmdHMSj(UTCDateTime(quake.time))
            f.write("%s  %s%02d   %.4f   %.4f    % 7.3f % 5.2f   0.15    0.51  % 5.2f   % 8d %1d\n"%\
                (Y['Y']+Y['m']+Y['d'],Y['H']+Y['M']+Y['S'],int(quake.time*100)%100,\
                    quake.loc[0],quake.loc[1],max(5,quake.loc[2]),ml,1,i,0))
def cutSacByDate(date,staInfos,getFilename,comp=['BHE','BHN','BHZ'],\
    R=[-90,90,-180,180],outDir='/home/jiangyr/cmpaz/cmpAZ/example/',delta=0.01\
    ,B=-200,E=1800,isFromO=False,decMul=10,nameMode='ML'):
    time0 = date.timestamp
    tmpDir = outDir
    if not os.path.exists(tmpDir):
        os.mkdir(tmpDir)
    n = int((E - B) / delta)
    #print(n)
    for staInfo in staInfos:
        if staInfo['la']>=R[0] and \
            staInfo['la']<=R[1] and \
            staInfo['lo']>=R[2] and \
            staInfo['lo']<=R[3]:
            print(staInfo['net'] + '.' + staInfo['sta'])
            Y = tool.getYmdHMSj(UTCDateTime(time0))
            if nameMode == 'ML':
                rawDir = outDir + '/' + Y['Y'] + Y['m'] + Y['d'] + '/'
            if not os.path.exists(rawDir):
                os.mkdir(rawDir)
            for c in comp:
                if nameMode == 'ML':
                    sacName = staInfo['sta'] + '.' + c
                fileNames = getFilename(staInfo['net'], staInfo['sta'], c, Y)
                fileNames = list(set(fileNames))
                sacM = mergeSacByName(fileNames, delta0=delta)
                print(sacM)
                if not sacM == None:
                    try:
                        sacM.interpolate(int(1 / delta), starttime=time0 + B)
                    except:
                        print('no data')
                        continue
                    else:
                        pass
                    if isFromO:
                        time0 = time0
                    adjust(sacM,loc=[staInfo['la'],staInfo['lo'],staInfo['dep']],kzTime=time0,\
                        decMul=decMul,net=staInfo['net'],sta=staInfo['sta'],\
                        chn=c,o=0)
                    os.system('mv %s  %s' % (tmpSac1, rawDir + sacName))
def cutSacByQuakeForCmpAz(quake,staInfos,getFilename,comp=['BHE','BHN','BHZ'],\
    R=[-90,90,-180,180],outDir='/home/jiangyr/cmpaz/cmpAZ/example/',delta=0.01\
    ,B=-200,E=1800,isFromO=False,decMul=10,nameMode='cmpAz',maxDT=100000):
    time0 = quake.time
    tmpDir = outDir
    if not os.path.exists(tmpDir):
        os.mkdir(tmpDir)
    n = int((E - B) / delta)
    pTimeL = quake.getPTimeL(staInfos)
    for ii in range(len(staInfos)):
        staInfo = staInfos[ii]
        if nameMode == 'ML' and len(quake) > 0 and (
                pTimeL[ii] <= 0 or (pTimeL[ii] - quake.time) > maxDT):
            print('skip')
            continue

        if staInfo['la']>=R[0] and \
            staInfo['la']<=R[1] and \
            staInfo['lo']>=R[2] and \
            staInfo['lo']<=R[3]:
            print(staInfo['net'] + staInfo['sta'])
            if nameMode == 'cmpAz':
                staDir = outDir + '/' + staInfo['net'] + '.' + staInfo[
                    'sta'] + '/'
                if not os.path.exists(staDir):
                    os.mkdir(staDir)
                rawDir = staDir + '/' + 'raw/'
            bTime = time0 + B
            eTime = time0 + E
            YmdHMSj0 = tool.getYmdHMSj(UTCDateTime(bTime))
            YmdHMSj1 = tool.getYmdHMSj(UTCDateTime(eTime))
            Y = tool.getYmdHMSj(UTCDateTime(time0))
            if nameMode == 'ML':
                rawDir = outDir + '/' + Y['Y'] + Y['m'] + Y['d'] + Y['H'] + Y[
                    'M'] + '%05.2f/' % (time0 % 60)
            if not os.path.exists(rawDir):
                os.mkdir(rawDir)
            for c in comp:
                if nameMode == 'cmpAz':
                    sacName=Y['Y']+Y['m']+Y['d']+'_'+Y['H']+Y['M']+'.'\
                    +staInfo['sta']+'.'+c
                if nameMode == 'ML':
                    sacName = staInfo['sta'] + '.' + c
                fileNames=getFilename(staInfo['net'],staInfo['sta'],c,YmdHMSj0)\
                +getFilename(staInfo['net'],staInfo['sta'],c,YmdHMSj1)
                fileNames = list(set(fileNames))
                sacM = mergeSacByName(fileNames, delta0=delta)
                print(sacM)
                if not sacM == None:
                    try:
                        sacM.interpolate(int(1 / delta),
                                         starttime=bTime,
                                         npts=n)
                    except:
                        print('no data')
                        continue
                    else:
                        pass
                    if isFromO:
                        time0 = bTime
                    adjust(sacM,loc=[staInfo['la'],staInfo['lo'],staInfo['dep']],kzTime=time0,\
                        decMul=decMul,eloc=quake.loc,net=staInfo['net'],sta=staInfo['sta'],\
                        chn=c)
                    os.system('mv %s  %s' % (tmpSac1, rawDir + sacName))