[bugfix] fixes and modifications for (inhomogeneous) global datasets, WIP

This commit is contained in:
Marcel Paffrath 2017-05-30 16:09:48 +02:00
parent ceed165307
commit f493359c26
4 changed files with 66 additions and 30 deletions

View File

@ -81,11 +81,13 @@ class MainWindow(QMainWindow):
__version__ = _getVersionString() __version__ = _getVersionString()
closing = Signal() closing = Signal()
def __init__(self, parent=None): def __init__(self, parent=None, infile=None):
super(MainWindow, self).__init__(parent) super(MainWindow, self).__init__(parent)
# check for default pylot.in-file # check for default pylot.in-file
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in') if not infile:
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
print('Using default input file {}'.format(infile))
if os.path.isfile(infile)== False: if os.path.isfile(infile)== False:
infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file') infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')
if not os.path.exists(infile[0]): if not os.path.exists(infile[0]):
@ -742,6 +744,7 @@ class MainWindow(QMainWindow):
self.eventBox.setCurrentIndex(nitems) self.eventBox.setCurrentIndex(nitems)
self.refreshEvents() self.refreshEvents()
tabindex = self.tabs.currentIndex() tabindex = self.tabs.currentIndex()
self.setDirty(True)
def fill_eventbox(self, eventBox=None, select_events='all'): def fill_eventbox(self, eventBox=None, select_events='all'):
''' '''
@ -1215,17 +1218,15 @@ class MainWindow(QMainWindow):
nth_sample = settings.value('nth_sample') nth_sample = settings.value('nth_sample')
if not nth_sample: if not nth_sample:
nth_sample = 1 nth_sample = 1
compclass = SetChannelComponents()
zne_text = {'Z': 'vertical', 'N': 'north-south', 'E': 'east-west'} zne_text = {'Z': 'vertical', 'N': 'north-south', 'E': 'east-west'}
comp = self.getComponent() comp = self.getComponent()
title = 'section: {0} components'.format(zne_text[comp]) title = 'section: {0} components'.format(zne_text[comp])
alter_comp = compclass.getCompPosition(comp) wfst = self.get_data().getWFData()
alter_comp = str(alter_comp[0]) # wfst = self.get_data().getWFData().select(component=comp)
wfst = self.get_data().getWFData().select(component=comp) # wfst += self.get_data().getWFData().select(component=alter_comp)
wfst += self.get_data().getWFData().select(component=alter_comp)
plotWidget = self.getPlotWidget() plotWidget = self.getPlotWidget()
self.adjustPlotHeight() self.adjustPlotHeight()
plotWidget.plotWFData(wfdata=wfst, title=title, mapping=False, nth_sample=int(nth_sample)) plotWidget.plotWFData(wfdata=wfst, title=title, mapping=False, component=comp, nth_sample=int(nth_sample))
plotDict = plotWidget.getPlotDict() plotDict = plotWidget.getPlotDict()
pos = plotDict.keys() pos = plotDict.keys()
labels = [plotDict[n][2]+'.'+plotDict[n][0] for n in pos] labels = [plotDict[n][2]+'.'+plotDict[n][0] for n in pos]
@ -2240,6 +2241,14 @@ def create_window():
def main(args=None): def main(args=None):
project_filename = None
pylot_infile = None
if args:
if args.project_filename:
project_filename = args.project_filename
if args.input_filename:
pylot_infile = args.input_filename
# create the Qt application # create the Qt application
pylot_app, app_created = create_window() pylot_app, app_created = create_window()
#pylot_app = QApplication(sys.argv) #pylot_app = QApplication(sys.argv)
@ -2251,7 +2260,7 @@ def main(args=None):
app_icon.addPixmap(QPixmap(':/icons/pylot.png')) app_icon.addPixmap(QPixmap(':/icons/pylot.png'))
# create the main window # create the main window
pylot_form = MainWindow() pylot_form = MainWindow(infile=pylot_infile)
icon = QIcon() icon = QIcon()
pylot_form.setWindowIcon(icon) pylot_form.setWindowIcon(icon)
pylot_form.setIconSize(QSize(60, 60)) pylot_form.setIconSize(QSize(60, 60))
@ -2274,9 +2283,8 @@ def main(args=None):
splash.finish(pylot_form) splash.finish(pylot_form)
if args: if project_filename:
if args.project_filename: pylot_form.loadProject(args.project_filename)
pylot_form.loadProject(args.project_filename)
if app_created: if app_created:
pylot_app.exec_() pylot_app.exec_()
@ -2288,5 +2296,7 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Welcome to PyLoT.') parser = argparse.ArgumentParser(description='Welcome to PyLoT.')
parser.add_argument('-p', dest='project_filename', help='load project file', parser.add_argument('-p', dest='project_filename', help='load project file',
default=None) default=None)
parser.add_argument('-in', dest='input_filename', help='set pylot input file',
default=None)
args = parser.parse_args() args = parser.parse_args()
sys.exit(main(args)) sys.exit(main(args))

View File

@ -1 +1 @@
a745-dirty ceed1-dirty

View File

