예제 #1
0
 def test_extract_sac_4(self):
     outdir = os.path.join(pwd, "test4")
     win32.extract_sac(data, ctable, filter_by_name="N.NG*", outdir=outdir)
     sac = sorted(glob.glob(os.path.join(outdir, "N.*.SAC")))
     filelist = ["N.NGUH.E.SAC", "N.NGUH.N.SAC", "N.NGUH.U.SAC"]
     sac_to_check = [os.path.join(outdir, name) for name in filelist]
     assert sac == sac_to_check
     shutil.rmtree(outdir)
예제 #2
0
 def test_extract_sac_3(self):
     outdir = os.path.join(pwd, "test3")
     win32.extract_sac(data, ctable, filter_by_id='3e8?', outdir=outdir)
     sac = sorted(glob.glob(os.path.join(outdir, "N.*.SAC")))
     filelist = ['N.NNMH.E.SAC', 'N.NNMH.N.SAC', 'N.NNMH.U.SAC']
     sac_to_check = [os.path.join(outdir, name) for name in filelist]
     assert sac == sac_to_check
     shutil.rmtree(outdir)
예제 #3
0
def data_process(data, ctable, data_path, ctable_path):
    try:
        if (os.path.exists(data)):
            win32.extract_sac(data, ctable, outdir=data_path)
            win32.extract_pz(ctable, outdir=ctable_path)
        else:
            print('no file: %s' % (path))
    except:
        print('error %s' % (path))
예제 #4
0
 def test_extract_sac_4(self):
     outdir = os.path.join(pwd, "test4")
     win32.extract_sac(data, ctable, filter_by_name='N.NG*', outdir=outdir)
     sac = sorted(glob.glob(os.path.join(outdir, "N.*.SAC")))
     filelist = ['N.NGUH.E.SAC',
                 'N.NGUH.N.SAC',
                 'N.NGUH.U.SAC']
     sac_to_check = [os.path.join(outdir, name) for name in filelist]
     assert sac == sac_to_check
     shutil.rmtree(outdir)
예제 #5
0
 def test_extract_sac_2(self):
     outdir = os.path.join(pwd, "test2")
     win32.extract_sac(data, ctable, suffix="", outdir=outdir)
     sac = sorted(glob.glob(os.path.join(outdir, "N.*.[ENU]")))
     filelist = [
         'N.NGUH.E', 'N.NGUH.N', 'N.NGUH.U', 'N.NNMH.E', 'N.NNMH.N',
         'N.NNMH.U'
     ]
     sac_to_check = [os.path.join(outdir, name) for name in filelist]
     assert sac == sac_to_check
     shutil.rmtree(outdir)
예제 #6
0
 def test_extract_sac_2(self):
     outdir = os.path.join(pwd, "test2")
     win32.extract_sac(data, ctable, suffix="", outdir=outdir)
     sac = sorted(glob.glob(os.path.join(outdir, "N.*.[ENU]")))
     filelist = ['N.NGUH.E',
                 'N.NGUH.N',
                 'N.NGUH.U',
                 'N.NNMH.E',
                 'N.NNMH.N',
                 'N.NNMH.U']
     sac_to_check = [os.path.join(outdir, name) for name in filelist]
     assert sac == sac_to_check
     shutil.rmtree(outdir)
예제 #7
0
def extract_sac(data, ctable, processes):
    """
    extract the downloaded data to the sac and pz format.
    """
    # * get dirname
    thedir = dirname(data)
    # * mkdir for the sac and pz files
    sh.mkdir("-p", join(thedir, "SAC"))
    sh.mkdir("-p", join(thedir, "PZ"))
    # * extract sac
    win32.extract_sac(data,
                      ctable,
                      with_pz=False,
                      outdir=join(thedir, "SAC"),
                      processes=processes)
    # * extract pz
    win32.extract_pz(ctable, outdir=join(thedir, "PZ"))
    # * return the sac and pz directory path
    return join(thedir, "SAC"), join(thedir, "PZ")
예제 #8
0
    def test_extract_sac_6(self):
        outdir = os.path.join(pwd, "test6")
        win32.extract_sac(data, ctable, filter_by_component=['N', 'E'],
                          outdir=outdir, with_pz=True)
        sac = sorted(glob.glob(os.path.join(outdir, "N.*.SAC")))
        filelist = ['N.NGUH.E.SAC',
                    'N.NGUH.N.SAC',
                    'N.NNMH.E.SAC',
                    'N.NNMH.N.SAC']
        sac_to_check = [os.path.join(outdir, name) for name in filelist]
        assert sac == sac_to_check

        pz = sorted(glob.glob(os.path.join(outdir, "N.*.SAC_PZ")))
        filelist = ['N.NGUH.E.SAC_PZ',
                    'N.NGUH.N.SAC_PZ',
                    'N.NNMH.E.SAC_PZ',
                    'N.NNMH.N.SAC_PZ']
        pz_to_check = [os.path.join(outdir, name) for name in filelist]
        assert pz == pz_to_check
        shutil.rmtree(outdir)
