Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lemi2seed
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Public
MT
lemi2seed
Commits
b84d72f0
Commit
b84d72f0
authored
3 years ago
by
Maeva Pourpoint
Browse files
Options
Downloads
Patches
Plain Diff
Add type hints
parent
15d8f77c
No related branches found
Branches containing commit
No related tags found
1 merge request
!3
Util functions
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lemi2seed/utils.py
+7
-7
7 additions, 7 deletions
lemi2seed/utils.py
with
7 additions
and
7 deletions
lemi2seed/utils.py
+
7
−
7
View file @
b84d72f0
...
...
@@ -13,8 +13,8 @@ import logging.config
import
re
from
obspy
import
UTCDateTime
from
typing
import
Any
,
Dict
,
List
from
pathlib
import
Path
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Tuple
# Read logging config file
log_file_path
=
Path
(
__file__
).
parent
.
joinpath
(
'
logging.conf
'
)
...
...
@@ -99,22 +99,22 @@ def check_serial_number(serial_number: str, equipment: str) -> bool:
return
False
def
convert_coordinate
(
coordinate
,
hemisphere
)
:
def
convert_coordinate
(
coordinate
:
str
,
hemisphere
:
str
)
->
Optional
[
float
]
:
"""
Convert coordinates outputted by LEMI to decimal degrees.
"""
if
hemisphere
not
in
[
'
N
'
,
'
S
'
,
'
E
'
,
'
W
'
]:
logger
.
error
(
"
Unexpected hemisphere - {} - listed in data file!
"
.
format
(
hemisphere
))
return
None
try
:
coordinate
=
float
(
coordinate
)
/
100
coordinate
=
float
(
coordinate
)
/
100
# type: ignore
except
ValueError
:
logger
.
error
(
"
Failed to convert geographic coordinate - {} - to
"
"
decimal degrees!
"
.
format
(
coordinate
))
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.
"""
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
):
...
...
@@ -128,7 +128,7 @@ def convert_time(time_stamp):
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.
"""
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
)]
...
...
@@ -148,7 +148,7 @@ def get_e_loc(e_info: Dict) -> Dict:
return
e_loc
def
get_run_list
(
nbr_runs
)
:
def
get_run_list
(
nbr_runs
:
int
)
->
List
[
str
]
:
"""
Get list of run ids.
"""
return
[
chr
(
x
)
for
x
in
range
(
ord
(
'
a
'
),
ord
(
'
a
'
)
+
nbr_runs
)]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment