huge structural rearrangement to resolve circular import problems

[add] new feature added to QtPyLoT capable of automatically picking an event from overview window
This commit is contained in:
Sebastian Wehling-Benatelli 2015-07-10 09:22:58 +02:00
parent f704d8b258
commit ea976295d0
13 changed files with 128 additions and 162 deletions

View File

@ -34,17 +34,23 @@ from PySide.QtCore import QCoreApplication, QSettings, Signal, QFile, \
from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
QWidget, QHBoxLayout, QStyle, QKeySequence, QLabel, QFrame, QAction, \
QDialog, QErrorMessage, QApplication, QPixmap, QMessageBox, QSplashScreen, \
QActionGroup, QListWidget
QActionGroup, QListWidget, QDockWidget
import numpy as np
from obspy.core import UTCDateTime
from pylot.core.read import Data, FilterOptions, AutoPickParameter
from pylot.core.util import _getVersionString, FILTERDEFAULTS, fnConstructor, \
checkurl, FormatError, FilterOptionsDialog, \
NewEventDlg, createEvent, MPLWidget, PropertiesDlg, HelpForm, \
DatastructureError, createAction, getLogin, createCreationInfo, PickDlg
from pylot.core.util.thread import WorkerThread
from pylot.core.read.data import Data
from pylot.core.read.inputs import FilterOptions, AutoPickParameter
from pylot.core.pick.autopick import autopickevent
from pylot.core.util.defaults import FILTERDEFAULTS
from pylot.core.util.errors import FormatError, DatastructureError
from pylot.core.util.connection import checkurl
from pylot.core.util.utils import fnConstructor, createEvent, getLogin,\
createCreationInfo
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg,\
MPLWidget, PropertiesDlg, HelpForm, createAction, PickDlg
from pylot.core.util.structure import DATASTRUCTURE
from pylot.core.util.thread import WorkerThread
from pylot.core.util.version import get_git_version as _getVersionString
import icons_rc
# Version information
@ -586,6 +592,13 @@ class MainWindow(QMainWindow):
def autoPick(self):
list = QListWidget()
logDockWidget = QDockWidget("AutoPickLog", self)
logDockWidget.setObjectName("LogDockWidget")
logDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea)
logDockWidget.setWidget(list)
logDockWidget.show()
logDockWidget.setFloating(False)
list.addItem('loading default values for local data ...')
autopick_parameter = AutoPickParameter('autoPyLoT_local.in')
list.addItem(str(autopick_parameter))
@ -597,6 +610,8 @@ class MainWindow(QMainWindow):
self.thread.message.connect(list.addItem)
self.thread.start()
self.drawPicks()
def addPicks(self, station, picks):
stat_picks = self.getPicksOnStation(station)

View File

@ -9,10 +9,10 @@ import glob
import matplotlib.pyplot as plt
from obspy.core import read
from pylot.core.util import _getVersionString
from pylot.core.read import Data, AutoPickParameter
from pylot.core.pick.run_autopicking import run_autopicking
from pylot.core.read.data import Data
from pylot.core.read.inputs import AutoPickParameter
from pylot.core.util.structure import DATASTRUCTURE
from pylot.core.pick.utils import wadaticheck, checkPonsets
from pylot.core.pick.autopick import autopickevent
__version__ = _getVersionString()
@ -49,12 +49,6 @@ def autoPyLoT(inputfile):
parameter = AutoPickParameter(inputfile)
# get some parameters for quality control from
# parameter input file (usually autoPyLoT.in).
wdttolerance = parameter.getParam('wdttolerance')
mdttolerance = parameter.getParam('mdttolerance')
iplot = parameter.getParam('iplot')
data = Data()
# getting information on data structure
@ -86,31 +80,7 @@ def autoPyLoT(inputfile):
wfdat = data.getWFData() # all available streams
##########################################################
# !automated picking starts here!
procstats = []
# initialize dictionary for onsets
picks = None
station = wfdat[0].stats.station
allonsets = {station: picks}
for i in range(len(wfdat)):
stationID = wfdat[i].stats.station
# check if station has already been processed
if stationID not in procstats:
procstats.append(stationID)
# find corresponding streams
statdat = wfdat.select(station=stationID)
######################################################
# get onset times and corresponding picking errors
picks = run_autopicking(statdat, parameter)
######################################################
# add station and corresponding onsets to dictionary
station = stationID
allonsets[station] = picks
# quality control
# median check and jackknife on P-onset times
checkedonsetsjk = checkPonsets(allonsets, mdttolerance, iplot)
# check S-P times (Wadati)
checkedonsetwd = wadaticheck(checkedonsetsjk, wdttolerance, iplot)
picks = autopickevent(wfdat, parameter)
print '------------------------------------------'
print '-----Finished event %s!-----' % event
@ -125,32 +95,7 @@ def autoPyLoT(inputfile):
wfdat = data.getWFData() # all available streams
##########################################################
# !automated picking starts here!
procstats = []
# initialize dictionary for onsets
picks = None
station = wfdat[0].stats.station
allonsets = {station: picks}
for i in range(len(wfdat)):
#for i in range(0,10):
stationID = wfdat[i].stats.station
#check if station has already been processed
if stationID not in procstats:
procstats.append(stationID)
# find corresponding streams
statdat = wfdat.select(station=stationID)
######################################################
# get onset times and corresponding picking parameters
picks = run_autopicking(statdat, parameter)
######################################################
# add station and corresponding onsets to dictionary
station = stationID
allonsets[station] = picks
# quality control
# median check and jackknife on P-onset times
checkedonsetsjk = checkPonsets(allonsets, mdttolerance, iplot)
# check S-P times (Wadati)
checkedonsetswd = wadaticheck(checkedonsetsjk, wdttolerance, iplot)
picks = autopickevent(wfdat, parameter)
print '------------------------------------------'
print '-------Finished event %s!-------' % parameter.getParam('eventID')

