This repository was archived by the owner on May 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsakeplot.py
More file actions
206 lines (144 loc) · 6.61 KB
/
sakeplot.py
File metadata and controls
206 lines (144 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# -*- coding: utf-8 -*-
##### ----------------------------- IMPORTS ----------------------------- #####
import os
import sys
import multiprocessing
import subprocess
import webbrowser
import pandas as pd
from PyQt5 import QtCore, QtWidgets, QtTest
from PyQt5.QtGui import QPixmap
from gui.sakeplot_ui import Ui_SAKEDSP
from cli import main_check
##### ------------------------------------------------------------------- #####
# init gui app
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QMainWindow()
ui = Ui_SAKEDSP()
ui.setupUi(Dialog)
Dialog.show()
_translate = QtCore.QCoreApplication.translate
script_dir=os.path.dirname(os.path.realpath(__file__))
ui.plotType.addItems(['box','violin','boxen','bar','swarm','strip'])
ui.plotValue.addItems(['Area','Ratio'])
class ctx():
obj={}
def updateImage(path):
ui.picLabel.setPixmap(QPixmap(path))
ui.picLabel.setScaledContents(True)
def setpath():
"""Set path to index file parent directory"""
# add path to original ctx.obj
widget=QtWidgets.QFileDialog()
path=widget.getExistingDirectory(None,_translate("SAKEDSP", 'Set path for index.csv'),ctx.obj['search_path'])
ui.pathEdit.setText(_translate("SAKEDSP",path))
msg=subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "setpath", path],capture_output=True)
ui.errorBrowser.setText(_translate("SAKEDSP",str(msg.stdout.decode())))
get_current_img()
ui.pathButton.clicked.connect(lambda:setpath())
def stft():
updateImage(os.path.join(script_dir,r"images\bomb2.png"))
ui.errorBrowser.setText(_translate("SAKEDSP","Processing... Check Terminal for Progess Bar"))
QtTest.QTest.qWait(100)
msg=subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "stft", "--njobs",ui.coresEdit.text()])
if msg.returncode != 0:
ui.errorBrowser.setText(_translate("SAKEDSP","ERROR: Could not perform STFT... \nCheck terminal for errors..."))
return
updateImage(os.path.join(script_dir,r"images\bomb3.png"))
ui.errorBrowser.setText(_translate("SAKEDSP",'STFT Complete!'))
ui.STFTButton.clicked.connect(lambda:stft())
def plotPSD():
"""Enter plot menu"""
freq_range= ui.PSDEdit.text()
msg=subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "plot", "--freq", freq_range, '--plot_type','psd'])
if msg.returncode != 0:
ui.errorBrowser.setText(_translate("SAKEDSP","Check Terminal for Errors"))
ui.PSDButton.clicked.connect(lambda:plotPSD())
def plotPower():
if ui.plotValue.currentText() == 'Area':
msg=subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "plot", '--plot_type','power_area','--kind',ui.plotType.currentText()])
if ui.plotValue.currentText() == 'Ratio':
msg=subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "plot", '--plot_type','power_ratio','--kind',ui.plotType.currentText()])
if msg.returncode != 0:
ui.errorBrowser.setText(_translate("SAKEDSP","Check Terminal for Errors"))
ui.PowerAreaButton.clicked.connect(lambda:plotPower())
def plotDist():
"""Enter plot menu"""
freq_range= ui.distEdit.text()
msg=subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "plot", "--freq", freq_range, '--plot_type','dist'])
if msg.returncode != 0:
ui.errorBrowser.setText(_translate("SAKEDSP","Check Terminal for Errors"))
ui.distButton.clicked.connect(lambda:plotDist())
def verify():
"""
Manual verification of PSDs
"""
#update threshold
threshold= ui.threshEdit.text()
msg=subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "verify", "--outlier_threshold", threshold])
if msg.returncode != 0:
ui.errorBrowser.setText(_translate("SAKEDSP",'ERROR: Unable to verify... \nCheck terminal for errors'))
return
ui.errorBrowser.setText(_translate("SAKEDSP",'Verified!'))
updateImage(os.path.join(script_dir,r"images\bomb4.png"))
ui.verifyButton.clicked.connect(lambda:verify())
def norm_changed():
"""
Manual verification of PSDs
"""
if ui.checkBoxNorm.isChecked():
subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "normalize", "--enable", "true", "--column", ui.normCol.currentText(), "--group", ui.normGroup.currentText()])
else:
subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "normalize", "--enable", "false", "--column", ui.normCol.currentText(), "--group", ui.normGroup.currentText()])
ui.checkBoxNorm.stateChanged.connect(lambda:norm_changed())
def norm_col_changed():
"""
Manual verification of PSDs
"""
try:
index=pd.read_csv(os.path.join(ctx.obj['search_path'],'index.csv'))
ui.normGroup.clear()
if ui.normCol.currentText() == 'transform':
ui.normGroup.addItems(['total_power'])
else:
ui.normGroup.addItems(index[ui.normCol.currentText()].unique())
norm_changed()
except:pass
ui.normCol.activated.connect(lambda:norm_col_changed())
ui.normGroup.activated.connect(lambda:norm_changed())
def openSettings():
webbrowser.open(os.path.join(script_dir, os.path.join(ctx.obj['search_path'],r"settings.yaml")))
ui.actionSettings.triggered.connect(lambda:openSettings())
def get_current_img():
subprocess.run(["python", os.path.join(script_dir,r"cli.py"), "checkpath"])
ctx.obj = main_check(ctx)
if os.path.isfile(ctx.obj['power_mat_verified_path']):
img=r"images\bomb4.png"
elif os.path.isfile(ctx.obj['power_mat_path']):
img=r"images\bomb3.png"
elif os.path.isfile(ctx.obj['index_path']):
img=r"images\bomb2.png"
else:
img=r"images\bomb1.png"
updateImage(os.path.join(script_dir,img))
#get groups and columns
try:
ui.normCol.clear()
ui.normGroup.clear()
index=pd.read_csv(os.path.join(ctx.obj['search_path'],'index.csv'))
ui.normCol.addItems(['transform']+list(index.columns)[list(index.columns).index('stop_time')+1:-1])
norm_col_changed()
except:pass
# Execute if module runs as main program
if __name__ == '__main__':
# define ctx.obj path
ctx.obj = main_check(ctx)
if not os.path.isdir(ctx.obj['search_path']):
ctx.obj['search_path']=""
ui.coresEdit.setText(str(int(multiprocessing.cpu_count()*.8)))
ui.pathEdit.setText(_translate("SAKEDSP", ctx.obj['search_path']))
ui.threshEdit.setText(_translate("SAKEDSP", str(ctx.obj['outlier_threshold'])))
ui.checkBoxNorm.setChecked(ctx.obj['normalize'])
norm_changed()
get_current_img()
app.exec_()