@ -343,6 +343,10 @@ def getSNR(X, TSNR, t1, tracenum=0):
assert isinstance(X, Stream), "%s is not a stream object" % str(X) assert isinstance(X, Stream), "%s is not a stream object" % str(X)
SNR = None
SNRdb = None
noiselevel = None
x = X[tracenum].data x = X[tracenum].data
npts = X[tracenum].stats.npts npts = X[tracenum].stats.npts
sr = X[tracenum].stats.sampling_rate sr = X[tracenum].stats.sampling_rate
@ -356,10 +360,7 @@ def getSNR(X, TSNR, t1, tracenum=0):
isignal = getsignalwin(t, t1, TSNR[2]) isignal = getsignalwin(t, t1, TSNR[2])
if np.size(inoise) < 1: if np.size(inoise) < 1:
print ("getSNR: Empty array inoise, check noise window!") print ("getSNR: Empty array inoise, check noise window!")
return return SNR, SNRdB, noiselevel
elif np.size(isignal) < 1:
print ("getSNR: Empty array isignal, check signal window!")
return
# demean over entire waveform # demean over entire waveform
x = x - np.mean(x[inoise]) x = x - np.mean(x[inoise])
@ -368,6 +369,10 @@ def getSNR(X, TSNR, t1, tracenum=0):
noiselevel = np.sqrt(np.mean(np.square(x[inoise]))) noiselevel = np.sqrt(np.mean(np.square(x[inoise])))
#signallevel = np.sqrt(np.mean(np.square(x[isignal]))) #signallevel = np.sqrt(np.mean(np.square(x[isignal])))
if np.size(isignal) < 1:
print ("getSNR: Empty array isignal, check signal window!")
return SNR, SNRdB, noiselevel
#noiselevel = np.abs(x[inoise]).max() #noiselevel = np.abs(x[inoise]).max()
signallevel = np.abs(x[isignal]).max() signallevel = np.abs(x[isignal]).max()
@ -431,7 +436,7 @@ def getsignalwin(t, t1, tsignal):
return isignal return isignal
def getResolutionWindow(snr): def getResolutionWindow(snr, aperture):
""" """
Number -> Float Number -> Float
produce the half of the time resolution window width from given SNR produce the half of the time resolution window width from given SNR
@ -454,16 +459,22 @@ def getResolutionWindow(snr):
2.5 2.5
""" """
res_wins = {'HRW': 2., 'MRW': 5., 'LRW': 10., 'VLRW': 15.} res_wins = {
'regional': {'HRW': 2., 'MRW': 5., 'LRW': 10., 'VLRW': 15.},
'local': {'HRW': 2., 'MRW': 5., 'LRW': 10., 'VLRW': 15.},
'global': {'HRW': 40., 'MRW': 100., 'LRW': 200., 'VLRW': 300.}
}
if snr < 1.5: if snr < 1.5:
time_resolution = res_wins['VLRW'] time_resolution = res_wins[aperture]['VLRW']
elif snr < 2.: elif snr < 2.:
time_resolution = res_wins['LRW'] time_resolution = res_wins[aperture]['LRW']
elif snr < 3.: elif snr < 3.:
time_resolution = res_wins['MRW'] time_resolution = res_wins[aperture]['MRW']
elif snr >3.:
time_resolution = res_wins[aperture]['HRW']
else: else:
time_resolution = res_wins['HRW'] time_resolution = res_wins[aperture]['VLRW']
return time_resolution / 2 return time_resolution / 2

View File

@ -431,12 +431,18 @@ class WaveformWidget(FigureCanvas):
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None, def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
noiselevel=None, scaleddata=False, mapping=True, noiselevel=None, scaleddata=False, mapping=True,
nth_sample=1): component='*', nth_sample=1):
self.getAxes().cla() self.getAxes().cla()
self.clearPlotDict() self.clearPlotDict()
wfstart, wfend = full_range(wfdata) wfstart, wfend = full_range(wfdata)
nmax = 0 nmax = 0
compclass = SetChannelComponents() compclass = SetChannelComponents()
alter_comp = compclass.getCompPosition(component)
alter_comp = str(alter_comp[0])
wfdata = wfdata.select(component=component)
wfdata += wfdata.select(component=alter_comp)
# list containing tuples of network, station, channel (for sorting) # list containing tuples of network, station, channel (for sorting)
nsc = [] nsc = []
@ -970,9 +976,13 @@ class PickDlg(QDialog):
result = getSNR(wfdata, (noise_win, gap_win, signal_win), ini_pick, itrace) result = getSNR(wfdata, (noise_win, gap_win, signal_win), ini_pick, itrace)
snr = result[0] snr = result[0]
noiselevel = result[2] * nfac noiselevel = result[2]
if noiselevel:
noiselevel *= nfac
else:
noiselevel = nfac
x_res = getResolutionWindow(snr) x_res = getResolutionWindow(snr, 'regional')
# remove mean noise level from waveforms # remove mean noise level from waveforms
for trace in data: for trace in data:
@ -1015,7 +1025,12 @@ class PickDlg(QDialog):
# determine SNR and noiselevel # determine SNR and noiselevel
result = getSNR(wfdata, (noise_win, gap_win, signal_win), ini_pick) result = getSNR(wfdata, (noise_win, gap_win, signal_win), ini_pick)
snr = result[0] snr = result[0]
noiselevel = result[2] * nfac noiselevel = result[2]
if noiselevel:
noiselevel *= nfac
else:
noiselevel = nfac
# prepare plotting of data # prepare plotting of data
for trace in data: for trace in data:
@ -1027,7 +1042,7 @@ class PickDlg(QDialog):
horiz_comp = find_horizontals(data) horiz_comp = find_horizontals(data)
data = scaleWFData(data, noiselevel * 2.5, horiz_comp) data = scaleWFData(data, noiselevel * 2.5, horiz_comp)
x_res = getResolutionWindow(snr) x_res = getResolutionWindow(snr, 'regional')
self.setXLims(tuple([ini_pick - x_res, ini_pick + x_res])) self.setXLims(tuple([ini_pick - x_res, ini_pick + x_res]))
traces = self.getTraceID(horiz_comp) traces = self.getTraceID(horiz_comp)