[bugfixes] several fixes relating to Channel Components, main issue: SetChannelComponents object was newly initated every time. Now: One object saved inside global QSettings. Testing needed.

This commit is contained in:
Marcel Paffrath 2017-06-02 11:51:00 +02:00
parent 0fb6e5d4df
commit 6434366e55
4 changed files with 120 additions and 39 deletions

View File

@ -142,6 +142,9 @@ class MainWindow(QMainWindow):
# setup UI
self.setupUi()
if settings.value('compclass', None) is None:
settings.setValue('compclass', SetChannelComponents())
if settings.value("user/FullName", None) is None:
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
settings.setValue("user/FullName", fulluser)

View File

@ -1 +1 @@
0430-dirty
0fb6-dirty

View File

@ -56,27 +56,55 @@ OUTPUTFORMATS = {'.xml': 'QUAKEML',
LOCTOOLS = dict(nll=nll, hyposat=hyposat, velest=velest, hypo71=hypo71, hypodd=hypodd)
class SetChannelComponents:
def getdefaultCompPosition():
class SetChannelComponents(object):
def __init__(self):
self.setDefaultCompPosition()
def setDefaultCompPosition(self):
# default component order
CompPosition_Map = dict(Z=2, N=1, E=0)
CompPosition_Map['1'] = 1
CompPosition_Map['2'] = 0
CompPosition_Map['3'] = 2
CompName_Map = dict(Z='3', N='1', E='2')
CompName_Map['1'] = str(1)
CompName_Map['2'] = str(2)
CompName_Map['3'] = str(3)
return CompPosition_Map, CompName_Map
self.compPosition_Map = dict(Z=2, N=1, E=0)
self.compName_Map = {'3': 'Z',
'1': 'N',
'2': 'E'}
CompPosition_Map, CompName_Map = getdefaultCompPosition()
def _getCurrentPosition(self, component):
for key, value in self.compName_Map.items():
if value == component:
return key, value
errMsg = 'getCurrentPosition: Could not find former position of component {}.'.format(component)
raise ValueError(errMsg)
def setCompPosition(self, component, position):
self.CompPosition_Map[component] = position
self.CompName_Map[component] = str(position)
def _switch(self, component, component_alter):
# Without switching, multiple definitions of the same alter_comp are possible
old_alter_comp, _ = self._getCurrentPosition(component)
old_comp = self.compName_Map[component_alter]
if not old_alter_comp == component_alter and not old_comp == component:
self.compName_Map[old_alter_comp] = old_comp
print('switch: Automatically switched component {} to {}'.format(old_alter_comp, old_comp))
def setCompPosition(self, component_alter, component, switch=True):
component_alter = str(component_alter)
if not component_alter in self.compName_Map.keys():
errMsg='setCompPosition: Unrecognized alternative component {}. Expecting one of {}.'
raise ValueError(errMsg.format(component_alter, self.compName_Map.keys()))
if not component in self.compPosition_Map.keys():
errMsg='setCompPosition: Unrecognized target component {}. Expecting one of {}.'
raise ValueError(errMsg.format(component, self.compPosition_Map.keys()))
print('setCompPosition: set component {} to {}'.format(component_alter, component))
if switch:
self._switch(component, component_alter)
self.compName_Map[component_alter] = component
def getCompPosition(self, component):
self.comppos = self.CompPosition_Map[component]
self.compname = self.CompName_Map[component]
return self.comppos, self.compname
return self._getCurrentPosition(component)[0]
def getPlotPosition(self, component):
component = str(component)
if component in self.compPosition_Map.keys():
return self.compPosition_Map[component]
elif component in self.compName_Map.keys():
return self.compPosition_Map[self.compName_Map[component]]
else:
errMsg='getCompPosition: Unrecognized component {}. Expecting one of {} or {}.'
raise ValueError(errMsg.format(component, self.compPosition_Map.keys(), self.compName_Map.keys()))

View File

@ -35,8 +35,7 @@ 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
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS, \
SetChannelComponents
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS
from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \
demeanTrace, isSorted, findComboBoxIndex, clims
from autoPyLoT import autoPyLoT
@ -437,11 +436,12 @@ class WaveformWidget(FigureCanvas):
wfstart, wfend = full_range(wfdata)
nmax = 0
compclass = SetChannelComponents()
settings = QSettings()
compclass = settings.value('compclass')
if not component == '*':
alter_comp = compclass.getCompPosition(component)
alter_comp = str(alter_comp[0])
#alter_comp = str(alter_comp[0])
wfdata = wfdata.select(component=component)
wfdata += wfdata.select(component=alter_comp)
@ -458,8 +458,8 @@ class WaveformWidget(FigureCanvas):
trace = st[0]
if mapping:
comp = channel[-1]
n = compclass.getCompPosition(str(comp))
n = n[0]
n = compclass.getPlotPosition(str(comp))
#n = n[0]
if n > nmax:
nmax = n
msg = 'plotting %s channel of station %s' % (channel, station)
@ -480,7 +480,7 @@ class WaveformWidget(FigureCanvas):
if iniPick:
ax = self.getAxes()
ax.vlines(iniPick, ax.get_ylim()[0], ax.get_ylim()[1],
colors='green', linestyles='dashed',
colors='m', linestyles='dashed',
linewidth=2)
self.setPlotDict(n, (station, channel, network))
xlabel = 'seconds since {0}'.format(wfstart)
@ -1109,7 +1109,8 @@ class PickDlg(QDialog):
stime = self.getStartTime()
stime_diff = wfdata[0].stats.starttime-stime
[epp, lpp, spe] = earllatepicker(wfdata, nfac, (TSNR[0], TSNR[1], TSNR[2]), pick-stime_diff, verbosity=2)
[epp, lpp, spe] = earllatepicker(wfdata, nfac, (TSNR[0], TSNR[1], TSNR[2]),
pick-stime_diff, verbosity=1)
mpp = stime + pick
if epp:
@ -2077,6 +2078,14 @@ class PropertiesDlg(QDialog):
if values is not None:
self.setValues(values)
def close(self):
self.reset_current()
QDialog.close(self)
def show(self):
self.keep_current()
QDialog.show(self)
def restore(self):
for widint in range(self.tabWidget.count()):
curwid = self.tabWidget.widget(widint)
@ -2084,23 +2093,35 @@ class PropertiesDlg(QDialog):
if values is not None:
self.setValues(values)
def keep_current(self):
self._current_values = []
for widint in range(self.tabWidget.count()):
curwid = self.tabWidget.widget(widint)
values = curwid.getValues()
if values is not None:
self._current_values.append(values)
def reset_current(self):
for values in self._current_values():
self.setValues(values)
@staticmethod
def setValues(tabValues):
settings = QSettings()
compclass = SetChannelComponents()
compclass = settings.value('compclass')
for setting, value in tabValues.items():
settings.setValue(setting, value)
if value is not None:
if setting.startswith('Channel Z'):
component = 'Z'
compclass.setCompPosition(component, value)
compclass.setCompPosition(value, component, False)
elif setting.startswith('Channel E'):
component = 'E'
compclass.setCompPosition(component, value)
compclass.setCompPosition(value, component, False)
elif setting.startswith('Channel N'):
component = 'N'
compclass.setCompPosition(component, value)
compclass.setCompPosition(value, component, False)
settings.sync()
@ -2254,7 +2275,8 @@ class ChannelOrderTab(PropTab):
def __init__(self, parent=None, infile=None):
super(ChannelOrderTab, self).__init__(parent)
compclass = SetChannelComponents()
settings = QSettings()
compclass = settings.value('compclass')
ChannelOrderLabelZ = QLabel("Channel Z [up/down, default=3]")
ChannelOrderLabelN = QLabel("Channel N [north/south, default=1]")
@ -2269,9 +2291,9 @@ class ChannelOrderTab(PropTab):
self.ChannelOrderEEdit.setMaxLength(1)
self.ChannelOrderEEdit.setFixedSize(20, 20)
# get channel order settings
zpos, zcomp = compclass.getCompPosition('Z')
epos, ecomp = compclass.getCompPosition('E')
npos, ncomp = compclass.getCompPosition('N')
zcomp = compclass.getCompPosition('Z')
ecomp = compclass.getCompPosition('E')
ncomp = compclass.getCompPosition('N')
self.ChannelOrderZEdit.setText("%s" % zcomp)
self.ChannelOrderNEdit.setText("%s" % ecomp)
self.ChannelOrderEEdit.setText("%s" % ncomp)
@ -2285,6 +2307,33 @@ class ChannelOrderTab(PropTab):
layout.addWidget(self.ChannelOrderEEdit, 2, 1)
self.setLayout(layout)
self.connectSignals()
def connectSignals(self):
self.ChannelOrderZEdit.textEdited.connect(self.checkDoubleZ)
self.ChannelOrderNEdit.textEdited.connect(self.checkDoubleN)
self.ChannelOrderEEdit.textEdited.connect(self.checkDoubleE)
def checkDoubleZ(self, text):
self.checkDouble(text, 'Z')
def checkDoubleN(self, text):
self.checkDouble(text, 'N')
def checkDoubleE(self, text):
self.checkDouble(text, 'E')
def checkDouble(self, text, comp):
channelOrderEdits = {
'Z': self.ChannelOrderZEdit,
'N': self.ChannelOrderNEdit,
'E': self.ChannelOrderEEdit
}
for key in channelOrderEdits.keys():
if key == comp:
continue
if str(channelOrderEdits[key].text()) == str(text):
channelOrderEdits[key].setText('')
def getValues(self):
values = {"Channel Z [up/down, default=3]": int(self.ChannelOrderZEdit.text()),
@ -2301,9 +2350,10 @@ class ChannelOrderTab(PropTab):
"Channel E [east/west, default=2]": self.ChannelOrderEEdit.setText("%d" % Edefault)}
return values
def getComponents(self):
# MP MP: No idea why this function exists!?
# def getComponents(self):
# self.CompName = dict(Z='10', N='11', E='12')
self.CompName = dict(Z='10', N='11', E='12')
class LocalisationTab(PropTab):
def __init__(self, parent=None, infile=None):