HinetPy.client 模块

class HinetPy.client.Client(user=None, password=None, timeout=60, retries=3, sleep_time_in_seconds=5, max_sleep_count=30)

Wrapper client to request waveform, catalog and manipulate stations.

参数:
  • user (str) – Hi-net账户用户名。

  • password (str) – Hi-net账户密码。

  • timeout (float) – Time to wait for the server to send data before giving up.

  • retries (int) – How many times to retry if a request fails.

  • sleep_time_in_seconds (float) – Sleep time between each data status check. See notes below.

  • max_sleep_count (int) – Maximum number of sleeps before failing. See notes below.

备注

The Hi-net server ususally spends 10-60 seconds on data preparation after receiving a data request. During the data preparation, users are NOT allowed to post another data request. So users have to wait until the data is ready.

HinetPy checks data status every sleep_time_in_seconds seconds for no more than max_sleep_count times, until the data is ready. If the data status is still NOT ready after max_sleep_count * sleep_time_in_seconds seconds, it most likely means something goes wrong with the data request. Then, HinetPy will retry to request the data retries times. Ususally, you don’t need to modify these parameters unless you know what you’re doing.

示例

>>> from HinetPy import Client
>>> client = Client("username", "password")
doctor()

做检查。

This is a utility function that checks:

  • if HinetPy has a new release

  • if Hi-net web service is updated

  • if catwin32 and win2sac_32 are in PATH

>>> client.doctor()
Hi-net web service is NOT updated.
You're using the latest release (v0.x.x).
catwin32: Full path is /home/user/bin/catwin32.
win2sac_32: Full path is /home/user/bin/win2sac_32.
check_service_update()

检查Hi-net网站是否被更新。

>>> client.check_service_update()
[2017-01-01 00:00:00] INFO: Hi-net web service is NOT updated.
info(code=None)

Show information of networks.

参数:

code (None or str) – 台网代码。

示例

>>> client.info()
0101   : NIED Hi-net
0103   : NIED F-net (broadband)
0103A  : NIED F-net (strong motion)
010501 : NIED V-net (Tokachidake)
...
0703   : Aomori Prefectural Government
0705   : Shizuoka Prefectural Government
0801   : ADEP
>>> client.info("0101")
== Information of Network 0101 ==
Name: NIED Hi-net
Starttime: 20040401
No. of channels: 2336
get_arrivaltime(startdate, span, filename=None, os='DOS')

从Hi-net获取JMA走时数据

参数:
  • startdate (str, datetime.date, datetime.datetime) – 请求数据的开始时间。

  • span (int) – 数据长度,单位为天。

  • os (str) – 文件格式。”DOS” 或 “UNIX”。

  • filename (str) – 要保存的文件名。

返回:

Filename saved.

返回类型:

str

示例

>>> from datetime import date
>>> startdate = date(2010, 1, 1)
>>> client.get_arrivaltime(startdate, 5)
'measure_20100101_5.txt'
>>> client.get_arrivaltime(startdate, 5, filename="arrivaltime.txt")
'arrivaltime.txt'
get_continuous_waveform(code, starttime, span, max_span=None, data=None, ctable=None, outdir=None, threads=3, cleanup=True)

Get continuous waveform data from Hi-net server.

参数:
  • code (str) – 台网代码。见 info()

  • starttime (datetime.datetime or str) – Starttime of a data request.

  • span (int) – 数据的时间长度,单位为分钟。

  • max_span (int) – Maximum time span for sub-requests. Defaults to be determined automatically. See notes below.

  • data (str) – 下载的win32数据的文件名。默认格式: CODE_YYYYmmddHHMM_SPAN.cnt

  • ctable (str) – 下载的通道表文件名。默认格式为 CODE_YYYYmmdd.ch

  • outdir (str) – Save win32 and channel table data to a specified directory. Default is in the current directory.

  • threads (int) – Parallel data download using more threads.

  • cleanup (bool) – 在合并文件之后清理1分钟长度的cnt文件。

返回:

  • data (str) – 下载得到的win32数据的文件名。

  • ctable (str) – 下载的通道表文件的文件名。

备注

时区

All times in HinetPy and in Hi-net data are in JST (UTC+0900).

max_span

Hi-net server sets three limitations for each data request:

  1. 数据长度不大于60分钟

  2. 通道数*数据长度不得大于12000分钟

  3. 仅保留最近150次请求的数据

For example, Hi-net network has about 24000 channels. Acoording to limitation 2, the record length should be no more than 5 minutes for each data request. HinetPy “break through” the limitation by splitting a long-duration data request into several short-duration sub-requsts.

How it works

  1. 做一些检查

  2. 将长数据请求分割成多个短的数据子请求

  3. loop over all sub-requests and return the data IDs

  4. download all data based on the data IDs

  5. extract all zip files and merge them into one single win32 data

  6. clean up

示例

Request 6-minute data since 2010-01-01T05:35 (UTC+0900) from Hi-net.

>>> client.get_continuous_waveform("0101", "201001010535", 6)
('0101_201001010535_6.cnt', '0101_20100101.ch')

starttime 也支持其他常见的格式:

>>> client.get_continuous_waveform("0101", "2010-01-01 05:35", 6)
>>> client.get_continuous_waveform("0101", "2010-01-01T05:35", 6)

datetime.datetime is also supported:

>>> from datetime import datetime
>>> starttime = datetime(2010, 1, 1, 5, 35)
>>> client.get_continuous_waveform("0101", starttime, 6)
('0101_201001010535_6.cnt', '0101_20100101.ch')

Request full-day data of 2010-01-01T00:00 (UTC+0900) of F-net:

