Ejemplo n.º 1
0
def init_client(username, password):
    """
    init client and check status.
    """
    client = Client(username, password)
    client.doctor()
    return client
Ejemplo n.º 2
0
def get_test_data():
    from HinetPy import Client
    client = Client(username, password)
    client.select_stations('0101', ['N.NGUH', 'N.NNMH'])
    client.get_continuous_waveform('0101', '2017-01-01T00:00', 3, outdir=path,
                        cleanup=False)
    for file in glob.glob("20170101000?0101VM.cnt"):
        os.rename(file, os.path.join(path, file))
Ejemplo n.º 3
0
def get_test_data():
    from HinetPy import Client
    client = Client(username, password)
    client.select_stations('0101', ['N.NGUH', 'N.NNMH'])
    client.get_waveform('0101',
                        '2017-01-01T00:00',
                        3,
                        outdir=path,
                        cleanup=False)
    for file in glob.glob("20170101000?0101VM.cnt"):
        os.rename(file, os.path.join(path, file))
Ejemplo n.º 4
0
def get_test_data():
    from HinetPy import Client

    client = Client(username, password)
    client.select_stations("0101", ["N.NGUH", "N.NNMH"])
    client.get_continuous_waveform("0101",
                                   "2017-01-01T00:00",
                                   3,
                                   outdir=path,
                                   cleanup=False)
    for file in glob.glob("20170101000?0101VM.cnt"):
        os.rename(file, os.path.join(path, file))
Ejemplo n.º 5
0
 def test_client_init_and_login_succeed(self):
     Client(username, password)
Ejemplo n.º 6
0
def client():
    client = Client(username, password)
    client.select_stations('0101', ['N.AAKH', 'N.ABNH'])
    yield client
    client.select_stations('0101')
Ejemplo n.º 7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from HinetPy import Client
from datetime import datetime

username = "******"
password = "******"
client = Client(username, password)
starttime = datetime(2017, 1, 1, 0, 0)
client.get_continuous_waveform('0101', starttime, 20, threads=4)
from HinetPy import Client, win32
from datetime import datetime
client = Client("UserName", "Password")

startdates = [line.rstrip('\n') for line in open('days.txt')]
for startdate in startdates:
	print(startdate)
	client.get_arrivaltime(startdate, 1)



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)
Ejemplo n.º 10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Check if a network has more channels"""

from datetime import datetime, timedelta

from HinetPy import Client
from HinetPy.header import NETWORK
from HinetPy.win32 import _get_channels


username = "******"
password = "******"
client = Client(username, password)

difference = {}
# always set one day before today as starttime
starttime = datetime.today() - timedelta(days=1)
for code in sorted(NETWORK.keys()):
    win32, chfile = client.get_continuous_waveform(code, starttime, 1)
    count = len(_get_channels(chfile))

    if count > NETWORK[code].channels:  # more
        difference[code] = count

    for code in difference.keys():
        print(code, difference[code])
Ejemplo n.º 11
0
from datetime import datetime, timedelta
import time
from HinetPy import Client, win32
import os
from obspy import read

sDate = datetime(2012, 2, 1) + timedelta(days=0)  #days=30+100+30-400)
count = 200  # how many days

spanDays = 1  #365*8
client = Client("***", "***")  #username passwd
filename = "event_lst"
client.get_arrivaltime(sDate, spanDays, filename=filename)

eventDir = 'eventDir/'
eventDir2 = 'event/'

while count > 0:
    try:
        cmd = "rm -r " + eventDir + "/D*"
        os.system(cmd)
        count = count - 1
        sDate = sDate + timedelta(days=1)
        client.get_arrivaltime(sDate, spanDays, filename=filename)
        ### set requirement
        client.get_event_waveform(sDate.strftime("%Y-%m-%d %H:%M:%S"),\
            (sDate+timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S"),minmagnitude=-1, maxmagnitude=9.9,\
            include_unknown_mag=True,minlatitude=30, maxlatitude=50, minlongitude=125,\
            maxlongitude=150)
        cmd = "mv  D* " + eventDir
        os.system(cmd)
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
def client():
    client = Client(username, password)
    client.select_stations("0101", ["N.AAKH", "N.ABNH"])
    yield client
    client.select_stations("0101")
Ejemplo n.º 14
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Check if a network has more channels"""

from datetime import datetime, timedelta

from HinetPy import Client
from HinetPy.header import NETWORK
from HinetPy.win32 import _get_channels


username = "******"
password = "******"
client = Client(username, password)

difference = {}
# always set one day before today as starttime
starttime = datetime.today() - timedelta(days=1)
for code in sorted(NETWORK.keys()):
    win32, chfile = client.get_waveform(code, starttime, 1)
    count = len(_get_channels(chfile))

    if count > NETWORK[code].channels:  # more
        difference[code] = count

    for code in difference.keys():
        print(code, difference[code])
Ejemplo n.º 15
0
def client():
    client = Client()
    yield client
Ejemplo n.º 16
0
 def test_client_init_and_login_fail(self):
     """ Raise ConnectionError if requests fails. """
     with pytest.raises(requests.ConnectionError):
         Client("anonymous", "anonymous")
Ejemplo n.º 17
0
 def test_login_after_init(self):
     client = Client()
     client.login(username, password)
Ejemplo n.º 18
0
    )
    sys.exit('\n')

# Read input
cmt_file = str(sys.argv[1])  # CMT catalog
out_dir = str(sys.argv[2])  # output folder
netid = str(
    sys.argv[3]
)  # Network No. separated by comma (e.g., 0101,0103 (Hi-net and F-net))

os.system('mkdir -p %s' % (out_dir))

# Please input Hinet username and passwd
username = ""
password = ""
client = Client(username, password)

# Read catalog
doc = open('%s' % (cmt_file), 'r')
cmtlist = doc.readlines()
doc.close()

# Downloading parameters
TWL = 2.5  # time before the event, e.g., 2.5 minutes
duration = 8  # data duration, e.g., 8 minutes
startline = 0
# starting line in the catalog
minmag = 0
maxmag = 10

# Loop events to download data