View File

@ -20,7 +20,7 @@ calculated after Diehl & Kissling (2009).
"""
import numpy as np
import matplotlib.pyplot as plt
from pylot.core.pick.utils import *
from pylot.core.pick.utils import getnoisewin, getsignalwin
from pylot.core.pick.CharFuns import CharacteristicFunction
import warnings

View File

@ -11,9 +11,37 @@ function conglomerate utils.
import matplotlib.pyplot as plt
import numpy as np
from pylot.core.pick.Picker import *
from pylot.core.pick.CharFuns import *
from pylot.core.pick.Picker import AICPicker, PragPicker
from pylot.core.pick.CharFuns import HOScf, AICcf, ARZcf, ARHcf, AR3Ccf
from pylot.core.pick.utils import checksignallength, checkZ4S, earllatepicker,\
getSNR, fmpicker, checkPonsets, wadaticheck
def autopickevent(data, param):
stations = []
all_onsets = {}
# get some parameters for quality control from
# parameter input file (usually autoPyLoT.in).
wdttolerance = param.getParam('wdttolerance')
mdttolerance = param.getParam('mdttolerance')
iplot = param.getParam('iplot')
for n in range(len(data)):
station = data[n].stats.station
if station not in stations:
stations.append(station)
else:
continue
for station in stations:
topick = data.select(station=station)
all_onsets[station] = run_autopicking(topick, param)
# quality control
# median check and jackknife on P-onset times
jk_checked_onsets = checkPonsets(all_onsets, mdttolerance, iplot)
# check S-P times (Wadati)
return wadaticheck(jk_checked_onsets, wdttolerance, iplot)
def run_autopicking(wfstream, pickparam):
"""

View File

