Skip to content

Commit

Permalink
get locations from csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdicaprio committed Apr 12, 2024
1 parent 74301f4 commit acdb760
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions toshi_hazard_post/locations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import csv

from collections import namedtuple
from pathlib import Path
from typing import Dict, List, Tuple

from nzshm_common.grids.region_grid import load_grid
Expand All @@ -22,6 +26,19 @@ def stat_test_missing() -> List[Tuple[float, float]]:
return [(round(loc[0], 1), round(loc[1], 1)) for loc in locations]


def locations_from_csv(locations_filepath):

locations = []
locations_filepath = Path(locations_filepath)
with locations_filepath.open('r') as locations_file:
reader = csv.reader(locations_file)
Location = namedtuple("Location", next(reader), rename=True)
for row in reader:
location = Location(*row)
locations.append((float(location.lat), float(location.lon)))
return locations


def transpower_locs() -> List[Tuple[float, float]]:

return [
Expand Down Expand Up @@ -342,6 +359,8 @@ def lat_lon(id):
locations += stat_test_missing()
elif location_spec == 'TP':
locations += transpower_locs()
elif Path(location_spec).exists():
locations += locations_from_csv(location_spec)
else:
locations += load_grid(location_spec)
if config.location_limit:
Expand Down

0 comments on commit acdb760

Please sign in to comment.