예제 #9
0
    def test_extract_sac_6(self):
        outdir = os.path.join(pwd, "test6")
        win32.extract_sac(data,
                          ctable,
                          filter_by_component=['N', 'E'],
                          outdir=outdir,
                          with_pz=True)
        sac = sorted(glob.glob(os.path.join(outdir, "N.*.SAC")))
        filelist = [
            'N.NGUH.E.SAC', 'N.NGUH.N.SAC', 'N.NNMH.E.SAC', 'N.NNMH.N.SAC'
        ]
        sac_to_check = [os.path.join(outdir, name) for name in filelist]
        assert sac == sac_to_check

        pz = sorted(glob.glob(os.path.join(outdir, "N.*.SAC_PZ")))
        filelist = [
            'N.NGUH.E.SAC_PZ', 'N.NGUH.N.SAC_PZ', 'N.NNMH.E.SAC_PZ',
            'N.NNMH.N.SAC_PZ'
        ]
        pz_to_check = [os.path.join(outdir, name) for name in filelist]
        assert pz == pz_to_check
        shutil.rmtree(outdir)
예제 #10
0
 def test_extract_sac_none_input(self):
     assert win32.extract_sac(None, None) is None
from HinetPy import Client, win32
from datetime import datetime
from shutil import copy2
client = Client("UserName",
                "password",
                sleep_time_in_seconds=60,
                max_sleep_count=2)
client.select_stations('0101', ['N.KKWH', 'N.RZTH', 'N.KAKH'])
print(client.get_selected_stations('0101'))
events = [line.rstrip('\n') for line in open("eventfile.txt")]
for starttime in events:
    print(starttime)
    outdir = starttime
    data, ctable = client.get_waveform('0101', starttime, 5, outdir=outdir)
    win32.extract_sac(data, ctable, outdir=outdir, with_pz=True)
    copy2(starttime + "_arr.txt", "./" + outdir)
예제 #12
0
     eventIndex = eventIndex + 1
 for eventName in os.listdir(eventDir):
     try:
         event = eventDir + eventName + '/'
         eventData = event + eventName + '.evt'
         eventCh = event + eventName + '.ch'
         eventInfo = event + eventName + '.txt'
         event2 = eventDir2 + eventName[1:7] + '/' + eventName + '/'
         eventPhaseFile = eventDir2 + eventName[
             1:7] + '/' + eventName + '/phaseLst'
         if os.path.exists(event2):
             1
         else:
             os.system("mkdir -p " + event2)
             os.system("cp " + eventInfo + " " + event2 + "/")
         win32.extract_sac(eventData, eventCh, outdir=event)
         with open(eventInfo, 'r', encoding="ISO-8859-1") as info:
             dateS = datetime.strptime(info.readline()[13:32],
                                       "%Y/%m/%d %H:%M:%S")
             laS = info.readline()
             la = float(laS[11:17])
             if laS[-1] == 'S':
                 la = -la
             loS = info.readline()
             lo = float(loS[12:18])
             if loS[-1] == 'W':
                 lo = -lo
         eventCode = 'J' + dateS.strftime("%Y%m%d%H%M%S")[0:-2]
         for i in range(eventIndex):
             line = eventLst[indexLst[i]]
             isFind = line.find(eventCode)
예제 #13
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from datetime import timedelta

from obspy.clients.fdsn import Client as fdsnClient
from obspy import UTCDateTime
from HinetPy import Client, win32


fdsnclient = fdsnClient('IRIS')
starttime = UTCDateTime("2005-01-01")
endtime = UTCDateTime("2005-01-03")
catalog = fdsnclient.get_events(starttime=starttime, endtime=endtime,
                                minmagnitude=6, catalog="ISC")

client = Client("username", "password")
for event in catalog:  # loop over events
    origin = event.origins[0].time.datetime
    starttime = origin + timedelta(hours=9)  # deal with TimeZone issue
    outdir = origin.strftime("%Y%m%d%H%M")

    # skip if outdir already exists to avoid overwrite
    if os.path.exits(ourdir):
        continue

    data, ctable = client.get_continuous_waveform('0101', starttime, 20, outdir=outdir)
    win32.extract_sac(data, ctable, outdir=outdir, with_pz=True)
예제 #14
0
        str(s_utc_dt)[11:13] + str(s_utc_dt)[14:16] + str(s_utc_dt)[17:19])

# Make traces starting from P & S wave onset time based on calculated travel times

from HinetPy import Client, win32
client = Client("msseo97", "minseong97")
client.select_stations('0101', ['N.TKTH'])
for i in range(0, 99):
    data, ctable = client.get_continuous_waveform('0101',
                                                  p_starttime[i],
                                                  20,
                                                  outdir="P_data_TKTH")
    win32.extract_sac(
        data,
        ctable,
        suffix="",
        outdir=
        f"/home/msseo/2019-2020_Intern/GainProb/Hinet_Gain/P_data_TKTH/{i}",
        with_pz=True)
    data, ctable = client.get_continuous_waveform('0101',
                                                  s_starttime[i],
                                                  20,
                                                  outdir="S_data_TKTH")
    win32.extract_sac(
        data,
        ctable,
        suffix="",
        outdir=
        f"/home/msseo/2019-2020_Intern/GainProb/Hinet_Gain/S_data_TKTH/{i}",
        with_pz=True)