code cleanup

This commit is contained in:
Marcel Paffrath 2016-08-02 12:21:25 +02:00
parent a8522d0fae
commit c13bdd2cf2
2 changed files with 31 additions and 90 deletions

View File

@ -93,7 +93,6 @@ class gui_control(object):
self.setConnected2SurveyState(False)
self.setSeisArrayState(True)
def gen_survey(self):
if self.checkSurveyState():
if not self.continueDialogExists('Survey'):
@ -126,13 +125,11 @@ class gui_control(object):
self.setSeisArrayState(True)
self.setConnected2SurveyState(True)
def initNewSurvey(self):
self.survey.setArtificialPick(0, 0) # artificial pick at source origin
self.setSurveyState(True)
self.setPickState(False)
def addArrayPlot(self):
self.seisArrayFigure = Figure()
self.seisArrayCanvas = FigureCanvas(self.seisArrayFigure)
@ -140,13 +137,11 @@ class gui_control(object):
self.seisArrayToolbar = NavigationToolbar(self.seisArrayCanvas, self.mainwindow)
self.mainUI.verticalLayout_tr1.addWidget(self.seisArrayToolbar)
def addSurfacePlot(self):
self.surfaceFigure = Figure()
self.surfaceCanvas = FigureCanvas(self.surfaceFigure)
self.mainUI.horizontalLayout_tr.addWidget(self.surfaceCanvas)
def addStatPlots(self):
self.statFigure_left = Figure()
self.statCanvas_left = FigureCanvas(self.statFigure_left)
@ -154,7 +149,6 @@ class gui_control(object):
self.statToolbar_left = NavigationToolbar(self.statCanvas_left, self.mainwindow)
self.mainUI.verticalLayout_br1.addWidget(self.statToolbar_left)
self.statFigure_right = Figure()
self.statCanvas_right = FigureCanvas(self.statFigure_right)
self.mainUI.verticalLayout_br2.addWidget(self.statCanvas_right)
@ -163,7 +157,6 @@ class gui_control(object):
self.addItems2StatsComboBox()
def addItems2StatsComboBox(self):
self.mainUI.comboBox_stats.insertItem(0, 'picked traces')
self.mainUI.comboBox_stats.insertItem(1, 'mean SNR')
@ -172,7 +165,6 @@ class gui_control(object):
self.mainUI.comboBox_stats.insertItem(4, 'median SPE')
self.enablePickedTools(False)
def addItems2ShotsComboBox(self):
shotnumbers = self.survey.data.keys()
shotnumbers.sort()
@ -180,7 +172,6 @@ class gui_control(object):
self.mainUI.comboBox_shots.insertItem(index, 'Shot: %s'%shotnumber)
self.mainUI.comboBox_shots.setMaxCount(len(shotnumbers))
def increaseShotnumber(self):
currentIndex = self.mainUI.comboBox_shots.currentIndex()
maxindex = self.mainUI.comboBox_shots.maxCount() - 1
@ -189,7 +180,6 @@ class gui_control(object):
else:
self.mainUI.comboBox_shots.setCurrentIndex(currentIndex + 1)
def decreaseShotnumber(self):
currentIndex = self.mainUI.comboBox_shots.currentIndex()
maxindex = self.mainUI.comboBox_shots.maxCount() - 1
@ -203,20 +193,16 @@ class gui_control(object):
shotnumber = int(self.mainUI.comboBox_shots.currentText().split()[1])
self.survey.data[shotnumber].matshow()
def addArrayAxes(self):
self.seisArrayAx = self.seisArrayFigure.add_subplot(111)
def addSurfaceAxes(self):
self.surfaceAx = self.surfaceFigure.add_subplot(111, projection = '3d')
def addStatAxes(self):
self.statAx_left = self.statFigure_left.add_subplot(111)
self.statAx_right = self.statFigure_right.add_subplot(111)
def enablePickedTools(self, bool, twoDim = False):
self.mainUI.comboBox_stats.setEnabled(bool)
self.statToolbar_left.setEnabled(bool)
@ -229,31 +215,26 @@ class gui_control(object):
if bool == False:
self.mainUI.comboBox_shots.clear()
def replotArray(self):
self.seisArrayFigure.clf()
self.addArrayAxes()
self.plotArray()
self.seisArrayCanvas.draw()
def replotSurface(self):
self.surfaceFigure.clf()
self.addSurfaceAxes()
self.plotSurface()
self.surfaceCanvas.draw()
def plotArray(self):
self.seisarray.plotArray2D(self.seisArrayAx, highlight_measured = True, plot_topo = True, twoDim = self.seisarray.twoDim)
def plotSurface(self):
if not self.seisarray.twoDim:
self.seisarray.plotSurface3D(ax = self.surfaceAx, exag = True)
self.seisarray.plotArray3D(ax = self.surfaceAx, legend = False, markersize = 3)
def InitPickedWidgets(self):
if self.checkPickState():
surveyUtils.plotScatterStats4Receivers(self.survey, self.mainUI.comboBox_stats.currentText(),
@ -262,7 +243,6 @@ class gui_control(object):
self.statAx_right, twoDim = self.survey.twoDim)
self.addItems2ShotsComboBox()
def refreshPickedWidgets(self):
self.statFigure_left.clf()
self.statFigure_right.clf()
@ -271,7 +251,6 @@ class gui_control(object):
self.statCanvas_left.draw()
self.statCanvas_right.draw()
def printSurveyTextbox(self, init = True):
if init == True:
surveytup = (0, 0, 0, 0)
@ -287,7 +266,6 @@ class gui_control(object):
string = surveyTitle + surveyText
self.mainUI.textBox_survey.setText(string)
def printSeisArrayTextbox(self, init = True):
if init == True:
seistup = (0, 0, 0)
@ -302,7 +280,6 @@ class gui_control(object):
string = seisArrayTitle + seisArrayText
self.mainUI.textBox_seisarray.setText(string)
def interpolate_receivers(self):
if not self.checkSeisArrayState():
self.printDialogMessage('No Seismic Array defined.')
@ -310,7 +287,6 @@ class gui_control(object):
self.seisarray.interpolateAll()
self.refreshSeisArrayWidgets()
def refreshSeisArrayWidgets(self):
self.replotArray()
self.replotSurface()
@ -333,7 +309,6 @@ class gui_control(object):
self.printSurveyTextbox(init = False)
print('Connected Seismic Array to active Survey object.')
def startPicker(self):
if not self.checkSurveyState():
self.printDialogMessage('No Survey defined.')
@ -351,7 +326,6 @@ class gui_control(object):
self.setPickState(True)
self.printSurveyTextbox(init = False)
def startFMTOMO(self):
if not self.checkSurveyState():
self.printDialogMessage('No Survey defined.')
@ -374,7 +348,6 @@ class gui_control(object):
else:
self.vtktools.start_dialog()
def postprocessing(self):
if not self.checkSurveyState():
self.printDialogMessage('No Survey defined.')
@ -419,7 +392,6 @@ class gui_control(object):
self.setSeisArrayState(False)
self.printDialogMessage('Loaded Survey.')
def load_seisarray(self):
disconnect = False
if self.checkSeisArrayState():
@ -450,7 +422,6 @@ class gui_control(object):
self.seisarray = seisarray
self.setSeisArrayState(True)
def save_seisarray(self):
if not self.checkSeisArrayState():
self.printDialogMessage('No Seismic Array defined.')
@ -460,7 +431,6 @@ class gui_control(object):
return
self.seisarray.saveSeisArray(filename)
def save_survey(self):
if not self.checkSurveyState():
self.printDialogMessage('No Survey defined.')
@ -470,7 +440,6 @@ class gui_control(object):
return
self.survey.saveSurvey(filename)
def setSurveyState(self, state):
if state == True:
self.mainUI.survey_active.setPixmap(self.applypixmap)
@ -478,21 +447,18 @@ class gui_control(object):
elif state == False:
self.mainUI.survey_active.setPixmap(self.cancelpixmap)
def checkSurveyState(self):
if self.survey == None:
return False
else:
return True
def checkSeisArrayState(self):
if self.seisarray == None:
return False
else:
return True
def setPickState(self, state):
if state == True and self.checkSurveyState():
self.mainUI.picked_active.setPixmap(self.applypixmap)
@ -510,7 +476,6 @@ class gui_control(object):
self.enablePickedTools(False)
self.survey.picked = False
def setSeisArrayState(self, state):
if state == True:
self.mainUI.seisarray_active.setPixmap(self.applypixmap)
@ -522,14 +487,12 @@ class gui_control(object):
if self.seisArrayFigure is not None:
self.seisArrayFigure.clf()
def setConnected2SurveyState(self, state):
if state == True:
self.mainUI.seisarray_on_survey_active.setPixmap(self.applypixmap)
elif state == False:
self.mainUI.seisarray_on_survey_active.setPixmap(self.cancelpixmap)
def checkConnected2SurveyState(self):
if self.checkSurveyState():
if self.survey.seisarray != None:
@ -537,14 +500,12 @@ class gui_control(object):
else:
return False
def checkPickState(self):
if not self.survey:
self.printDialogMessage('No Survey defined.')
return
return self.survey.picked
def printDialogMessage(self, message):
qmb = QtGui.QMessageBox()
qmb.setText(message)
@ -552,7 +513,6 @@ class gui_control(object):
qmb.setIcon(QtGui.QMessageBox.Warning)
qmb.exec_()
def continueDialogExists(self, name):
qmb = QtGui.QMessageBox()
qmb.setText('%s object already exists. Overwrite?'%name)
@ -564,7 +524,6 @@ class gui_control(object):
else:
return False
def continueDialogMessage(self, message):
qmb = QtGui.QMessageBox()
qmb.setText(message)
@ -576,7 +535,6 @@ class gui_control(object):
else:
return False
def exitApp(self):
QtCore.QCoreApplication.instance().quit()
@ -590,4 +548,3 @@ if __name__ == "__main__":
gui = gui_control()
sys.exit(app.exec_())

