coppied files from Ludgers Laptop
This commit is contained in:
0
pylot/core/util/__init__.py
Executable file → Normal file
0
pylot/core/util/__init__.py
Executable file → Normal file
@@ -180,8 +180,10 @@ def read_metadata(path_to_inventory):
|
||||
invtype = key_for_set_value(inv)
|
||||
|
||||
if invtype is None:
|
||||
raise IOError("Neither dataless-SEED file, inventory-xml file nor "
|
||||
"RESP-file found!")
|
||||
print("Neither dataless-SEED file, inventory-xml file nor "
|
||||
"RESP-file found!")
|
||||
print("!!WRONG CALCULATION OF SOURCE PARAMETERS!!")
|
||||
robj = None,
|
||||
elif invtype == 'dless': # prevent multiple read of large dlsv
|
||||
print("Reading metadata information from dataless-SEED file ...")
|
||||
if len(inv[invtype]) == 1:
|
||||
@@ -250,13 +252,23 @@ def restitute_data(data, invtype, inobj, unit='VEL', force=False):
|
||||
else:
|
||||
finv = invlist[0]
|
||||
inventory = read_inventory(finv, format='STATIONXML')
|
||||
elif invtype == None:
|
||||
print("No restitution possible, as there are no station-meta data available!")
|
||||
break
|
||||
else:
|
||||
data.remove(tr)
|
||||
continue
|
||||
# apply restitution to data
|
||||
print("Correcting instrument at station %s, channel %s" \
|
||||
% (tr.stats.station, tr.stats.channel))
|
||||
try:
|
||||
if invtype in ['resp', 'dless']:
|
||||
tr.simulate(**kwargs)
|
||||
try:
|
||||
tr.simulate(**kwargs)
|
||||
except ValueError as e:
|
||||
vmsg = '{0}'.format(e)
|
||||
print(vmsg)
|
||||
|
||||
else:
|
||||
tr.attach_response(inventory)
|
||||
tr.remove_response(output=unit,
|
||||
|
||||
@@ -8,7 +8,9 @@ Created on Wed Feb 26 12:31:25 2014
|
||||
|
||||
import os
|
||||
from pylot.core.loc import nll
|
||||
from pylot.core.loc import hsat
|
||||
from pylot.core.loc import hyposat
|
||||
from pylot.core.loc import hypo71
|
||||
from pylot.core.loc import hypodd
|
||||
from pylot.core.loc import velest
|
||||
|
||||
|
||||
@@ -43,10 +45,6 @@ FILTERDEFAULTS = readFilterInformation(os.path.join(os.path.expanduser('~'),
|
||||
'.pylot',
|
||||
'filter.in'))
|
||||
|
||||
AUTOMATIC_DEFAULTS = os.path.join(os.path.expanduser('~'),
|
||||
'.pylot',
|
||||
'autoPyLoT.in')
|
||||
|
||||
TIMEERROR_DEFAULTS = os.path.join(os.path.expanduser('~'),
|
||||
'.pylot',
|
||||
'PILOT_TimeErrors.in')
|
||||
@@ -55,7 +53,7 @@ OUTPUTFORMATS = {'.xml': 'QUAKEML',
|
||||
'.cnv': 'CNV',
|
||||
'.obs': 'NLLOC_OBS'}
|
||||
|
||||
LOCTOOLS = dict(nll=nll, hsat=hsat, velest=velest)
|
||||
LOCTOOLS = dict(nll=nll, hyposat=hyposat, velest=velest, hypo71=hypo71, hypodd=hypodd)
|
||||
|
||||
COMPPOSITION_MAP = dict(Z=2, N=1, E=0)
|
||||
COMPPOSITION_MAP['1'] = 1
|
||||
|
||||
@@ -51,8 +51,11 @@ def exp_parameter(te, tm, tl, eta):
|
||||
|
||||
sig1 = np.log(eta) / (te - tm)
|
||||
sig2 = np.log(eta) / (tm - tl)
|
||||
if np.isinf(sig1) == True:
|
||||
sig1 = np.log(eta) / (tm - tl)
|
||||
if np.isinf(sig2) == True:
|
||||
sig2 = np.log(eta) / (te - tm)
|
||||
a = 1 / (1 / sig1 + 1 / sig2)
|
||||
|
||||
return tm, sig1, sig2, a
|
||||
|
||||
|
||||
@@ -237,7 +240,7 @@ class ProbabilityDensityFunction(object):
|
||||
|
||||
@classmethod
|
||||
def from_pick(self, lbound, barycentre, rbound, incr=0.001, decfact=0.01,
|
||||
type='gauss'):
|
||||
type='exp'):
|
||||
'''
|
||||
Initialize a new ProbabilityDensityFunction object.
|
||||
Takes incr, lbound, barycentre and rbound to derive x0 and the number
|
||||
@@ -304,10 +307,14 @@ class ProbabilityDensityFunction(object):
|
||||
:return float: rval
|
||||
'''
|
||||
|
||||
rval = 0
|
||||
for x in self.axis:
|
||||
rval += x * self.data(x)
|
||||
return rval * self.incr
|
||||
#rval = 0
|
||||
#for x in self.axis:
|
||||
# rval += x * self.data(x)
|
||||
rval = self.mu
|
||||
# Not sure about this! That might not be the barycentre.
|
||||
# However, for std calculation (next function)
|
||||
# self.mu is also used!! (LK, 02/2017)
|
||||
return rval
|
||||
|
||||
def standard_deviation(self):
|
||||
mu = self.mu
|
||||
|
||||
@@ -7,17 +7,18 @@ class AutoPickThread(QThread):
|
||||
message = Signal(str)
|
||||
finished = Signal()
|
||||
|
||||
def __init__(self, parent, func, data, param):
|
||||
def __init__(self, parent, func, infile, fnames, savepath):
|
||||
super(AutoPickThread, self).__init__()
|
||||
self.setParent(parent)
|
||||
self.func = func
|
||||
self.data = data
|
||||
self.param = param
|
||||
self.infile = infile
|
||||
self.fnames = fnames
|
||||
self.savepath = savepath
|
||||
|
||||
def run(self):
|
||||
sys.stdout = self
|
||||
|
||||
picks = self.func(self.data, self.param)
|
||||
picks = self.func(self.infile, self.fnames, self.savepath)
|
||||
|
||||
print("Autopicking finished!\n")
|
||||
|
||||
|
||||
@@ -477,7 +477,7 @@ def runProgram(cmd, parameter=None):
|
||||
|
||||
subprocess.check_output('{} | tee /dev/stderr'.format(cmd), shell=True)
|
||||
|
||||
def which(program):
|
||||
def which(program, infile=None):
|
||||
"""
|
||||
takes a program name and returns the full path to the executable or None
|
||||
modified after: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
|
||||
@@ -490,7 +490,12 @@ def which(program):
|
||||
for key in settings.allKeys():
|
||||
if 'binPath' in key:
|
||||
os.environ['PATH'] += ':{0}'.format(settings.value(key))
|
||||
bpath = os.path.join(os.path.expanduser('~'), '.pylot', 'autoPyLoT.in')
|
||||
if infile is None:
|
||||
# use default parameter-file name
|
||||
bpath = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
|
||||
else:
|
||||
bpath = os.path.join(os.path.expanduser('~'), '.pylot', infile)
|
||||
|
||||
if os.path.exists(bpath):
|
||||
nllocpath = ":" + AutoPickParameter(bpath).get('nllocbin')
|
||||
os.environ['PATH'] += nllocpath
|
||||
|
||||
0
pylot/core/util/version.py
Executable file → Normal file
0
pylot/core/util/version.py
Executable file → Normal file
@@ -5,12 +5,15 @@ Created on Wed Mar 19 11:27:35 2014
|
||||
@author: sebastianw
|
||||
"""
|
||||
|
||||
import os
|
||||
import getpass
|
||||
import warnings
|
||||
import copy
|
||||
import datetime
|
||||
import numpy as np
|
||||
|
||||
from matplotlib.figure import Figure
|
||||
from pylot.core.util.utils import find_horizontals
|
||||
|
||||
try:
|
||||
from matplotlib.backends.backend_qt4agg import FigureCanvas
|
||||
@@ -26,7 +29,7 @@ from PySide.QtGui import QAction, QApplication, QCheckBox, QComboBox, \
|
||||
from PySide.QtCore import QSettings, Qt, QUrl, Signal, Slot
|
||||
from PySide.QtWebKit import QWebView
|
||||
from obspy import Stream, UTCDateTime
|
||||
from pylot.core.io.inputs import FilterOptions
|
||||
from pylot.core.io.inputs import FilterOptions, AutoPickParameter
|
||||
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
||||
getResolutionWindow
|
||||
from pylot.core.pick.compare import Comparison
|
||||
@@ -49,7 +52,12 @@ def getDataType(parent):
|
||||
|
||||
def plot_pdf(_axes, x, y, annotation, bbox_props, xlabel=None, ylabel=None,
|
||||
title=None):
|
||||
_axes.plot(x, y)
|
||||
# try method or data
|
||||
try:
|
||||
_axes.plot(x, y()) # y provided as method
|
||||
except:
|
||||
_axes.plot(x, y) # y provided as data
|
||||
|
||||
if title:
|
||||
_axes.set_title(title)
|
||||
if xlabel:
|
||||
@@ -235,23 +243,23 @@ class ComparisonDialog(QDialog):
|
||||
x, y, std, exp = pdf.axis, pdf.data, pdf.standard_deviation(), \
|
||||
pdf.expectation()
|
||||
|
||||
annotation = "{phase} difference on {station}\n" \
|
||||
"expectation: {exp}\n" \
|
||||
"std: {std}".format(station=station, phase=phase,
|
||||
std=std, exp=exp)
|
||||
annotation = "%s difference on %s\n" \
|
||||
"expectation: %7.4f s\n" \
|
||||
"std: %7.4f s" % (phase, station,
|
||||
exp, std)
|
||||
bbox_props = dict(boxstyle='round', facecolor='lightgrey', alpha=.7)
|
||||
|
||||
plot_pdf(_axes, x, y, annotation, bbox_props, 'time difference [s]',
|
||||
'propability density [-]', phase)
|
||||
'propability density [-]', phase)
|
||||
|
||||
pdf_a = copy.deepcopy(self.data.get('auto')[station][phase])
|
||||
pdf_m = copy.deepcopy(self.data.get('manu')[station][phase])
|
||||
|
||||
xauto, yauto, stdauto, expauto, alim = pdf_a.axis, pdf_a.data, \
|
||||
xauto, yauto, stdauto, expauto, alim = pdf_a.axis, pdf_a.data(), \
|
||||
pdf_a.standard_deviation(), \
|
||||
pdf_a.expectation(), \
|
||||
pdf_a.limits()
|
||||
xmanu, ymanu, stdmanu, expmanu, mlim = pdf_m.axis, pdf_m.data, \
|
||||
xmanu, ymanu, stdmanu, expmanu, mlim = pdf_m.axis, pdf_m.data(), \
|
||||
pdf_m.standard_deviation(), \
|
||||
pdf_m.expectation(), \
|
||||
pdf_m.limits()
|
||||
@@ -259,21 +267,19 @@ class ComparisonDialog(QDialog):
|
||||
lims = clims(alim, mlim)
|
||||
# relative x axis
|
||||
x0 = lims[0]
|
||||
xmanu -= x0
|
||||
xmanu -= x0
|
||||
xauto -= x0
|
||||
lims = [lim - x0 for lim in lims]
|
||||
x0 = UTCDateTime(x0)
|
||||
|
||||
# set annotation text
|
||||
mannotation = "probability density for manual pick\n" \
|
||||
"expectation: {exp}\n" \
|
||||
"std: {std}".format(std=stdmanu,
|
||||
exp=expmanu-x0.timestamp)
|
||||
mannotation = "probability density of manual pick\n" \
|
||||
"expectation: %7.4f s\n" \
|
||||
"std: %7.4f s" % (expmanu-x0.timestamp, stdmanu)
|
||||
|
||||
aannotation = "probability density for automatic pick\n" \
|
||||
"expectation: {exp}\n" \
|
||||
"std: {std}".format(std=stdauto,
|
||||
exp=expauto-x0.timestamp)
|
||||
aannotation = "probability density of automatic pick\n" \
|
||||
"expectation: %7.4f s\n" \
|
||||
"std: %7.4f s" % (expauto-x0.timestamp, stdauto)
|
||||
|
||||
_ax1 = plot_pdf(_ax1, xmanu, ymanu, mannotation,
|
||||
bbox_props=bbox_props, xlabel='seconds since '
|
||||
@@ -504,15 +510,17 @@ class WaveformWidget(FigureCanvas):
|
||||
|
||||
class PickDlg(QDialog):
|
||||
def __init__(self, parent=None, data=None, station=None, picks=None,
|
||||
rotate=False):
|
||||
rotate=False, infile=None):
|
||||
super(PickDlg, self).__init__(parent)
|
||||
|
||||
# initialize attributes
|
||||
self.infile = infile
|
||||
self.station = station
|
||||
self.rotate = rotate
|
||||
self.components = 'ZNE'
|
||||
settings = QSettings()
|
||||
self._user = settings.value('user/Login', 'anonymous')
|
||||
pylot_user = getpass.getuser()
|
||||
self._user = settings.value('user/Login', pylot_user)
|
||||
if picks:
|
||||
self.picks = picks
|
||||
else:
|
||||
@@ -704,6 +712,9 @@ class PickDlg(QDialog):
|
||||
self.cidrelease = self.connectReleaseEvent(self.panRelease)
|
||||
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
||||
|
||||
def getinfile(self):
|
||||
return self.infile
|
||||
|
||||
def getStartTime(self):
|
||||
return self.stime
|
||||
|
||||
@@ -806,6 +817,7 @@ class PickDlg(QDialog):
|
||||
self.disconnectMotionEvent()
|
||||
self.cidpress = self.connectPressEvent(self.setPick)
|
||||
|
||||
print(self.selectPhase.currentText())
|
||||
if self.selectPhase.currentText().upper().startswith('P'):
|
||||
self.setIniPickP(gui_event, wfdata, trace_number)
|
||||
elif self.selectPhase.currentText().upper().startswith('S'):
|
||||
@@ -819,14 +831,14 @@ class PickDlg(QDialog):
|
||||
|
||||
def setIniPickP(self, gui_event, wfdata, trace_number):
|
||||
|
||||
parameter = AutoPickParameter(self.getinfile())
|
||||
ini_pick = gui_event.xdata
|
||||
|
||||
settings = QSettings()
|
||||
|
||||
nfac = settings.value('picking/nfac_P', 1.3)
|
||||
noise_win = settings.value('picking/noise_win_P', 5.)
|
||||
gap_win = settings.value('picking/gap_win_P', .2)
|
||||
signal_win = settings.value('picking/signal_win_P', 3.)
|
||||
nfac = parameter.get('nfacP')
|
||||
twins = parameter.get('tsnrz')
|
||||
noise_win = twins[0]
|
||||
gap_win = twins[1]
|
||||
signal_win = twins[2]
|
||||
itrace = int(trace_number)
|
||||
|
||||
while itrace > len(wfdata) - 1:
|
||||
@@ -868,14 +880,14 @@ class PickDlg(QDialog):
|
||||
|
||||
def setIniPickS(self, gui_event, wfdata):
|
||||
|
||||
parameter = AutoPickParameter(self.getinfile())
|
||||
ini_pick = gui_event.xdata
|
||||
|
||||
settings = QSettings()
|
||||
|
||||
nfac = settings.value('picking/nfac_S', 1.5)
|
||||
noise_win = settings.value('picking/noise_win_S', 5.)
|
||||
gap_win = settings.value('picking/gap_win_S', .2)
|
||||
signal_win = settings.value('picking/signal_win_S', 3.)
|
||||
nfac = parameter.get('nfacS')
|
||||
twins = parameter.get('tsnrh')
|
||||
noise_win = twins[0]
|
||||
gap_win = twins[1]
|
||||
signal_win = twins[2]
|
||||
|
||||
# copy data for plotting
|
||||
data = self.getWFData().copy()
|
||||
@@ -922,6 +934,8 @@ class PickDlg(QDialog):
|
||||
|
||||
def setPick(self, gui_event):
|
||||
|
||||
parameter = AutoPickParameter(self.getinfile())
|
||||
|
||||
# get axes limits
|
||||
self.updateCurrentLimits()
|
||||
|
||||
@@ -941,7 +955,14 @@ class PickDlg(QDialog):
|
||||
wfdata.filter(**filteroptions)
|
||||
|
||||
# get earliest and latest possible pick and symmetric pick error
|
||||
[epp, lpp, spe] = earllatepicker(wfdata, 1.5, (5., .5, 2.), pick)
|
||||
if wfdata[0].stats.channel[2] == 'Z' or wfdata[0].stats.channel[2] == '3':
|
||||
nfac = parameter.get('nfacP')
|
||||
TSNR = parameter.get('tsnrz')
|
||||
else:
|
||||
nfac = parameter.get('nfacS')
|
||||
TSNR = parameter.get('tsnrh')
|
||||
|
||||
[epp, lpp, spe] = earllatepicker(wfdata, nfac, (TSNR[0], TSNR[1], TSNR[2]), pick)
|
||||
|
||||
# return absolute time values for phases
|
||||
stime = self.getStartTime()
|
||||
@@ -951,7 +972,8 @@ class PickDlg(QDialog):
|
||||
|
||||
# save pick times for actual phase
|
||||
phasepicks = dict(epp=epp, lpp=lpp, mpp=mpp, spe=spe,
|
||||
picker=self.getUser())
|
||||
picker='manual', channel=channel,
|
||||
network=wfdata[0].stats.network)
|
||||
|
||||
try:
|
||||
oldphasepick = self.picks[phase]
|
||||
@@ -1171,13 +1193,15 @@ class PickDlg(QDialog):
|
||||
|
||||
|
||||
class PropertiesDlg(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, parent=None, infile=None):
|
||||
super(PropertiesDlg, self).__init__(parent)
|
||||
|
||||
self.infile = infile
|
||||
|
||||
|
||||
appName = QApplication.applicationName()
|
||||
|
||||
self.setWindowTitle("{0} Properties".format(appName))
|
||||
|
||||
self.tabWidget = QTabWidget()
|
||||
self.tabWidget.addTab(InputsTab(self), "Inputs")
|
||||
self.tabWidget.addTab(OutputsTab(self), "Outputs")
|
||||
@@ -1186,7 +1210,8 @@ class PropertiesDlg(QDialog):
|
||||
self.tabWidget.addTab(LocalisationTab(self), "Loc Tools")
|
||||
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok |
|
||||
QDialogButtonBox.Apply |
|
||||
QDialogButtonBox.Close)
|
||||
QDialogButtonBox.Close |
|
||||
QDialogButtonBox.RestoreDefaults)
|
||||
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(self.tabWidget)
|
||||
@@ -1195,8 +1220,11 @@ class PropertiesDlg(QDialog):
|
||||
|
||||
self.buttonBox.accepted.connect(self.accept)
|
||||
self.buttonBox.rejected.connect(self.reject)
|
||||
self.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(
|
||||
self.apply)
|
||||
self.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.apply)
|
||||
self.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.restore)
|
||||
|
||||
def getinfile(self):
|
||||
return self.infile
|
||||
|
||||
def accept(self, *args, **kwargs):
|
||||
self.apply()
|
||||
@@ -1209,6 +1237,14 @@ class PropertiesDlg(QDialog):
|
||||
if values is not None:
|
||||
self.setValues(values)
|
||||
|
||||
def restore(self):
|
||||
for widint in range(self.tabWidget.count()):
|
||||
curwid = self.tabWidget.widget(widint)
|
||||
values = curwid.resetValues(self.getinfile())
|
||||
if values is not None:
|
||||
self.setValues(values)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def setValues(tabValues):
|
||||
settings = QSettings()
|
||||
@@ -1224,16 +1260,19 @@ class PropTab(QWidget):
|
||||
def getValues(self):
|
||||
return None
|
||||
|
||||
def resetValues(self, infile=None):
|
||||
return None
|
||||
|
||||
class InputsTab(PropTab):
|
||||
def __init__(self, parent):
|
||||
def __init__(self, parent, infile=None):
|
||||
super(InputsTab, self).__init__(parent)
|
||||
|
||||
settings = QSettings()
|
||||
pylot_user = getpass.getuser()
|
||||
fulluser = settings.value("user/FullName")
|
||||
login = settings.value("user/Login")
|
||||
|
||||
fullNameLabel = QLabel("Full name for user '{0}': ".format(login))
|
||||
fullNameLabel = QLabel("Full name for user '{0}': ".format(pylot_user))
|
||||
|
||||
# get the full name of the actual user
|
||||
self.fullNameEdit = QLineEdit()
|
||||
@@ -1276,9 +1315,24 @@ class InputsTab(PropTab):
|
||||
"data/Structure": self.structureSelect.currentText()}
|
||||
return values
|
||||
|
||||
def resetValues(self, infile):
|
||||
para = AutoPickParameter(infile)
|
||||
datstruct = para.get('datastructure')
|
||||
if datstruct == 'SeisComp':
|
||||
index = 0
|
||||
else:
|
||||
index = 2
|
||||
datapath = para.get('datapath')
|
||||
rootpath = para.get('rootpath')
|
||||
database = para.get('database')
|
||||
path = os.path.join(os.path.expanduser('~'), rootpath, datapath, database)
|
||||
values = {"data/dataRoot": self.dataDirEdit.setText("%s" % path),
|
||||
"user/FullName": self.fullNameEdit.text(),
|
||||
"data/Structure": self.structureSelect.setCurrentIndex(index)}
|
||||
return values
|
||||
|
||||
class OutputsTab(PropTab):
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, parent=None, infile=None):
|
||||
super(OutputsTab, self).__init__(parent)
|
||||
|
||||
settings = QSettings()
|
||||
@@ -1302,6 +1356,9 @@ class OutputsTab(PropTab):
|
||||
values = {"output/Format": self.eventOutputComboBox.currentText()}
|
||||
return values
|
||||
|
||||
def resetValues(self, infile):
|
||||
values = {"output/Format": self.eventOutputComboBox.setCurrentIndex(1)}
|
||||
return values
|
||||
|
||||
class PhasesTab(PropTab):
|
||||
def __init__(self, parent=None):
|
||||
@@ -1318,7 +1375,7 @@ class GraphicsTab(PropTab):
|
||||
|
||||
|
||||
class LocalisationTab(PropTab):
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, parent=None, infile=None):
|
||||
super(LocalisationTab, self).__init__(parent)
|
||||
|
||||
settings = QSettings()
|
||||
@@ -1388,6 +1445,13 @@ class LocalisationTab(PropTab):
|
||||
"loc/tool": loctool}
|
||||
return values
|
||||
|
||||
def resetValues(self, infile):
|
||||
para = AutoPickParameter(infile)
|
||||
nllocroot = para.get('nllocroot')
|
||||
nllocbin = para.get('nllocbin')
|
||||
loctool = self.locToolComboBox.setCurrentIndex(3)
|
||||
values = {"nll/rootPath": self.rootedit.setText("%s" % nllocroot),
|
||||
"nll/binPath": self.binedit.setText("%s" % nllocbin)}
|
||||
|
||||
class NewEventDlg(QDialog):
|
||||
def __init__(self, parent=None, titleString="Create a new event"):
|
||||
|
||||
Reference in New Issue
Block a user