[cleanup] add @staticmethod, some other stuff

This commit is contained in:
Marcel Paffrath 2018-07-16 14:09:06 +02:00
parent d151cdbc6d
commit 415af11f63
9 changed files with 64 additions and 40 deletions

View File

@ -860,7 +860,8 @@ class MainWindow(QMainWindow):
def inputs(self):
return self._inputs
def getRoot(self):
@staticmethod
def getRoot():
settings = QSettings()
return settings.value("data/dataRoot")
@ -1022,7 +1023,8 @@ class MainWindow(QMainWindow):
raise DatastructureError('not specified')
return fnames
def getPhaseID(self, phase):
@staticmethod
def getPhaseID(phase):
return identifyPhaseID(phase)
def get_current_event(self, eventbox=None):
@ -1150,7 +1152,8 @@ class MainWindow(QMainWindow):
self.project.remove_event(event)
self.init_events(True)
def createEventBox(self):
@staticmethod
def createEventBox():
'''
Eventbox generator.
'''
@ -1926,7 +1929,8 @@ class MainWindow(QMainWindow):
self.compare_action.setEnabled(True)
self.draw()
def checkEvent4comparison(self, event):
@staticmethod
def checkEvent4comparison(event):
if event.pylot_picks and event.pylot_autopicks:
for station in event.pylot_picks:
if station in event.pylot_autopicks:
@ -2560,13 +2564,15 @@ class MainWindow(QMainWindow):
if event.pylot_id == eventID:
return event
def get_event_paths(self, eventlist):
@staticmethod
def get_event_paths(eventlist):
eventPaths = []
for event in eventlist:
eventPaths.append(event.path)
return eventPaths
def get_event_ids(self, eventlist):
@staticmethod
def get_event_ids(eventlist):
eventIDs = []
for event in eventlist:
eventIDs.append(event.pylot_id)

View File

@ -38,6 +38,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
"""
Determine phase onsets automatically utilizing the automatic picking
algorithms by Kueperkoch et al. 2010/2012.
:param obspyDMT_wfpath: if obspyDMT is used, name of data directory ("raw" or "processed")
:param input_dict:
:type input_dict:
:param parameter: PylotParameter object containing parameters used for automatic picking
@ -200,8 +201,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
events.append(os.path.join(datapath, eventID))
else:
# autoPyLoT was initialized from GUI
events = []
events.append(eventid)
events = [eventid]
evID = os.path.split(eventid)[-1]
locflag = 2
else:

View File

@ -76,6 +76,7 @@ def modify_inputs(ctrfn, root, nllocoutn, phasefn, tttn):
def locate(fnin, parameter=None):
"""
takes an external program name and tries to run it
:param parameter: PyLoT Parameter object
:param fnin: external program name
:return: None
"""

View File

@ -506,7 +506,8 @@ class PDFstatistics(object):
return rlist
def writeThetaToFile(self, array, out_dir):
@staticmethod
def writeThetaToFile(array, out_dir):
"""
Method to write array like data to file. Useful since acquiring can take
serious amount of time when dealing with large databases.

View File

@ -226,8 +226,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None, linecolor='k'):
# get zero crossings after most likely pick
# initial onset is assumed to be the first zero crossing
# first from unfiltered trace
zc1 = []
zc1.append(Pick)
zc1 = [Pick]
index1 = []
i = 0
for j in range(ipick[0][1], ipick[0][len(t[ipick]) - 1]):
@ -272,8 +271,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None, linecolor='k'):
# now using filterd trace
# next zero crossings after most likely pick
zc2 = []
zc2.append(Pick)
zc2 = [Pick]
index2 = []
i = 0
for j in range(ipick[0][1], ipick[0][len(t[ipick]) - 1]):

View File

@ -263,7 +263,8 @@ class Metadata(object):
return None, None
def _read_dless(self, path_to_inventory):
@staticmethod
def _read_dless(path_to_inventory):
exc = None
try:
parser = Parser(path_to_inventory)
@ -272,7 +273,8 @@ class Metadata(object):
return parser, exc
def _read_inventory_file(self, path_to_inventory):
@staticmethod
def _read_inventory_file(path_to_inventory):
exc = None
try:
inv = read_inventory(path_to_inventory)
@ -582,9 +584,6 @@ def restitute_data(data, metadata, unit='VEL', force=False, ncores=0):
takes a data stream and a path_to_inventory and returns the corrected
waveform data stream
:param data: seismic data stream
:param invtype: type of found metadata
:param inobj: either list of metadata files or `obspy.io.xseed.Parser`
object
:param unit: unit to correct for (default: 'VEL')
:param force: force restitution for already corrected traces (default:
False)

View File

@ -162,7 +162,6 @@ class Event(ObsPyEvent):
"""
Add automatic picks to event
:param autopicks: automatic picks to add to event
:type autopicks dict:
:return:
:rtype: None
"""

View File

