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
4cb772a7
Commit
4cb772a7
authored
2 years ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Refactor gps plot code
parent
9fa4184c
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/view/plotting/gps_dialog.py
+52
-34
52 additions, 34 deletions
sohstationviewer/view/plotting/gps_dialog.py
with
52 additions
and
34 deletions
sohstationviewer/view/plotting/gps_dialog.py
+
52
−
34
View file @
4cb772a7
...
...
@@ -7,68 +7,77 @@ from sohstationviewer.model.mseed.mseed import MSeed
from
PySide2
import
QtWidgets
,
QtCore
from
matplotlib.backends.backend_qt5agg
import
(
FigureCanvasQTAgg
as
Canvas
)
FigureCanvasQTAgg
as
Canvas
)
from
matplotlib.figure
import
Figure
from
matplotlib.axes
import
Axes
class
GPSWidget
(
QtWidgets
.
QWidget
):
def
__init__
(
self
,
parent
,
tracking_box
,
gps_points
):
def
__init__
(
self
,
parent
,
tracking_box
):
super
().
__init__
(
parent
)
self
.
tracking_box
=
tracking_box
self
.
gps_points
=
gps_points
self
.
gps_points
=
None
self
.
fig
=
Figure
(
figsize
=
(
6
,
6
),
dpi
=
100
)
self
.
canvas
=
Canvas
(
self
.
fig
)
self
.
ax
:
Axes
=
self
.
fig
.
add_axes
((
0
,
0
,
1
,
1
))
self
.
ax
.
set_facecolor
(
"
dimgray
"
)
self
.
canvas
=
Canvas
(
self
.
fig
)
self
.
ax
.
set_box_aspect
(
1
)
self
.
ax
.
set_yticks
([])
self
.
ax
.
set_xticks
([])
self
.
ax
.
spines
[
'
right
'
].
set_visible
(
False
)
self
.
ax
.
spines
[
'
left
'
].
set_visible
(
False
)
self
.
ax
.
spines
[
'
top
'
].
set_visible
(
False
)
self
.
ax
.
spines
[
'
bottom
'
].
set_visible
(
False
)
@QtCore.Slot
()
def
plot_gps
(
self
):
good_gps_points
=
[
point
for
point
in
self
.
gps_points
if
not
point
.
is_bad_point
()]
all_latitudes
=
[
point
.
latitude
for
point
in
good_gps_points
]
all_longitudes
=
[
point
.
longitude
for
point
in
good_gps_points
]
all_latitudes
=
[
point
.
latitude
for
point
in
self
.
gps_points
]
all_longitudes
=
[
point
.
longitude
for
point
in
self
.
gps_points
]
max_latitude
=
max
(
all_latitudes
)
min_latitude
=
min
(
all_latitudes
)
max_longitude
=
max
(
all_longitudes
)
min_longitude
=
min
(
all_longitudes
)
self
.
ax
.
plot
(
all_longitudes
,
all_latitudes
,
'
ws
'
,
markersize
=
3
,
markeredgecolor
=
'
black
'
)
latitude_range
=
max_latitude
-
min_latitude
longitude_range
=
max_longitude
-
min_longitude
if
latitude_range
>
longitude_range
:
longitude_average
=
(
min_longitude
+
max_longitude
)
/
2
min_longitude
=
longitude_average
-
latitude_range
/
2
max_longitude
=
longitude_average
+
latitude_range
/
2
self
.
ax
.
set_xlim
(
min_longitude
,
max_longitude
)
else
:
latitude_average
=
(
min_latitude
+
max_latitude
)
/
2
min_latitude
=
latitude_average
-
longitude_range
/
2
max_latitude
=
latitude_average
+
longitude_range
/
2
self
.
ax
.
set_yticks
([])
self
.
ax
.
set_xticks
([])
self
.
ax
.
spines
[
'
right
'
].
set_visible
(
False
)
self
.
ax
.
spines
[
'
left
'
].
set_visible
(
False
)
self
.
ax
.
spines
[
'
top
'
].
set_visible
(
False
)
self
.
ax
.
spines
[
'
bottom
'
].
set_visible
(
False
)
self
.
ax
.
plot
(
all_longitudes
,
all_latitudes
,
'
ws
'
,
markersize
=
3
,
markeredgecolor
=
'
black
'
)
if
latitude_range
>
longitude_range
:
self
.
ax
.
set_xlim
(
min_longitude
,
max_longitude
)
else
:
self
.
ax
.
set_ylim
(
min_latitude
,
max_latitude
)
self
.
ax
.
set_box_aspect
(
1
)
self
.
canvas
.
draw
()
self
.
repaint
()
class
GPSDialog
(
QtWidgets
.
QWidget
):
def
__init__
(
self
,
parent
,
gps_points
:
List
[
GPSPoint
]
):
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
()
self
.
parent
=
parent
self
.
gps_points
=
gps_points
self
.
data_path
=
None
self
.
info_text_browser
=
QtWidgets
.
QTextBrowser
(
self
)
self
.
plotting_widget
=
GPSWidget
(
self
,
self
.
info_text_browser
)
self
.
read_button
=
QtWidgets
.
QPushButton
(
'
Read/Plot
'
,
self
)
self
.
export_button
=
QtWidgets
.
QPushButton
(
'
Export
'
,
self
)
self
.
close_button
=
QtWidgets
.
QPushButton
(
'
Close
'
,
self
)
self
.
setup_ui
()
def
setup_ui
(
self
):
# The height of the dialog is chosen so that the GPS plot is flush with
# the edges of the dialog.
dialog_height
=
518
...
...
@@ -80,9 +89,6 @@ class GPSDialog(QtWidgets.QWidget):
main_layout
.
setContentsMargins
(
0
,
0
,
0
,
0
)
main_layout
.
setSpacing
(
0
)
self
.
plotting_widget
=
GPSWidget
(
self
,
self
.
info_text_browser
,
gps_points
)
main_layout
.
addWidget
(
self
.
plotting_widget
.
canvas
)
# Add a 1-pixel high widget to the main layout so that there is a
...
...
@@ -97,15 +103,12 @@ class GPSDialog(QtWidgets.QWidget):
button_layout
.
setStretch
(
1
,
3
)
button_layout
.
setSpacing
(
10
)
self
.
read_button
=
QtWidgets
.
QPushButton
(
'
Read/Plot
'
,
self
)
self
.
read_button
.
clicked
.
connect
(
self
.
plotting_widget
.
plot_gps
)
button_layout
.
addWidget
(
self
.
read_button
)
self
.
export_button
=
QtWidgets
.
QPushButton
(
'
Export
'
,
self
)
self
.
export_button
.
clicked
.
connect
(
self
.
export_gps_points
)
button_layout
.
addWidget
(
self
.
export_button
)
self
.
close_button
=
QtWidgets
.
QPushButton
(
'
Close
'
,
self
)
self
.
close_button
.
setStyleSheet
(
'
QPushButton {color: red;}
'
)
self
.
close_button
.
clicked
.
connect
(
self
.
close
)
button_layout
.
addWidget
(
self
.
close_button
)
...
...
@@ -113,13 +116,25 @@ class GPSDialog(QtWidgets.QWidget):
bottom_layout
=
QtWidgets
.
QVBoxLayout
()
bottom_layout
.
addLayout
(
button_layout
)
self
.
info_text_browser
.
setFixedHeight
(
42
)
self
.
info_text_browser
.
setHorizontalScrollBarPolicy
(
QtCore
.
Qt
.
ScrollBarAlwaysOff
)
self
.
info_text_browser
.
setVerticalScrollBarPolicy
(
QtCore
.
Qt
.
ScrollBarAlwaysOff
)
self
.
info_text_browser
.
setHorizontalScrollBarPolicy
(
QtCore
.
Qt
.
ScrollBarAlwaysOff
)
self
.
info_text_browser
.
setVerticalScrollBarPolicy
(
QtCore
.
Qt
.
ScrollBarAlwaysOff
)
self
.
info_text_browser
.
verticalScrollBar
().
setDisabled
(
True
)
self
.
info_text_browser
.
horizontalScrollBar
().
setDisabled
(
True
)
bottom_layout
.
addWidget
(
self
.
info_text_browser
)
main_layout
.
addLayout
(
bottom_layout
)
@property
def
gps_points
(
self
):
return
self
.
plotting_widget
.
gps_points
@gps_points.setter
def
gps_points
(
self
,
points
):
self
.
plotting_widget
.
gps_points
=
[
point
for
point
in
points
if
not
point
.
is_bad_point
()]
def
export_gps_points
(
self
):
folder_name
=
self
.
data_path
.
name
outside_folder
=
self
.
data_path
.
parent
...
...
@@ -138,14 +153,17 @@ class GPSDialog(QtWidgets.QWidget):
if
__name__
==
'
__main__
'
:
import
os
os
.
chdir
(
'
/Users/kle/PycharmProjects/sohstationviewer
'
)
app
=
QtWidgets
.
QApplication
(
sys
.
argv
)
# data_path = '/Users/kle/PycharmProjects/sohstationviewer/tests/test_data/Q330-sample'
data_path
=
'
/Users/kle/Documents/SOHView data/Q330/Q330_5281.sdr
'
data
=
MSeed
(
QtWidgets
.
QTextBrowser
(),
data_path
)
wnd
=
GPSDialog
(
None
,
data
.
gps_points
)
wnd
=
GPSDialog
()
wnd
.
gps_points
=
data
.
gps_points
wnd
.
data_path
=
Path
(
data_path
)
wnd
.
show
()
wnd
.
read_button
.
click
()
sys
.
exit
(
app
.
exec_
())
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