>>> client.get_continuous_waveform("0103", starttime, 1440, max_span=25)
('0103_201001010000_1440.cnt', '0103_20100101.ch')
get_event_waveform(starttime, endtime, region='00', minmagnitude=3.0, maxmagnitude=9.9, include_unknown_mag=True, mindepth=None, maxdepth=None, minlatitude=None, maxlatitude=None, minlongitude=None, maxlongitude=None, latitude=None, longitude=None, minradius=None, maxradius=None)

获取事件波形数据。

参数:
  • starttime (datetime.datetime or str) – 事件的开始事件。

  • endtime (datetime.datetime or str) – 事件的结束事件。

  • region (str) –

    限制事件在指定的区域内。可选值包括:

    • 00: Whole Japan

    • 01: Hokkaido Region

    • 02: Tohoku Region

    • 03: Kanto Region

    • 04: Chubu Region

    • 05: Kinki Region

    • 06: Chugoku/Shikoku Region

    • 07: Kyushu Region

    • 08: Others

  • minmagnitude (float) – 限制事件震级大于指定值。

  • maxmagnitude (float) – 限制事件震级小于指定值。

  • include_unknown_mag (bool) – 包括/排除未定震级的时间。

  • mindepth (float) – 限制事件深度大于指定值。

  • maxdepth (float) – 限制事件深度小于指定值。

  • minlatitude (float) – 限制台站纬度大于指定值。

  • maxlatitude (float) – 限制台站纬度小于指定值。

  • minlongitude (float) – 限制台站经度大于指定值。

  • maxlongitude (float) – 限制台站经度小于指定值。

  • latitude (float) – 指定用于半径搜索的纬度。

  • longitude (float) – 指定用于半径搜索的经度。

  • minradius (float) – 指定环形搜索区域的最小半径。

  • maxradius (float) – 指定环形搜索区域的最大半径。

get_focalmechanism(startdate, span, filename=None, os='DOS')

从Hi-net获取JMA震源机制解数据。

参数:
  • startdate (str, datetime.date, datetime.datetime) – 请求数据的开始时间。

  • span (int) – 数据长度,单位为天。

  • os (str) – 文件格式。”DOS” 或 “UNIX”。

  • filename (str) – 要保存的文件名。

返回:

Filename saved.

返回类型:

str

示例

>>> from datetime import date
>>> startdate = date(2010, 1, 1)
>>> client.get_focalmechanism(startdate, 5)
'focal_20100101_5.txt'
>>> client.get_focalmechanism(startdate, 5, filename="focal.txt")
'focal.txt'
get_selected_stations(code)

Query stations selected for requesting data.

It supports two networks: Hi-net (0101) and F-net (0103, 0103A).

参数:

code (str) – 台网代码。

返回:

stations – List of selected stations with station metadata information.

返回类型:

list of Station

示例

>>> stations = client.get_selected_stations("0101")
>>> len(stations)
16
>>> for station in stations:
...     print(station)
0101 N.WNNH 45.4883 141.885 -159.06
0101 N.SFNH 45.3346 142.1185 -81.6
>>> names = [station.name for station in stations]
>>> print(*names)
N.WNNH N.SFNH ...
get_station_list(code)

获取某个台网的台站列表。

The function only supports the following networks: Hi-net (0101), F-net (0103, 0103A), S-net (0120, 0120A) and MeSO-net (0131).

>>> stations = client.get_station_list("0101")
>>> for station in stations:
...     print(station)
0101 N.WNNH 45.4883 141.885 -159.06
0101 N.SFNH 45.3346 142.1185 -81.6
...
get_waveform(code, starttime, span, **kwargs)

自 0.6.0 版本弃用: get_waveform() is deprecated. Use get_continuous_waveform() instead.

login(user, password)

Login in the Hi-net server.

参数:
  • user (str) – Hi-net账户用户名。

  • password (str) – Hi-net账户密码。

示例

>>> from HinetPy import Client
>>> client = Client()
>>> client.login("username", "password")
select_stations(code, stations=None, minlatitude=None, maxlatitude=None, minlongitude=None, maxlongitude=None, latitude=None, longitude=None, minradius=None, maxradius=None)

获取某个台网的台站列表。

It only supports the following networks: Hi-net (0101), F-net (0103, 0103A), S-net (0120, 0120A) and MeSO-net (0131).

参数:
  • code (str) – 台网代码。

  • stations (str or list) – 要选择的台站。

  • minlatitude (float) – 限制台站纬度大于指定值。

  • maxlatitude (float) – 限制台站纬度小于指定值。

  • minlongitude (float) – 限制台站经度大于指定值。

  • maxlongitude (float) – 限制台站经度小于指定值。

  • latitude (float) – 指定用于半径搜索的纬度。

  • longitude (float) – 指定用于半径搜索的经度。

  • minradius (float) – Limit to stations within the specified minimum number of degrees from the geographic point defined by the latitude and longitude parameters.

  • maxradius (float) – Limit to stations within the specified maximum number of degrees from the geographic point defined by the latitude and longitude parameters.

示例

只选择Hi-net的两个台站:

>>> client.select_stations("0101", ["N.AAKH", "N.ABNH"])
>>> len(client.get_selected_stations("0101"))
2

选择矩形框内的台站:

>>> client.select_stations(
...     "0101",
...     minlatitude=40,
...     maxlatitude=50,
...     minlongitude=140,
...     maxlongitude=150,
... )

选择环形区域内的台站:

>>> client.select_stations(
...     "0101", latitude=30, longitude=139, minradius=0, maxradius=2
... )

选择Hi-net的全部台站:

>>> client.select_stations("0101")
>>> len(client.get_selected_stations("0101"))
0
class HinetPy.client.Event(evid, origin, latitude, longitude, depth, magnitude, name, name_en)

Event class for requesting event waveforms.

class HinetPy.client.Station(code, name, latitude, longitude, elevation)

Class for Stations.