Skip to content
Snippets Groups Projects
Commit b84d72f0 authored by Maeva Pourpoint's avatar Maeva Pourpoint
Browse files

Add type hints

parent 15d8f77c
No related branches found
No related tags found
Loading
...@@ -13,8 +13,8 @@ import logging.config ...@@ -13,8 +13,8 @@ import logging.config
import re import re
from obspy import UTCDateTime from obspy import UTCDateTime
from typing import Any, Dict, List
from pathlib import Path from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
# Read logging config file # Read logging config file
log_file_path = Path(__file__).parent.joinpath('logging.conf') log_file_path = Path(__file__).parent.joinpath('logging.conf')
...@@ -99,22 +99,22 @@ def check_serial_number(serial_number: str, equipment: str) -> bool: ...@@ -99,22 +99,22 @@ def check_serial_number(serial_number: str, equipment: str) -> bool:
return False return False
def convert_coordinate(coordinate, hemisphere): def convert_coordinate(coordinate: str, hemisphere: str) -> Optional[float]:
"""Convert coordinates outputted by LEMI to decimal degrees.""" """Convert coordinates outputted by LEMI to decimal degrees."""
if hemisphere not in ['N', 'S', 'E', 'W']: if hemisphere not in ['N', 'S', 'E', 'W']:
logger.error("Unexpected hemisphere - {} - listed in data file!" logger.error("Unexpected hemisphere - {} - listed in data file!"
.format(hemisphere)) .format(hemisphere))
return None return None
try: try:
coordinate = float(coordinate) / 100 coordinate = float(coordinate) / 100 # type: ignore
except ValueError: except ValueError:
logger.error("Failed to convert geographic coordinate - {} - to " logger.error("Failed to convert geographic coordinate - {} - to "
"decimal degrees!".format(coordinate)) "decimal degrees!".format(coordinate))
return None return None
return -coordinate if hemisphere in ["S", "W"] else coordinate return -coordinate if hemisphere in ["S", "W"] else coordinate # type: ignore
def convert_time(time_stamp): def convert_time(time_stamp: str) -> Optional[UTCDateTime]:
"""Convert time stamp recorded by LEMI to UTC.""" """Convert time stamp recorded by LEMI to UTC."""
msg = ("Failed to convert time stamp - {} - to UTC!".format(time_stamp)) msg = ("Failed to convert time stamp - {} - to UTC!".format(time_stamp))
if re.match(r"^\d{4} \d{2} \d{2} \d{2} \d{2} \d{2}$", time_stamp): if re.match(r"^\d{4} \d{2} \d{2} \d{2} \d{2} \d{2}$", time_stamp):
...@@ -128,7 +128,7 @@ def convert_time(time_stamp): ...@@ -128,7 +128,7 @@ def convert_time(time_stamp):
return None return None
def get_e_ids(nbr_runs): def get_e_ids(nbr_runs: int) -> List[Tuple[str, int]]:
"""Get permutation of run ids and channel numbers.""" """Get permutation of run ids and channel numbers."""
run_list = get_run_list(nbr_runs) run_list = get_run_list(nbr_runs)
return [(i, j) for i in run_list for j in range(1, NBR_E_CHANNEL_MAX + 1)] return [(i, j) for i in run_list for j in range(1, NBR_E_CHANNEL_MAX + 1)]
...@@ -148,7 +148,7 @@ def get_e_loc(e_info: Dict) -> Dict: ...@@ -148,7 +148,7 @@ def get_e_loc(e_info: Dict) -> Dict:
return e_loc return e_loc
def get_run_list(nbr_runs): def get_run_list(nbr_runs: int) -> List[str]:
"""Get list of run ids.""" """Get list of run ids."""
return [chr(x) for x in range(ord('a'), ord('a') + nbr_runs)] return [chr(x) for x in range(ord('a'), ord('a') + nbr_runs)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment