Merge branch 'develop' of ariadne.geophysik.ruhr-uni-bochum.de:/data/git/pylot into develop

This commit is contained in:
Marcel Paffrath
2015-11-03 10:31:18 +01:00
7 changed files with 217 additions and 61 deletions

View File

@@ -931,6 +931,81 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
return returnflag
def writephases(arrivals, fformat, filename):
'''
Function of methods to write phases to the following standard file
formats used for locating earthquakes:
HYPO71, NLLoc, VELEST, HYPOSAT, HYPOINVERSE and hypoDD
:param: arrivals
:type: dictionary containing all phase information including
station ID, phase, first motion, weight (uncertainty),
....
:param: fformat
:type: string, chosen file format (location routine),
choose between NLLoc, HYPO71, HYPOSAT, VELEST,
HYPOINVERSE, and hypoDD
:param: filename, full path and name of phase file
:type: string
'''
if fformat == 'NLLoc':
print ("Writing phases to %s for NLLoc" % filename)
fid = open("%s" % filename, 'w')
# write header
fid.write('# EQEVENT: Label: EQ001 Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n')
for key in arrivals:
if arrivals[key]['P']['weight'] < 4:
fm = arrivals[key]['P']['fm']
onset = arrivals[key]['P']['mpp']
year = onset.year
month = onset.month
day = onset.day
hh = onset.hour
mm = onset.minute
ss = onset.second
ms = onset.microsecond
ss_ms = ss + ms / 1000000.0
fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 1 \n' % (key,
fm,
year,
month,
day,
hh,
mm,
ss_ms))
if arrivals[key]['S']['weight'] < 4:
fm = '?'
onset = arrivals[key]['S']['mpp']
year = onset.year
month = onset.month
day = onset.day
hh = onset.hour
mm = onset.minute
ss = onset.second
ms = onset.microsecond
ss_ms = ss + ms / 1000000.0
fid.write('%s ? ? ? S %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 1 \n' % (key,
fm,
year,
month,
day,
hh,
mm,
ss_ms))
fid.close()
if __name__ == '__main__':
import doctest
doctest.testmod()

View File

@@ -206,8 +206,11 @@ class FilterOptions(object):
order=self.getOrder())
return hrs
def __nonzero__(self):
return bool(self.getFilterType())
def parseFilterOptions(self):
if self.getFilterType():
if self:
robject = {'type': self.getFilterType(), 'corners': self.getOrder()}
if len(self.getFreq()) > 1:
robject['freqmin'] = self.getFreq()[0]

View File

@@ -32,7 +32,8 @@ def runProgram(cmd, parameter=None):
output = subprocess.check_output('{} | tee /dev/stderr'.format(cmd),
shell = True)
def isSorted(iterable):
return sorted(iterable) == iterable
def fnConstructor(s):
if type(s) is str:

View File

@@ -27,7 +27,7 @@ from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin,\
getResolutionWindow
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS
from pylot.core.util.utils import prepTimeAxis, getGlobalTimes, scaleWFData, \
demeanTrace
demeanTrace, isSorted
def createAction(parent, text, slot=None, shortcut=None, icon=None,
@@ -985,7 +985,7 @@ class FilterOptionsDialog(QDialog):
"""
super(FilterOptionsDialog, self).__init__()
if parent is not None:
if parent is not None and parent.getFilterOptions():
self.filterOptions = parent.getFilterOptions()
elif filterOptions is not None:
self.filterOptions = FilterOptions(filterOptions)
@@ -1021,8 +1021,8 @@ class FilterOptionsDialog(QDialog):
try:
self.freqmaxSpinBox.setValue(self.getFilterOptions().getFreq())
self.freqminSpinBox.setValue(self.getFilterOptions().getFreq())
except TypeError, e:
print e
except TypeError as e:
print(e)
self.freqmaxSpinBox.setValue(1.)
self.freqminSpinBox.setValue(.1)
@@ -1037,6 +1037,7 @@ class FilterOptionsDialog(QDialog):
self.selectTypeLabel.setText("Select filter type:")
self.selectTypeCombo = QComboBox()
self.selectTypeCombo.addItems(typeOptions)
self.selectTypeCombo.setCurrentIndex(typeOptions.index(self.getFilterOptions().getFilterType()))
self.selectTypeLayout = QVBoxLayout()
self.selectTypeLayout.addWidget(self.orderLabel)
self.selectTypeLayout.addWidget(self.orderSpinBox)
@@ -1071,30 +1072,28 @@ class FilterOptionsDialog(QDialog):
self.buttonBox.rejected.connect(self.reject)
def updateUi(self):
_enable = False
if self.selectTypeCombo.currentText() not in ['bandpass', 'bandstop']:
self.freqminLabel.setText("cutoff:")
self.freqmaxSpinBox.setValue(self.freqminSpinBox.value())
else:
_enable = True
self.freqminLabel.setText("minimum:")
type = self.selectTypeCombo.currentText()
_enable = type in ['bandpass', 'bandstop']
freq = [self.freqminSpinBox.value(), self.freqmaxSpinBox.value()]
self.freqmaxLabel.setEnabled(_enable)
self.freqmaxSpinBox.setEnabled(_enable)
self.getFilterOptions().setFilterType(
self.selectTypeCombo.currentText())
freq = [self.freqminSpinBox.value()]
if _enable:
if self.freqminSpinBox.value() > self.freqmaxSpinBox.value():
if not _enable:
self.freqminLabel.setText("cutoff:")
self.freqmaxSpinBox.setValue(freq[0])
freq.remove(freq[1])
else:
self.freqminLabel.setText("minimum:")
if not isSorted(freq):
QMessageBox.warning(self, "Value error",
"Maximum frequency must be at least the "
"same value as minimum frequency (notch)!")
self.freqmaxSpinBox.setValue(self.freqminSpinBox.value())
self.freqmaxSpinBox.setValue(freq[0])
self.freqmaxSpinBox.selectAll()
self.freqmaxSpinBox.setFocus()
return
freq.append(self.freqmaxSpinBox.value())
self.getFilterOptions().setFilterType(type)
self.getFilterOptions().setFreq(freq)
self.getFilterOptions().setOrder(self.orderSpinBox.value())