[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:
parent
0fb6e5d4df
commit
6434366e55
@ -142,6 +142,9 @@ class MainWindow(QMainWindow):
|
|||||||
# setup UI
|
# setup UI
|
||||||
self.setupUi()
|
self.setupUi()
|
||||||
|
|
||||||
|
if settings.value('compclass', None) is None:
|
||||||
|
settings.setValue('compclass', SetChannelComponents())
|
||||||
|
|
||||||
if settings.value("user/FullName", None) is None:
|
if settings.value("user/FullName", None) is None:
|
||||||
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
|
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
|
||||||
settings.setValue("user/FullName", fulluser)
|
settings.setValue("user/FullName", fulluser)
|
||||||
|
@ -1 +1 @@
|
|||||||
0430-dirty
|
0fb6-dirty
|
||||||
|
@ -56,27 +56,55 @@ OUTPUTFORMATS = {'.xml': 'QUAKEML',
|
|||||||
LOCTOOLS = dict(nll=nll, hyposat=hyposat, velest=velest, hypo71=hypo71, hypodd=hypodd)
|
LOCTOOLS = dict(nll=nll, hyposat=hyposat, velest=velest, hypo71=hypo71, hypodd=hypodd)
|
||||||
|
|
||||||
|
|
||||||
class SetChannelComponents:
|
class SetChannelComponents(object):
|
||||||
def getdefaultCompPosition():
|
def __init__(self):
|
||||||
|
self.setDefaultCompPosition()
|
||||||
|
|
||||||
|
def setDefaultCompPosition(self):
|
||||||
# default component order
|
# default component order
|
||||||
CompPosition_Map = dict(Z=2, N=1, E=0)
|
self.compPosition_Map = dict(Z=2, N=1, E=0)
|
||||||
CompPosition_Map['1'] = 1
|
self.compName_Map = {'3': 'Z',
|
||||||
CompPosition_Map['2'] = 0
|
'1': 'N',
|
||||||
CompPosition_Map['3'] = 2
|
'2': 'E'}
|
||||||
CompName_Map = dict(Z='3', N='1', E='2')
|
|
||||||
CompName_Map['1'] = str(1)
|
def _getCurrentPosition(self, component):
|
||||||
CompName_Map['2'] = str(2)
|
for key, value in self.compName_Map.items():
|
||||||
CompName_Map['3'] = str(3)
|
if value == component:
|
||||||
return CompPosition_Map, CompName_Map
|
return key, value
|
||||||
|
errMsg = 'getCurrentPosition: Could not find former position of component {}.'.format(component)
|
||||||
|
raise ValueError(errMsg)
|
||||||
|
|
||||||
CompPosition_Map, CompName_Map = getdefaultCompPosition()
|
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, position):
|
def setCompPosition(self, component_alter, component, switch=True):
|
||||||
self.CompPosition_Map[component] = position
|
component_alter = str(component_alter)
|
||||||
self.CompName_Map[component] = str(position)
|
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):
|
def getCompPosition(self, component):
|
||||||
self.comppos = self.CompPosition_Map[component]
|
return self._getCurrentPosition(component)[0]
|
||||||
self.compname = self.CompName_Map[component]
|
|
||||||
return self.comppos, self.compname
|
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()))
|
||||||
|
|
||||||
|
@ -35,8 +35,7 @@ from pylot.core.io.inputs import FilterOptions, AutoPickParameter
|
|||||||
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
||||||
getResolutionWindow
|
getResolutionWindow
|
||||||
from pylot.core.pick.compare import Comparison
|
from pylot.core.pick.compare import Comparison
|
||||||
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS, \
|
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS
|
||||||
SetChannelComponents
|
|
||||||
from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \
|
from pylot.core.util.utils import prepTimeAxis, full_range, scaleWFData, \
|
||||||
demeanTrace, isSorted, findComboBoxIndex, clims
|
demeanTrace, isSorted, findComboBoxIndex, clims
|
||||||
from autoPyLoT import autoPyLoT
|
from autoPyLoT import autoPyLoT
|
||||||
@ -437,11 +436,12 @@ class WaveformWidget(FigureCanvas):
|
|||||||
wfstart, wfend = full_range(wfdata)
|
wfstart, wfend = full_range(wfdata)
|
||||||
nmax = 0
|
nmax = 0
|
||||||
|
|
||||||
compclass = SetChannelComponents()
|
settings = QSettings()
|
||||||
|
compclass = settings.value('compclass')
|
||||||
|
|
||||||
if not component == '*':
|
if not component == '*':
|
||||||
alter_comp = compclass.getCompPosition(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=component)
|
||||||
wfdata += wfdata.select(component=alter_comp)
|
wfdata += wfdata.select(component=alter_comp)
|
||||||
@ -458,8 +458,8 @@ class WaveformWidget(FigureCanvas):
|
|||||||
trace = st[0]
|
trace = st[0]
|
||||||
if mapping:
|
if mapping:
|
||||||
comp = channel[-1]
|
comp = channel[-1]
|
||||||
n = compclass.getCompPosition(str(comp))
|
n = compclass.getPlotPosition(str(comp))
|
||||||
n = n[0]
|
#n = n[0]
|
||||||
if n > nmax:
|
if n > nmax:
|
||||||
nmax = n
|
nmax = n
|
||||||
msg = 'plotting %s channel of station %s' % (channel, station)
|
msg = 'plotting %s channel of station %s' % (channel, station)
|
||||||
@ -480,7 +480,7 @@ class WaveformWidget(FigureCanvas):
|
|||||||
if iniPick:
|
if iniPick:
|
||||||
ax = self.getAxes()
|
ax = self.getAxes()
|
||||||
ax.vlines(iniPick, ax.get_ylim()[0], ax.get_ylim()[1],
|
ax.vlines(iniPick, ax.get_ylim()[0], ax.get_ylim()[1],
|
||||||
colors='green', linestyles='dashed',
|
colors='m', linestyles='dashed',
|
||||||
linewidth=2)
|
linewidth=2)
|
||||||
self.setPlotDict(n, (station, channel, network))
|
self.setPlotDict(n, (station, channel, network))
|
||||||
xlabel = 'seconds since {0}'.format(wfstart)
|
xlabel = 'seconds since {0}'.format(wfstart)
|
||||||
@ -1109,7 +1109,8 @@ class PickDlg(QDialog):
|
|||||||
stime = self.getStartTime()
|
stime = self.getStartTime()
|
||||||
stime_diff = wfdata[0].stats.starttime-stime
|
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
|
mpp = stime + pick
|
||||||
if epp:
|
if epp:
|
||||||
@ -2077,6 +2078,14 @@ class PropertiesDlg(QDialog):
|
|||||||
if values is not None:
|
if values is not None:
|
||||||
self.setValues(values)
|
self.setValues(values)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.reset_current()
|
||||||
|
QDialog.close(self)
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
self.keep_current()
|
||||||
|
QDialog.show(self)
|
||||||
|
|
||||||
def restore(self):
|
def restore(self):
|
||||||
for widint in range(self.tabWidget.count()):
|
for widint in range(self.tabWidget.count()):
|
||||||
curwid = self.tabWidget.widget(widint)
|
curwid = self.tabWidget.widget(widint)
|
||||||
@ -2084,23 +2093,35 @@ class PropertiesDlg(QDialog):
|
|||||||
if values is not None:
|
if values is not None:
|
||||||
self.setValues(values)
|
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
|
@staticmethod
|
||||||
def setValues(tabValues):
|
def setValues(tabValues):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
compclass = SetChannelComponents()
|
compclass = settings.value('compclass')
|
||||||
for setting, value in tabValues.items():
|
for setting, value in tabValues.items():
|
||||||
settings.setValue(setting, value)
|
settings.setValue(setting, value)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if setting.startswith('Channel Z'):
|
if setting.startswith('Channel Z'):
|
||||||
component = 'Z'
|
component = 'Z'
|
||||||
compclass.setCompPosition(component, value)
|
compclass.setCompPosition(value, component, False)
|
||||||
elif setting.startswith('Channel E'):
|
elif setting.startswith('Channel E'):
|
||||||
component = 'E'
|
component = 'E'
|
||||||
compclass.setCompPosition(component, value)
|
compclass.setCompPosition(value, component, False)
|
||||||
elif setting.startswith('Channel N'):
|
elif setting.startswith('Channel N'):
|
||||||
component = 'N'
|
component = 'N'
|
||||||
compclass.setCompPosition(component, value)
|
compclass.setCompPosition(value, component, False)
|
||||||
settings.sync()
|
settings.sync()
|
||||||
|
|
||||||
|
|
||||||
@ -2254,7 +2275,8 @@ class ChannelOrderTab(PropTab):
|
|||||||
def __init__(self, parent=None, infile=None):
|
def __init__(self, parent=None, infile=None):
|
||||||
super(ChannelOrderTab, self).__init__(parent)
|
super(ChannelOrderTab, self).__init__(parent)
|
||||||
|
|
||||||
compclass = SetChannelComponents()
|
settings = QSettings()
|
||||||
|
compclass = settings.value('compclass')
|
||||||
|
|
||||||
ChannelOrderLabelZ = QLabel("Channel Z [up/down, default=3]")
|
ChannelOrderLabelZ = QLabel("Channel Z [up/down, default=3]")
|
||||||
ChannelOrderLabelN = QLabel("Channel N [north/south, default=1]")
|
ChannelOrderLabelN = QLabel("Channel N [north/south, default=1]")
|
||||||
@ -2269,9 +2291,9 @@ class ChannelOrderTab(PropTab):
|
|||||||
self.ChannelOrderEEdit.setMaxLength(1)
|
self.ChannelOrderEEdit.setMaxLength(1)
|
||||||
self.ChannelOrderEEdit.setFixedSize(20, 20)
|
self.ChannelOrderEEdit.setFixedSize(20, 20)
|
||||||
# get channel order settings
|
# get channel order settings
|
||||||
zpos, zcomp = compclass.getCompPosition('Z')
|
zcomp = compclass.getCompPosition('Z')
|
||||||
epos, ecomp = compclass.getCompPosition('E')
|
ecomp = compclass.getCompPosition('E')
|
||||||
npos, ncomp = compclass.getCompPosition('N')
|
ncomp = compclass.getCompPosition('N')
|
||||||
self.ChannelOrderZEdit.setText("%s" % zcomp)
|
self.ChannelOrderZEdit.setText("%s" % zcomp)
|
||||||
self.ChannelOrderNEdit.setText("%s" % ecomp)
|
self.ChannelOrderNEdit.setText("%s" % ecomp)
|
||||||
self.ChannelOrderEEdit.setText("%s" % ncomp)
|
self.ChannelOrderEEdit.setText("%s" % ncomp)
|
||||||
@ -2285,7 +2307,34 @@ class ChannelOrderTab(PropTab):
|
|||||||
layout.addWidget(self.ChannelOrderEEdit, 2, 1)
|
layout.addWidget(self.ChannelOrderEEdit, 2, 1)
|
||||||
|
|
||||||
self.setLayout(layout)
|
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):
|
def getValues(self):
|
||||||
values = {"Channel Z [up/down, default=3]": int(self.ChannelOrderZEdit.text()),
|
values = {"Channel Z [up/down, default=3]": int(self.ChannelOrderZEdit.text()),
|
||||||
"Channel N [north/south, default=1]": int(self.ChannelOrderNEdit.text()),
|
"Channel N [north/south, default=1]": int(self.ChannelOrderNEdit.text()),
|
||||||
@ -2301,10 +2350,11 @@ class ChannelOrderTab(PropTab):
|
|||||||
"Channel E [east/west, default=2]": self.ChannelOrderEEdit.setText("%d" % Edefault)}
|
"Channel E [east/west, default=2]": self.ChannelOrderEEdit.setText("%d" % Edefault)}
|
||||||
return values
|
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):
|
class LocalisationTab(PropTab):
|
||||||
def __init__(self, parent=None, infile=None):
|
def __init__(self, parent=None, infile=None):
|
||||||
super(LocalisationTab, self).__init__(parent)
|
super(LocalisationTab, self).__init__(parent)
|
||||||
|
Loading…
Reference in New Issue
Block a user