Skip to content

Commit

Permalink
Special handling of MeSO-net that have two network codes for two period
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Nov 20, 2024
1 parent 881cf8e commit 121f08f
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions HinetPy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,28 @@ def get_continuous_waveform( # noqa: PLR0915, PLR0912
if code not in NETWORK:
raise ValueError(f"{code}: Incorrect network code.")

starttime = to_datetime(starttime)
endtime = starttime + timedelta(minutes=span)

# Special handling for MeSO-net since it has two network codes:
# - 0131: Data after 20170401
# - 0231: Data 20080516-20170401
mesonet_time = NETWORK["0131"].starttime
if code == "0131" and starttime < mesonet_time:
code = "0231"
if code == "0231" and starttime >= mesonet_time:
code = "0131"
if code in ("0131", "0231") and starttime <= mesonet_time <= endtime:
msg = (
"MeSO-net has two network codes: '0131' for data after 20170401, and "
"'0231' for data 20080516-20170401. But the time span you requested "
"crosses the date 20170401. Please use the correct network code."
)
raise ValueError(msg)

time0 = NETWORK[code].starttime
# time1 = UTCTime + JST (UTC+0900) - 2 hour delay
time1 = datetime.utcnow() + timedelta(hours=9) + timedelta(hours=-2)
starttime = to_datetime(starttime)
endtime = starttime + timedelta(minutes=span)
if not time0 <= starttime < endtime <= time1:
msg = f"Data not available in the time period. Call Client.info('{code}') for help."
raise ValueError(msg)
Expand Down Expand Up @@ -1052,7 +1069,7 @@ def get_selected_stations(self, code: str):
parser.close()
return stations

def select_stations( # noqa: PLR0913
def select_stations(
self,
code,
stations=None,
Expand Down

0 comments on commit 121f08f

Please sign in to comment.