diff --git a/QtPyLoT.py b/QtPyLoT.py index 06693782..3f367348 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -81,11 +81,13 @@ class MainWindow(QMainWindow): __version__ = _getVersionString() closing = Signal() - def __init__(self, parent=None): + def __init__(self, parent=None, infile=None): super(MainWindow, self).__init__(parent) # 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: infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file') if not os.path.exists(infile[0]): @@ -742,6 +744,7 @@ class MainWindow(QMainWindow): self.eventBox.setCurrentIndex(nitems) self.refreshEvents() tabindex = self.tabs.currentIndex() + self.setDirty(True) def fill_eventbox(self, eventBox=None, select_events='all'): ''' @@ -1215,17 +1218,15 @@ class MainWindow(QMainWindow): nth_sample = settings.value('nth_sample') if not nth_sample: nth_sample = 1 - compclass = SetChannelComponents() zne_text = {'Z': 'vertical', 'N': 'north-south', 'E': 'east-west'} comp = self.getComponent() title = 'section: {0} components'.format(zne_text[comp]) - alter_comp = compclass.getCompPosition(comp) - alter_comp = str(alter_comp[0]) - wfst = self.get_data().getWFData().select(component=comp) - wfst += self.get_data().getWFData().select(component=alter_comp) + wfst = self.get_data().getWFData() + # wfst = self.get_data().getWFData().select(component=comp) + # wfst += self.get_data().getWFData().select(component=alter_comp) plotWidget = self.getPlotWidget() 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() pos = plotDict.keys() labels = [plotDict[n][2]+'.'+plotDict[n][0] for n in pos] @@ -2240,6 +2241,14 @@ def create_window(): 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 pylot_app, app_created = create_window() #pylot_app = QApplication(sys.argv) @@ -2251,7 +2260,7 @@ def main(args=None): app_icon.addPixmap(QPixmap(':/icons/pylot.png')) # create the main window - pylot_form = MainWindow() + pylot_form = MainWindow(infile=pylot_infile) icon = QIcon() pylot_form.setWindowIcon(icon) pylot_form.setIconSize(QSize(60, 60)) @@ -2274,9 +2283,8 @@ def main(args=None): splash.finish(pylot_form) - if args: - if args.project_filename: - pylot_form.loadProject(args.project_filename) + if project_filename: + pylot_form.loadProject(args.project_filename) if app_created: pylot_app.exec_() @@ -2288,5 +2296,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description='Welcome to PyLoT.') parser.add_argument('-p', dest='project_filename', help='load project file', default=None) + parser.add_argument('-in', dest='input_filename', help='set pylot input file', + default=None) args = parser.parse_args() sys.exit(main(args)) diff --git a/pylot/RELEASE-VERSION b/pylot/RELEASE-VERSION index ce5c4cbf..3bdc5478 100644 --- a/pylot/RELEASE-VERSION +++ b/pylot/RELEASE-VERSION @@ -1 +1 @@ -a745-dirty +ceed1-dirty diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 724997a3..5a06de3e 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -343,6 +343,10 @@ def getSNR(X, TSNR, t1, tracenum=0): assert isinstance(X, Stream), "%s is not a stream object" % str(X) + SNR = None + SNRdb = None + noiselevel = None + x = X[tracenum].data npts = X[tracenum].stats.npts sr = X[tracenum].stats.sampling_rate @@ -356,10 +360,7 @@ def getSNR(X, TSNR, t1, tracenum=0): isignal = getsignalwin(t, t1, TSNR[2]) if np.size(inoise) < 1: print ("getSNR: Empty array inoise, check noise window!") - return - elif np.size(isignal) < 1: - print ("getSNR: Empty array isignal, check signal window!") - return + return SNR, SNRdB, noiselevel # demean over entire waveform 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]))) #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() signallevel = np.abs(x[isignal]).max() @@ -431,7 +436,7 @@ def getsignalwin(t, t1, tsignal): return isignal -def getResolutionWindow(snr): +def getResolutionWindow(snr, aperture): """ Number -> Float produce the half of the time resolution window width from given SNR @@ -453,18 +458,24 @@ def getResolutionWindow(snr): >>> getResolutionWindow(2) 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: - time_resolution = res_wins['VLRW'] + time_resolution = res_wins[aperture]['VLRW'] elif snr < 2.: - time_resolution = res_wins['LRW'] + time_resolution = res_wins[aperture]['LRW'] elif snr < 3.: - time_resolution = res_wins['MRW'] + time_resolution = res_wins[aperture]['MRW'] + elif snr >3.: + time_resolution = res_wins[aperture]['HRW'] else: - time_resolution = res_wins['HRW'] - + time_resolution = res_wins[aperture]['VLRW'] + return time_resolution / 2 diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 3f4f6839..04d63c78 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -431,13 +431,19 @@ class WaveformWidget(FigureCanvas): def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None, noiselevel=None, scaleddata=False, mapping=True, - nth_sample=1): + component='*', nth_sample=1): self.getAxes().cla() self.clearPlotDict() wfstart, wfend = full_range(wfdata) nmax = 0 + 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) nsc = [] for trace in wfdata: @@ -970,9 +976,13 @@ class PickDlg(QDialog): result = getSNR(wfdata, (noise_win, gap_win, signal_win), ini_pick, itrace) 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 for trace in data: @@ -1015,7 +1025,12 @@ class PickDlg(QDialog): # determine SNR and noiselevel result = getSNR(wfdata, (noise_win, gap_win, signal_win), ini_pick) snr = result[0] - noiselevel = result[2] * nfac + noiselevel = result[2] + + if noiselevel: + noiselevel *= nfac + else: + noiselevel = nfac # prepare plotting of data for trace in data: @@ -1027,7 +1042,7 @@ class PickDlg(QDialog): horiz_comp = find_horizontals(data) 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])) traces = self.getTraceID(horiz_comp)