Skip to content

Commit 6899dab

Browse files
committed
Added find_staation method to station list class.
1 parent 5fc1678 commit 6899dab

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

gmsvtoolkit/core/station_list.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
BSD 3-Clause License
44
@@ -143,6 +143,24 @@ def get_station_list(self):
143143
"""
144144
return self.site_list
145145

146+
def find_station(self, station_name):
147+
"""
148+
Returns station object for station matching station_name,
149+
otherwise returns None
150+
"""
151+
matching_list = [station for station in self.site_list if station.scode == station_name]
152+
153+
# Not found
154+
if not len(matching_list):
155+
return None
156+
157+
# Alert user that are multiple matches
158+
if len(matching_list) > 1:
159+
print("[WARNING]: multiple stations match station name %s!" % (station_name))
160+
161+
# Return match
162+
return matching_list[0]
163+
146164
if __name__ == "__main__":
147165
print("Testing Module: %s" % (sys.argv[0]))
148166
STATION_LIST = StationList(sys.argv[1])

0 commit comments

Comments
 (0)