Skip to content

Commit

Permalink
Client.get_selected_stations: Be more careful with checking the parse…
Browse files Browse the repository at this point in the history
…d values
  • Loading branch information
seisman committed Jul 12, 2024
1 parent 30b7e28 commit 3eab71b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions HinetPy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,15 +993,15 @@ def get_station_list(self, code):
raise ValueError("Only support Hi-net, F-net, S-net and MeSO-net.")
return stations

def get_selected_stations(self, code):
def get_selected_stations(self, code: str):
"""
Query stations selected for requesting data.
It supports two networks: Hi-net (0101) and F-net (0103, 0103A).
Parameters
----------
code: str
code
Network code.
Returns
Expand All @@ -1022,7 +1022,6 @@ def get_selected_stations(self, code):
>>> print(*names)
N.WNNH N.SFNH ...
"""

if code == "0101":
pattern = r"N\..{3}H"
elif code in ("0103", "0103A"):
Expand All @@ -1036,13 +1035,18 @@ def get_selected_stations(self, code):
for i, text in enumerate(parser.tabledata):
# If the target station, grep both lon and lat.
if re.match(pattern, text):
latitude, longitude, elevation = parser.tabledata[i + 3 : i + 6]
latitude = latitude.strip("N")
longitude = longitude.strip("E")
elevation = elevation.strip("m")

stations.append(
Station(
code=code,
name=text,
latitude=float(parser.tabledata[i + 3].strip("N")),
longitude=float(parser.tabledata[i + 4].strip("E")),
elevation=float(parser.tabledata[i + 5].strip("m")),
latitude=latitude,
longitude=longitude,
elevation=elevation,
)
)
parser.close()
Expand Down Expand Up @@ -1329,9 +1333,9 @@ class Station:
def __init__(self, code, name, latitude, longitude, elevation):
self.code = code
self.name = name
self.latitude = float(latitude)
self.longitude = float(longitude)
self.elevation = float(elevation)
self.latitude = float(latitude) if latitude else None
self.longitude = float(longitude) if longitude else None
self.elevation = float(elevation) if elevation else None

def __str__(self):
return (
Expand Down

0 comments on commit 3eab71b

Please sign in to comment.