@ -12,24 +12,9 @@ import numpy as np
import scipy as sc
import matplotlib.pyplot as plt
from obspy.core import Stream, UTCDateTime
from pylot.core.pick.run_autopicking import run_autopicking
import warnings
import pdb
def autopickevent(data, param):
stations = []
for n in len(data):
station = data[n].stats.station
if station not in stations:
stations.append(station)
else:
continue
for station in stations:
topick = data.select(station=station)
stat_picks = run_autopicking(topick, param)
def earllatepicker(X, nfac, TSNR, Pick1, iplot=None):
'''

View File

@ -1,4 +1 @@
from pylot.core.read.inputs import AutoPickParameter, FilterOptions
from pylot.core.read.io import readPILOTEvent
from pylot.core.read.data import GenericDataStructure, SeiscompDataStructure, \
PilotDataStructure, Data

View File

@ -7,9 +7,9 @@ from obspy.core import (read, Stream, UTCDateTime)
from obspy import readEvents, read_inventory
from obspy.core.event import (Event, Catalog)
from pylot.core.read import readPILOTEvent
from pylot.core.util import fnConstructor, FormatError, \
getGlobalTimes
from pylot.core.read.io import readPILOTEvent
from pylot.core.util.utils import fnConstructor, getGlobalTimes
from pylot.core.util.errors import FormatError
class Data(object):

View File

@ -7,9 +7,8 @@ import scipy.io as sio
import obspy.core.event as ope
from obspy.core import UTCDateTime
from pylot.core.util import getOwner, createPick, createArrival, createEvent, \
createOrigin, createMagnitude
from pylot.core.util.utils import getOwner, createPick, createArrival,\
createEvent, createOrigin, createMagnitude
def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
"""

View File

@ -1,10 +1 @@
from pylot.core.util.connection import checkurl
from pylot.core.util.defaults import FILTERDEFAULTS
from pylot.core.util.errors import OptionsError, FormatError, DatastructureError
from pylot.core.util.utils import fnConstructor, createArrival, createEvent,\
createPick, createAmplitude, createOrigin, createMagnitude, getOwner, \
getHash, getLogin, createCreationInfo, createResourceID, prepTimeAxis, \
getGlobalTimes, scaleWFData, demeanWFData
from pylot.core.util.widgets import PickDlg, HelpForm, FilterOptionsDialog,\
PropertiesDlg, NewEventDlg, MPLWidget, createAction
from pylot.core.util.version import get_git_version as _getVersionString

View File

@ -6,7 +6,7 @@ Created on Wed Jan 26 17:47:25 2015
@author: sebastianw
"""
from pylot.core.read import SeiscompDataStructure, PilotDataStructure
from pylot.core.read.data import SeiscompDataStructure, PilotDataStructure
DATASTRUCTURE = {'PILOT': PilotDataStructure, 'SeisComP': SeiscompDataStructure,
None: None}

View File

@ -17,7 +17,8 @@ class WorkerThread(QThread):
picks = self.func(self.data, self.param)
try:
self.parent().addPicks(picks)
for station in picks:
self.parent().addPicks(station, picks[station])
except AttributeError:
print picks

View File

@ -10,7 +10,6 @@ import hashlib
import numpy as np
from obspy.core import UTCDateTime
import obspy.core.event as ope
from pylot.core.pick.utils import getnoisewin
def runProgram(cmd, parameter=None):
"""
@ -119,28 +118,20 @@ def scaleWFData(data, factor=None, components='all'):
return data
def demeanWFData(data, t0, win, gap):
def demeanTrace(trace, window):
"""
returns the DATA where each trace is demean by the average value within
a desired time window WIN before T0 and a GAP
:param data: waveform stream object
:type data: `~obspy.core.stream.Stream`
:param t0: time before which the noise
:type t0: float
:param win: time window for average calculation
:type win: tuple
:param gap: gap window to avoid polluting the average
:type gap: float
:return: data
:rtype: `~obspy.core.stream.Stream`
WINDOW
:param trace: waveform trace object
:type trace: `~obspy.core.stream.Trace`
:param inoise: range of indices of DATA within the WINDOW
:type window: tuple
:return: trace
:rtype: `~obspy.core.stream.Trace`
"""
starttime = getGlobalTimes(data)[0]
for tr in data:
stime = tr.stats.starttime - starttime
t = prepTimeAxis(stime, tr)
inoise = getnoisewin(t, t0, win, gap)
tr.data -= tr.data[inoise].mean()
return data
trace.data -= trace.data[window].mean()
return trace
def getGlobalTimes(stream):
min_start = UTCDateTime()

View File

@ -19,12 +19,12 @@ from PySide.QtGui import QAction, QApplication, QComboBox, QDateTimeEdit, \
from PySide.QtCore import QSettings, Qt, QUrl, Signal, Slot
from PySide.QtWebKit import QWebView
from obspy import Stream, UTCDateTime
from pylot.core.read import FilterOptions
from pylot.core.read.inputs import FilterOptions
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin,\
getResolutionWindow
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS
from pylot.core.util import prepTimeAxis, getGlobalTimes, scaleWFData, \
demeanWFData
from pylot.core.util.utils import prepTimeAxis, getGlobalTimes, scaleWFData, \
demeanTrace
def createAction(parent, text, slot=None, shortcut=None, icon=None,
@ -191,6 +191,8 @@ class PickDlg(QDialog):
else:
self.data = data
self.stime, self.etime = getGlobalTimes(self.getWFData())
# initialize plotting widget
self.multicompfig = MPLWidget(self)
@ -336,6 +338,12 @@ class PickDlg(QDialog):
self.cidrelease = self.connectReleaseEvent(self.panRelease)
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
def getStartTime(self):
return self.stime
def getEndTime(self):
return self.etime
def getComponents(self):
return self.components
@ -446,13 +454,16 @@ class PickDlg(QDialog):
x_res = getResolutionWindow(snr)
data = demeanWFData(data=self.getWFData().copy(), t0=ini_pick,
win=noise_win, gap=gap_win)
# remove mean noise level from waveforms
for trace in wfdata:
t = prepTimeAxis(self.getStartTime(), trace)
inoise = getnoisewin(t, ini_pick, noise_win, gap_win)
trace = demeanTrace(trace=trace, window=inoise)
self.setXLims([ini_pick - x_res, ini_pick + x_res])
self.setYLims(np.array([-noiselevel * 2.5, noiselevel * 2.5]) +
trace_number)
self.getPlotWidget().plotWFData(wfdata=data,
self.getPlotWidget().plotWFData(wfdata=wfdata,
title=self.getStation() +
' picking mode',
zoomx=self.getXLims(),
@ -482,7 +493,10 @@ class PickDlg(QDialog):
filteroptions = self.getFilterOptions(phase).parseFilterOptions()
data.filter(**filteroptions)
data = demeanWFData(data=data, t0=ini_pick, win=noise_win, gap=gap_win)
for trace in data:
t = prepTimeAxis(self.getStartTime(), trace)
inoise = getnoisewin(t, ini_pick, noise_win, gap_win)
trace = demeanTrace(trace, inoise)
horiz_comp = ('n', 'e')
@ -576,9 +590,9 @@ class PickDlg(QDialog):
else:
return
mpp = picks['mpp']
epp = picks['epp']
lpp = picks['lpp']
mpp = picks['mpp'] - self.getStartTime()
epp = picks['epp'] - self.getStartTime()
lpp = picks['lpp'] - self.getStartTime()
spe = picks['spe']
ax.fill_between([epp, lpp], ylims[0], ylims[1],