@ -541,7 +541,7 @@ def isSorted(iterable):
False
"""
assert isIterable(iterable), 'object is not iterable; object: {' \
'0}'.format(iterable)
'}'.format(iterable)
if type(iterable) is str:
iterable = [s for s in iterable]
return sorted(iterable) == iterable

View File

@ -242,7 +242,8 @@ class ComparisonWidget(QWidget):
def clf(self):
self.canvas.figure.clf()
def hasvalue(self, sender):
@staticmethod
def hasvalue(sender):
text = sender.currentText()
index = sender.findText(text.upper())
return index
@ -895,7 +896,8 @@ class PylotCanvas(FigureCanvas):
fname += '.png'
self.figure.savefig(fname)
def calcPanZoom(self, origin, lower_b, upper_b, factor, positive):
@staticmethod
def calcPanZoom(origin, lower_b, upper_b, factor, positive):
d_lower = abs(origin - lower_b)
d_upper = abs(origin - upper_b)
@ -1029,7 +1031,8 @@ class PylotCanvas(FigureCanvas):
def clearPlotDict(self):
self.plotdict = dict()
def calcPlotPositions(self, wfdata, compclass):
@staticmethod
def calcPlotPositions(wfdata, compclass):
possible_plot_pos = list(range(len(wfdata)))
plot_positions = {}
for trace in wfdata:
@ -1173,16 +1176,20 @@ class PylotCanvas(FigureCanvas):
self.setYLims(ax, zoomy)
self.draw()
def getXLims(self, ax):
@staticmethod
def getXLims(ax):
return ax.get_xlim()
def getYLims(self, ax):
@staticmethod
def getYLims(ax):
return ax.get_ylim()
def setXLims(self, ax, lims):
@staticmethod
def setXLims(ax, lims):
ax.set_xlim(lims)
def setYLims(self, ax, lims):
@staticmethod
def setYLims(ax, lims):
ax.set_ylim(lims)
def setYTickLabels(self, pos, labels):
@ -1298,7 +1305,8 @@ class PhaseDefaults(QtGui.QDialog):
checkbox.setChecked(bool(phase in self.current_phases))
row += 1
def create_phase_box(self, phase_name):
@staticmethod
def create_phase_box(phase_name):
checkbox = QtGui.QCheckBox(phase_name)
return checkbox
@ -1699,7 +1707,8 @@ class PickDlg(QDialog):
phases)
self.arrivals = arrivals
def prepare_phases(self):
@staticmethod
def prepare_phases():
settings = QtCore.QSettings()
p_phases = settings.value('p_phases')
s_phases = settings.value('s_phases')
@ -1875,7 +1884,8 @@ class PickDlg(QDialog):
self.currentPhase = str(self.s_button.text())
self.activatePicking()
def getPhaseID(self, phase):
@staticmethod
def getPhaseID(phase):
return identifyPhaseID(phase)
def set_button_border_color(self, button, color=None):
@ -2087,7 +2097,8 @@ class PickDlg(QDialog):
st += data.select(channel=action.text())
return st
def calcNoiseScaleFactor(self, noiselevel, zoomfactor=5., norm=1):
@staticmethod
def calcNoiseScaleFactor(noiselevel, zoomfactor=5., norm=1):
# calculate factor to upscale a trace normed to 'norm' in a way that all values
# zoomfactor*noiselevel are found within -0.5*norm and 0.5*norm
scaleFactor = (norm/2.) / (zoomfactor * noiselevel)
@ -2626,15 +2637,18 @@ class PickDlg(QDialog):
settings = QSettings()
settings.setValue('autoFilter', self.autoFilterAction.isChecked())
def updateChannelSettingsP(self, action):
@staticmethod
def updateChannelSettingsP(action):
settings = QSettings()
settings.setValue('p_channel_{}'.format(action.text()), action.isChecked())
def updateChannelSettingsS(self, action):
@staticmethod
def updateChannelSettingsS(action):
settings = QSettings()
settings.setValue('s_channel_{}'.format(action.text()), action.isChecked())
def getChannelSettingsP(self, channel):
@staticmethod
def getChannelSettingsP(channel):
settings = QSettings()
rval = real_Bool(settings.value('p_channel_{}'.format(channel)))
compclass = settings.value('compclass')
@ -2648,7 +2662,8 @@ class PickDlg(QDialog):
rval = False
return rval
def getChannelSettingsS(self, channel):
@staticmethod
def getChannelSettingsS(channel):
settings = QSettings()
rval = real_Bool(settings.value('s_channel_{}'.format(channel)))
compclass = settings.value('compclass')
@ -3220,7 +3235,8 @@ class TuneAutopicker(QWidget):
def get_current_station_id(self):
return str(self.stationBox.currentText())
def gen_tab_widget(self, name, canvas):
@staticmethod
def gen_tab_widget(name, canvas):
widget = QtGui.QWidget()
v_layout = QtGui.QVBoxLayout()
v_layout.addWidget(canvas)
@ -3650,7 +3666,8 @@ class PylotParaBox(QtGui.QWidget):
grid.addWidget(box, index1, 2)
return grid
def create_box(self, typ, tooltip):
@staticmethod
def create_box(typ, tooltip):
if typ == str:
box = QtGui.QLineEdit()
elif typ == float:
@ -3665,7 +3682,8 @@ class PylotParaBox(QtGui.QWidget):
raise TypeError('Unrecognized type {}'.format(typ))
return box
def create_multi_box(self, boxes, headline=None):
@staticmethod
def create_multi_box(boxes, headline=None):
box = QtGui.QWidget()
gl = QtGui.QGridLayout()
column = 0
@ -4366,7 +4384,8 @@ class PhasesTab(PropTab):
self.PphasesEdit.setText(p_phases)
self.SphasesEdit.setText(s_phases)
def sortPhases(self, phases):
@staticmethod
def sortPhases(phases):
sorted_phases = {'P': [],
'S': []}
for phase in phases:
@ -4607,7 +4626,8 @@ class LocalisationTab(PropTab):
self.rootlabel.setText("{0} root directory".format(curtool))
self.binlabel.setText("{0} bin directory".format(curtool))
def selectDirectory(self, edit):
@staticmethod
def selectDirectory(edit):
selected_directory = QFileDialog.getExistingDirectory()
# check if string is empty
if selected_directory: