Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOHViewer
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
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
PASSOFT
SOHViewer
Commits
c299282f
Commit
c299282f
authored
2 years ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Refactor method that extracts GPS point from log
parent
705490db
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sohstationviewer/model/mseed/mseed.py
+55
-58
55 additions, 58 deletions
sohstationviewer/model/mseed/mseed.py
with
55 additions
and
58 deletions
sohstationviewer/model/mseed/mseed.py
+
55
−
58
View file @
c299282f
...
...
@@ -336,67 +336,64 @@ class MSeed(DataTypeModel):
# preconditions hold and raise an error if not.
self
.
check_q330_gps_status_format
(
log_lines
[
idx
:
idx
+
13
])
last_timemark
=
log_lines
[
idx
+
11
][
19
:]
fix_type
=
log_lines
[
idx
+
3
][
10
:]
# If fix type is off, there is no location data available
# so we set them all to 0.
if
fix_type
==
'
OFF
'
:
self
.
gps_points
.
append
(
GPSPoint
(
last_timemark
,
fix_type
,
0
,
0
,
0
,
0
)
)
continue
if
fix_type
==
'
NONE
'
and
log_lines
[
idx
+
1
]
==
'
Time:
'
:
self
.
gps_points
.
append
(
GPSPoint
(
last_timemark
,
fix_type
,
0
,
0
,
0
,
0
)
)
continue
num_sats_used
=
int
(
log_lines
[
idx
+
8
].
split
(
'
:
'
)[
1
])
# Height is encoded as a float followed by the unit. We
# don't know how many characters the unit is composed of,
# so we have to loop through the height string backward
# until we can detect the end of the height value.
height_str
:
str
=
log_lines
[
idx
+
4
].
split
(
'
:
'
)[
1
]
# Start pass the end of the string and look backward one
# index every iteration so we don't have to add 1 to the
# final index.
i
=
len
(
height_str
)
current_char
=
height_str
[
i
-
1
]
while
current_char
!=
'
.
'
and
not
current_char
.
isnumeric
():
i
-=
1
current_char
=
height_str
[
i
-
1
]
height
=
float
(
height_str
[:
i
])
# Latitude and longitude are encoded in the format
# <degree><decimal minute><cardinal direction>. For
# latitude, <degree> has two characters, while <degree> for
# longitude has three.
raw_latitude
=
log_lines
[
idx
+
5
].
split
(
'
:
'
)[
1
]
lat_degree
=
int
(
raw_latitude
[:
2
])
lat_minute
=
float
(
raw_latitude
[
2
:
-
1
])
/
60
latitude
=
lat_degree
+
lat_minute
if
raw_latitude
[
-
1
].
lower
()
==
'
s
'
:
latitude
=
-
latitude
raw_longitude
=
log_lines
[
idx
+
6
].
split
(
'
:
'
)[
1
]
long_degree
=
int
(
raw_longitude
[:
3
])
long_minute
=
float
(
raw_longitude
[
3
:
-
1
])
/
60
longitude
=
long_degree
+
long_minute
if
raw_longitude
[
-
1
].
lower
()
==
'
s
'
:
longitude
=
-
longitude
# Make latitude and longitude always nonnegative to make
# plotting easier. Latitude ranges from -90 to 90, while
# longitude ranges from -180 to 180.
latitude
+=
90
longitude
+=
180
point
=
self
.
extract_gps_point
(
log_lines
[
idx
:
idx
+
12
])
print
(
point
)
self
.
gps_points
.
append
(
GPSPoint
(
last_timemark
,
fix_type
,
num_sats_used
,
height
,
latitude
,
longitude
)
point
)
def
extract_gps_point
(
self
,
gps_status_lines
:
List
[
str
])
->
GPSPoint
:
print
(
gps_status_lines
)
# Last timemark and fix type are always available, so we have to get
# them before doing anything else.
last_timemark
=
gps_status_lines
[
11
][
19
:]
fix_type
=
gps_status_lines
[
3
][
10
:]
# If location data is missing, we set them to 0.
if
gps_status_lines
[
5
]
==
'
Latitude:
'
:
return
GPSPoint
(
last_timemark
,
fix_type
,
0
,
0
,
0
,
0
)
num_sats_used
=
int
(
gps_status_lines
[
8
].
split
(
'
:
'
)[
1
])
# Height is encoded as a float followed by the unit. We
# don't know how many characters the unit is composed of,
# so we have to loop through the height string backward
# until we can detect the end of the height value.
height_str
:
str
=
gps_status_lines
[
4
].
split
(
'
:
'
)[
1
]
# Start pass the end of the string and look backward one
# index every iteration so we don't have to add 1 to the
# final index.
i
=
len
(
height_str
)
current_char
=
height_str
[
i
-
1
]
while
current_char
!=
'
.
'
and
not
current_char
.
isnumeric
():
i
-=
1
current_char
=
height_str
[
i
-
1
]
height
=
float
(
height_str
[:
i
])
# Latitude and longitude are encoded in the format
# <degree><decimal minute><cardinal direction>. For
# latitude, <degree> has two characters, while for longitude, <degree>
# has three.
# To make the GPS points easier to plot, we convert the latitude and
# longitude to decimal degree.
raw_latitude
=
gps_status_lines
[
5
].
split
(
'
:
'
)[
1
]
lat_degree
=
int
(
raw_latitude
[:
2
])
lat_minute
=
float
(
raw_latitude
[
2
:
-
1
])
/
60
latitude
=
lat_degree
+
lat_minute
if
raw_latitude
[
-
1
].
lower
()
==
'
s
'
:
latitude
=
-
latitude
raw_longitude
=
gps_status_lines
[
6
].
split
(
'
:
'
)[
1
]
long_degree
=
int
(
raw_longitude
[:
3
])
long_minute
=
float
(
raw_longitude
[
3
:
-
1
])
/
60
longitude
=
long_degree
+
long_minute
if
raw_longitude
[
-
1
].
lower
()
==
'
w
'
:
longitude
=
-
longitude
gps_point
=
GPSPoint
(
last_timemark
,
fix_type
,
num_sats_used
,
latitude
,
longitude
,
height
)
return
gps_point
@staticmethod
def
check_q330_gps_status_format
(
gps_status_lines
:
List
[
str
]):
if
gps_status_lines
[
12
].
lower
()
!=
'
pll status
'
:
...
...
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