View File

@ -45,6 +45,7 @@ def getMaxCPU():
import multiprocessing
return multiprocessing.cpu_count()
class Gen_SeisArray(object):
def __init__(self, mainwindow):
self.mainwindow = mainwindow
@ -65,6 +66,7 @@ class Gen_SeisArray(object):
def start_dialog(self):
if self.qdialog.exec_():
self.refresh_selection()
if self.ui.radioButton_interpolatable.isChecked():
self.seisarray = seismicArrayPreparation.SeisArray(self.recfile, True)
elif self.ui.radioButton_normal.isChecked():
@ -75,8 +77,14 @@ class Gen_SeisArray(object):
self.seisarray.addMeasuredTopographyPoints(self.ptsfile)
self.executed = True
else:
self.refresh_selection()
self.executed = False
def refresh_selection(self):
self.srcfile = self.ui.lineEdit_src.text()
self.recfile = self.ui.lineEdit_rec.text()
self.ptsfile = self.ui.lineEdit_pts.text()
def get_seisarray(self):
if self.seisarray is not None:
return self.seisarray
@ -96,7 +104,6 @@ class Gen_SeisArray(object):
self.ui.lineEdit_pts.setText(openFile('Open measured points file.'))
class Gen_Survey_from_SA(object):
def __init__(self, mainwindow, seisarray):
self.mainwindow = mainwindow
@ -118,13 +125,20 @@ class Gen_Survey_from_SA(object):
def start_dialog(self):
if self.qdialog.exec_():
self.refresh_selection()
self.survey = activeSeismoPick.Survey(self.obsdir, seisArray = self.seisarray,
useDefaultParas = True, fstart = self.fstart,
fend = self.fend)
self.executed = True
else:
self.refresh_selection()
self.executed = False
def refresh_selection(self):
self.obsdir = self.ui.lineEdit_obs.text()
self.fstart = self.ui.fstart.text()
self.fend = self.ui.fend.text()
def get_survey(self):
return self.survey
@ -157,13 +171,22 @@ class Gen_Survey_from_SR(object):
def start_dialog(self):
if self.qdialog.exec_():
self.refresh_selection()
self.survey = activeSeismoPick.Survey(self.obsdir, self.srcfile, self.recfile,
useDefaultParas = True,
fstart = self.fstart, fend = self.fend)
self.executed = True
else:
self.refresh_selection()
self.executed = False
def refresh_selection(self):
self.obsdir = self.ui.lineEdit_obs.text()
self.srcfile = self.ui.lineEdit_src.text()
self.recfile = self.ui.lineEdit_rec.text()
self.fstart = self.ui.fstart.text()
self.fend = self.ui.fend.text()
def get_survey(self):
return self.survey
@ -256,7 +279,6 @@ class Call_autopicker(object):
self.snrCanvas.draw()
def start_dialog(self):
self.init_last_selection()
self.plotDynSNR()
if self.qdialog.exec_():
self.refresh_selection()
@ -294,19 +316,6 @@ class Call_autopicker(object):
self.p1 = float(self.ui.p1.value())
self.p2 = float(self.ui.p2.value())
def init_last_selection(self):
self.ui.ncores.setValue(self.ncores)
self.ui.lineEdit_vmin.setText(str(self.vmin))
self.ui.lineEdit_vmax.setText(str(self.vmax))
self.ui.slider_folm.setValue(self.folm)
self.ui.checkBox_AIC.setChecked(self.AIC)
self.ui.lineEdit_aicleft.setText(str(self.aicwindow[0]))
self.ui.lineEdit_aicright.setText(str(self.aicwindow[1]))
self.ui.shift_snr.setValue(self.shiftSNR)
self.ui.shift_snr.setValue(self.shiftDist)
self.ui.p1.setValue(self.p1)
self.ui.p2.setValue(self.p2)
def connectButtons(self):
QtCore.QObject.connect(self.ui.slider_folm, QtCore.SIGNAL("valueChanged(int)"), self.refreshFolm)
QtCore.QObject.connect(self.ui.shift_snr, QtCore.SIGNAL("valueChanged(int)"), self.plotDynSNR)
@ -324,7 +333,6 @@ class Call_autopicker(object):
self.ui.lineEdit_rec.setText(openFile('Open receiverfile.'))
class Call_FMTOMO(object):
def __init__(self, mainwindow, survey):
self.mainwindow = mainwindow
@ -343,7 +351,6 @@ class Call_FMTOMO(object):
self.connectButtons()
def start_dialog(self):
self.init_last_selection()
if self.qdialog.exec_():
self.refresh_selection()
@ -383,22 +390,6 @@ class Call_FMTOMO(object):
self.simuldir = self.ui.simuldir.text()
self.picks_dir = os.path.join(self.simuldir, 'picks')
def init_last_selection(self):
self.ui.fmtomo_dir.setText(self.fmtomo_dir)
self.ui.nIter.setValue(self.nIter)
self.ui.nproc.setValue(self.nproc)
self.ui.btop.setText(str(self.btop))
self.ui.bbot.setText(str(self.bbot))
self.ui.pgrid_x.setValue(self.propgrid[0])
self.ui.pgrid_y.setValue(self.propgrid[1])
self.ui.pgrid_z.setValue(self.propgrid[2])
self.ui.invgrid_x.setValue(self.vgrid[0])
self.ui.invgrid_y.setValue(self.vgrid[1])
self.ui.invgrid_z.setValue(self.vgrid[2])
self.ui.cushion.setValue(self.cushionfactor)
self.ui.customgrid.setText(self.customgrid)
self.ui.simuldir.setText(self.simuldir)
def connectButtons(self):
QtCore.QObject.connect(self.ui.browse_tomodir, QtCore.SIGNAL("clicked()"), self.chooseFMTOMOdir)
QtCore.QObject.connect(self.ui.browse_customgrid, QtCore.SIGNAL("clicked()"), self.chooseCustomgrid)
@ -418,7 +409,7 @@ class Call_VTK_dialog(object):
def __init__(self, mainwindow):
self.mainwindow = mainwindow
self.init_dialog()
#self.refresh_selection()
self.refresh_selection()
self.start_dialog()
def init_dialog(self):
@ -430,22 +421,15 @@ class Call_VTK_dialog(object):
self.connectButtons()
def start_dialog(self):
#self.init_last_selection()
self.qdialog.exec_()
#self.refresh_selection()
self.refresh_selection()
# def refresh_selection(self):
# self.vg = self.ui.lineEdit_vg.text()
# self.vgout = self.ui.lineEdit_vgout.text()
# self.rays = self.ui.lineEdit_rays.text()
# self.raysout = self.ui.lineEdit_raysout.text()
def refresh_selection(self):
self.vg = self.ui.lineEdit_vg.text()
self.vgout = self.ui.lineEdit_vgout.text()
self.rays = self.ui.lineEdit_rays.text()
self.raysout = self.ui.lineEdit_raysout.text()
# def init_last_selection(self):
# self.ui.lineEdit_vg.setText(self.vg)
# self.ui.lineEdit_vgout.setText(self.vgout)
# self.ui.lineEdit_rays.setText(self.rays)
# self.ui.lineEdit_raysout.setText(self.raysout)
def checkVgStartButton(self):
ui = self.ui
if ui.radioButton_rel.isChecked():