Merged 195 into develop

This commit is contained in:
Sebastian Wehling-Benatelli 2016-06-10 14:37:40 +02:00
commit a3deb2a9d3
2 changed files with 68 additions and 36 deletions

View File

@ -140,6 +140,18 @@ class Comparison(object):
plt.show() plt.show()
def get_array(self, phase, method):
pdf_dict = self.comparison
exp_array = list()
for station, phases in pdf_dict.items():
try:
exp_array.append(phases[phase].expectation())
except KeyError as e:
print('{err_msg}; station = {station}, phase = {phase}'.format(
err_msg=str(e), station=station, phase=phase))
continue
return exp_array
def get_expectation_array(self, phase): def get_expectation_array(self, phase):
pdf_dict = self.comparison pdf_dict = self.comparison
exp_array = list() exp_array = list()

View File

@ -17,11 +17,11 @@ except ImportError:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT
from matplotlib.widgets import MultiCursor from matplotlib.widgets import MultiCursor
from PySide.QtGui import QAction, QApplication, QComboBox, QDateTimeEdit, \ from PySide.QtGui import QAction, QApplication, QCheckBox, QComboBox, \
QDialog, QDialogButtonBox, QDoubleSpinBox, QGroupBox, QGridLayout, \ QDateTimeEdit, QDialog, QDialogButtonBox, QDoubleSpinBox, QGroupBox, \
QIcon, QKeySequence, QLabel, QLineEdit, QMessageBox, QPixmap, QSpinBox, \ QGridLayout, QIcon, QKeySequence, QLabel, QLineEdit, QMessageBox, \
QTabWidget, QToolBar, QVBoxLayout, QWidget, QPushButton, QFileDialog, \ QPixmap, QSpinBox, QTabWidget, QToolBar, QVBoxLayout, QWidget, \
QInputDialog QPushButton, QFileDialog, QInputDialog
from PySide.QtCore import QSettings, Qt, QUrl, Signal, Slot from PySide.QtCore import QSettings, Qt, QUrl, Signal, Slot
from PySide.QtWebKit import QWebView from PySide.QtWebKit import QWebView
from obspy import Stream, UTCDateTime from obspy import Stream, UTCDateTime
@ -71,7 +71,8 @@ class ComparisonDialog(QDialog):
self._stats = c.stations self._stats = c.stations
self._canvas = PlotWidget(self) self._canvas = PlotWidget(self)
self._widgets = dict(stationsComboBox=None, self._widgets = dict(stationsComboBox=None,
phasesComboBox=None) phasesComboBox=None,
histCheckBox=None)
self._phases = 'PS' self._phases = 'PS'
self._plotprops = dict(station=self.stations[0], phase=self.phases[0]) self._plotprops = dict(station=self.stations[0], phase=self.phases[0])
super(ComparisonDialog, self).__init__(parent) super(ComparisonDialog, self).__init__(parent)
@ -97,9 +98,15 @@ class ComparisonDialog(QDialog):
_phases_combobox.currentIndexChanged.connect(self.prepareplot) _phases_combobox.currentIndexChanged.connect(self.prepareplot)
self.widgets = _phases_combobox self.widgets = _phases_combobox
_hist_checkbox = QCheckBox('Show histograms', self)
_hist_checkbox.setObjectName('histCheckBox')
_hist_checkbox.stateChanged.connect(self.plothist)
self.widgets = _hist_checkbox
_toolbar = QToolBar(self) _toolbar = QToolBar(self)
_toolbar.addWidget(_stats_combobox) _toolbar.addWidget(_stats_combobox)
_toolbar.addWidget(_phases_combobox) _toolbar.addWidget(_phases_combobox)
_toolbar.addWidget(_hist_checkbox)
_buttonbox = QDialogButtonBox(QDialogButtonBox.Close) _buttonbox = QDialogButtonBox(QDialogButtonBox.Close)
@ -170,7 +177,7 @@ class ComparisonDialog(QDialog):
@widgets.setter @widgets.setter
def widgets(self, widget): def widgets(self, widget):
name = widget.objectName name = widget.objectName()
if name in self.widgets.keys(): if name in self.widgets.keys():
self._widgets[name] = widget self._widgets[name] = widget
@ -218,37 +225,50 @@ class ComparisonDialog(QDialog):
self.canvas.draw() self.canvas.draw()
def plothist(self): def plothist(self):
self.canvas = PlotWidget(self) name = self.sender().objectName()
_axPstd, _axPexp = self.canvas.figure.add_subplot(221), self.canvas.figure.add_subplot(223) if self.widgets[name].isChecked():
_axSstd, _axSexp = self.canvas.figure.add_subplot(222), self.canvas.figure.add_subplot(224) for wname, widget in self.widgets.items():
axes_dict = dict(P=dict(std=_axPstd, exp=_axPexp), if wname != name:
S=dict(std=_axSstd, exp=_axSexp)) self.widgets[wname].setEnabled(False)
bbox_props = dict(boxstyle='round', facecolor='lightgrey', alpha=.7) self.canvas.figure.clf()
for phase in self.phases: _axPstd, _axPexp = self.canvas.figure.add_subplot(221), self.canvas.figure.add_subplot(223)
std = self.data.get_std_array(phase) _axSstd, _axSexp = self.canvas.figure.add_subplot(222), self.canvas.figure.add_subplot(224)
stdxlims = [0., 1.2 * max(std)] axes_dict = dict(P=dict(std=_axPstd, exp=_axPexp),
exp = self.data.get_expectation_array(phase) S=dict(std=_axSstd, exp=_axSexp))
eps_exp = 0.05 * (max(exp) - min(exp)) bbox_props = dict(boxstyle='round', facecolor='lightgrey', alpha=.7)
expxlims = [min(exp) - eps_exp, max(exp) + eps_exp] for phase in self.phases:
axes_dict[phase][std].hist(std, range=stdxlims, bins=20, normed=False) std = self.data.get_std_array(phase)
axes_dict[phase][exp].hist(std, range=expxlims, bins=20, normed=False) stdxlims = [0., 1.2 * max(std)]
std_annotation = "Distribution curve for {phase} differences'\n" \ exp = self.data.get_expectation_array(phase)
"standard deviations (all stations)\n" \ eps_exp = 0.05 * (max(exp) - min(exp))
"number of samples: {nsamples}".format(phase=phase, nsamples=len(std)) expxlims = [min(exp) - eps_exp, max(exp) + eps_exp]
_anno_std = axes_dict[phase][std].annotate(std_annotation, xy=(.05, .8), xycoords='axes fraction') axes_dict[phase]['std'].hist(std, range=stdxlims, bins=20, normed=False)
_anno_std.set_bbox(bbox_props) axes_dict[phase]['exp'].hist(exp, range=expxlims, bins=20,
exp_annotation = "Distribution curve for {phase} differences'\n" \ normed=False)
"expectations (all stations)\n" \ std_annotation = "Distribution curve for {phase} differences'\n" \
"number of samples: {nsamples}".format(phase=phase, nsamples=len(exp)) "standard deviations (all stations)\n" \
_anno_exp = axes_dict[phase][exp].annotate(exp_annotation, xy=(.05, .8), xycoords='axes fraction') "number of samples: {nsamples}".format(phase=phase, nsamples=len(std))
_anno_exp.set_bbox(bbox_props) _anno_std = axes_dict[phase]['std'].annotate(std_annotation, xy=(.05, .8), xycoords='axes fraction')
axes_dict[phase]['exp'].set_xlabel('expectation [s]') _anno_std.set_bbox(bbox_props)
axes_dict[phase]['std'].set_xlabel('standard deviation [s]') exp_annotation = "Distribution curve for {phase} differences'\n" \
"expectations (all stations)\n" \
"number of samples: {nsamples}".format(phase=phase, nsamples=len(exp))
_anno_exp = axes_dict[phase]['exp'].annotate(exp_annotation, xy=(.05, .8), xycoords='axes fraction')
_anno_exp.set_bbox(bbox_props)
axes_dict[phase]['exp'].set_xlabel('expectation [s]')
axes_dict[phase]['std'].set_xlabel('standard deviation [s]')
for ax in axes_dict['P'].values(): for ax in axes_dict['P'].values():
ax.set_ylabel('frequency [-]') ax.set_ylabel('frequency [-]')
self.canvas.draw()
else:
for wname, widget in self.widgets.items():
if wname != name:
self.widgets[wname].setEnabled(True)
self.canvas.figure.clf()
self.plotcomparison()
self.canvas.draw()
class PlotWidget(FigureCanvas): class PlotWidget(FigureCanvas):
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'): def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):