[closes #198] comparison dialog now available from QtPyLoT
This commit is contained in:
		
							parent
							
								
									3583f70e2b
								
							
						
					
					
						commit
						b3acef0bcd
					
				| @ -4,7 +4,7 @@ | |||||||
| import warnings | import warnings | ||||||
| import numpy as np | import numpy as np | ||||||
| from obspy import UTCDateTime | from obspy import UTCDateTime | ||||||
| from pylot.core.util.utils import find_nearest | from pylot.core.util.utils import find_nearest, clims | ||||||
| from pylot.core.util.version import get_git_version as _getVersionString | from pylot.core.util.version import get_git_version as _getVersionString | ||||||
| 
 | 
 | ||||||
| __version__ = _getVersionString() | __version__ = _getVersionString() | ||||||
| @ -329,28 +329,14 @@ class ProbabilityDensityFunction(object): | |||||||
|         :param r2: |         :param r2: | ||||||
|         :param max_npts: |         :param max_npts: | ||||||
|         :return: |         :return: | ||||||
| 
 |  | ||||||
|         ''' |         ''' | ||||||
|         # >>> manu = ProbabilityDensityFunction.from_pick(0.01, 0.3, 0.5, 0.54) |  | ||||||
|         # >>> auto = ProbabilityDensityFunction.from_pick(0.01, 0.3, 0.34, 0.54) |  | ||||||
|         # >>> manu.commonlimits(0.01, auto) |  | ||||||
|         # ( |  | ||||||
| 
 | 
 | ||||||
|         l1, r1 = self.limits() |         x0, r = clims(self.limits(), other.limits()) | ||||||
|         l2, r2 = other.limits() |  | ||||||
| 
 |  | ||||||
|         if l1 < l2: |  | ||||||
|             x0 = l1 |  | ||||||
|         else: |  | ||||||
|             x0 = l2 |  | ||||||
| 
 | 
 | ||||||
|         # calculate index for rounding |         # calculate index for rounding | ||||||
|         ri = self.precision(incr) |         ri = self.precision(incr) | ||||||
| 
 | 
 | ||||||
|         if r1 < r2: |         npts = int(round(r - x0, ri) // incr) | ||||||
|             npts = int(round(r2 - x0, ri) // incr) |  | ||||||
|         else: |  | ||||||
|             npts = int(round(r1 - x0, ri) // incr) |  | ||||||
| 
 | 
 | ||||||
|         if npts > max_npts: |         if npts > max_npts: | ||||||
|             raise ValueError('Maximum number of points exceeded:\n' |             raise ValueError('Maximum number of points exceeded:\n' | ||||||
|  | |||||||
| @ -31,6 +31,43 @@ def worker(func, input, cores='max', async=False): | |||||||
|     pool.close() |     pool.close() | ||||||
|     return result |     return result | ||||||
| 
 | 
 | ||||||
|  | def clims(lim1, lim2): | ||||||
|  |     """ | ||||||
|  |     takes two pairs of limits and returns one pair of common limts | ||||||
|  |     :param lim1: | ||||||
|  |     :param lim2: | ||||||
|  |     :return: | ||||||
|  | 
 | ||||||
|  |     >>> clims([0, 4], [1, 3]) | ||||||
|  |     [0, 4] | ||||||
|  |     >>> clims([1, 4], [0, 3]) | ||||||
|  |     [0, 4] | ||||||
|  |     >>> clims([1, 3], [0, 4]) | ||||||
|  |     [0, 4] | ||||||
|  |     >>> clims([0, 3], [1, 4]) | ||||||
|  |     [0, 4] | ||||||
|  |     >>> clims([0, 3], [0, 4]) | ||||||
|  |     [0, 4] | ||||||
|  |     >>> clims([1, 4], [0, 4]) | ||||||
|  |     [0, 4] | ||||||
|  |     >>> clims([0, 4], [0, 4]) | ||||||
|  |     [0, 4] | ||||||
|  |     >>> clims([0, 4], [1, 4]) | ||||||
|  |     [0, 4] | ||||||
|  |     >>> clims([0, 4], [0, 3]) | ||||||
|  |     [0, 4] | ||||||
|  |     """ | ||||||
|  |     lim = [None, None] | ||||||
|  |     if lim1[0] < lim2[0]: | ||||||
|  |         lim[0] = lim1[0] | ||||||
|  |     else: | ||||||
|  |         lim[0] = lim2[0] | ||||||
|  |     if lim1[1] > lim2[1]: | ||||||
|  |         lim[1] = lim1[1] | ||||||
|  |     else: | ||||||
|  |         lim[1] = lim2[1] | ||||||
|  |     return lim | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def demeanTrace(trace, window): | def demeanTrace(trace, window): | ||||||
|     """ |     """ | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ Created on Wed Mar 19 11:27:35 2014 | |||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| import warnings | import warnings | ||||||
|  | import copy | ||||||
| import datetime | import datetime | ||||||
| import numpy as np | import numpy as np | ||||||
| 
 | 
 | ||||||
| @ -32,7 +33,7 @@ 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, \ | ||||||
|     COMPPOSITION_MAP |     COMPPOSITION_MAP | ||||||
| from pylot.core.util.utils import prepTimeAxis, getGlobalTimes, scaleWFData, \ | from pylot.core.util.utils import prepTimeAxis, getGlobalTimes, scaleWFData, \ | ||||||
|     demeanTrace, isSorted, findComboBoxIndex |     demeanTrace, isSorted, findComboBoxIndex, clims | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def getDataType(parent): | def getDataType(parent): | ||||||
| @ -46,6 +47,19 @@ def getDataType(parent): | |||||||
| 
 | 
 | ||||||
|     return type |     return type | ||||||
| 
 | 
 | ||||||
|  | def plot_pdf(_axes, x, y, annotation, bbox_props, xlabel=None, ylabel=None, | ||||||
|  |              title=None): | ||||||
|  |     _axes.plot(x, y) | ||||||
|  |     if title: | ||||||
|  |         _axes.set_title(title) | ||||||
|  |     if xlabel: | ||||||
|  |         _axes.set_xlabel(xlabel) | ||||||
|  |     if ylabel: | ||||||
|  |         _axes.set_ylabel(ylabel) | ||||||
|  |     _anno = _axes.annotate(annotation, xy=(.05, .5), xycoords='axes fraction') | ||||||
|  |     _anno.set_bbox(bbox_props) | ||||||
|  | 
 | ||||||
|  |     return _axes | ||||||
| 
 | 
 | ||||||
| def createAction(parent, text, slot=None, shortcut=None, icon=None, | def createAction(parent, text, slot=None, shortcut=None, icon=None, | ||||||
|                  tip=None, checkable=False): |                  tip=None, checkable=False): | ||||||
| @ -214,55 +228,63 @@ class ComparisonDialog(QDialog): | |||||||
|         _ax1 = self.canvas.figure.add_subplot(_gs[2, 0]) |         _ax1 = self.canvas.figure.add_subplot(_gs[2, 0]) | ||||||
|         _ax2 = self.canvas.figure.add_subplot(_gs[2, 1]) |         _ax2 = self.canvas.figure.add_subplot(_gs[2, 1]) | ||||||
| 
 | 
 | ||||||
|         _axes.cla() |         #_axes.cla() | ||||||
|         station = self.plotprops['station'] |         station = self.plotprops['station'] | ||||||
|         phase = self.plotprops['phase'] |         phase = self.plotprops['phase'] | ||||||
|         pdf = self.data.comparison[station][phase] |         pdf = self.data.comparison[station][phase] | ||||||
|         x, y, std, exp = pdf.axis, pdf.data, pdf.standard_deviation(), \ |         x, y, std, exp = pdf.axis, pdf.data, pdf.standard_deviation(), \ | ||||||
|                          pdf.expectation() |                          pdf.expectation() | ||||||
|         _axes.plot(x, y) | 
 | ||||||
|         _axes.set_title(phase) |  | ||||||
|         _axes.set_ylabel('propability density [-]') |  | ||||||
|         _axes.set_xlabel('time difference [s]') |  | ||||||
|         annotation = "{phase} difference on {station}\n" \ |         annotation = "{phase} difference on {station}\n" \ | ||||||
|                       "expectation: {exp}\n" \ |                      "expectation: {exp}\n" \ | ||||||
|                       "std: {std}".format(station=station, phase=phase, |                      "std: {std}".format(station=station, phase=phase, | ||||||
|                                           std=std, exp=exp) |                                          std=std, exp=exp) | ||||||
|         _anno = _axes.annotate(annotation, xy=(.05, .5), xycoords='axes ' |  | ||||||
|                                                                   'fraction') |  | ||||||
|         bbox_props = dict(boxstyle='round', facecolor='lightgrey', alpha=.7) |         bbox_props = dict(boxstyle='round', facecolor='lightgrey', alpha=.7) | ||||||
|         _anno.set_bbox(bbox_props) |  | ||||||
| 
 | 
 | ||||||
|         pdf_a = self.data.get('auto')[station][phase] |         plot_pdf(_axes, x, y, annotation, bbox_props, 'time difference [s]', | ||||||
|         pdf_m = self.data.get('manu')[station][phase] |                  'propability density [-]', phase) | ||||||
| 
 | 
 | ||||||
|         xauto, yauto, stdauto, expauto = pdf_a.axis, pdf_a.data, \ |         pdf_a = copy.deepcopy(self.data.get('auto')[station][phase]) | ||||||
|                                          pdf_a.standard_deviation(), \ |         pdf_m = copy.deepcopy(self.data.get('manu')[station][phase]) | ||||||
|                                          pdf_a.expectation() |  | ||||||
|         xmanu, ymanu, stdmanu, expmanu = pdf_m.axis, pdf_m.data, \ |  | ||||||
|                                          pdf_m.standard_deviation(), \ |  | ||||||
|                                          pdf_m.expectation() |  | ||||||
| 
 | 
 | ||||||
|         _ax1.plot(xmanu, ymanu) |         xauto, yauto, stdauto, expauto, alim = pdf_a.axis, pdf_a.data, \ | ||||||
|         _ax1.set_xlim(pdf_m.limits()) |                                                pdf_a.standard_deviation(), \ | ||||||
|  |                                                pdf_a.expectation(), \ | ||||||
|  |                                                pdf_a.limits() | ||||||
|  |         xmanu, ymanu, stdmanu, expmanu, mlim = pdf_m.axis, pdf_m.data, \ | ||||||
|  |                                                pdf_m.standard_deviation(), \ | ||||||
|  |                                                pdf_m.expectation(), \ | ||||||
|  |                                                pdf_m.limits() | ||||||
|  |         # find common limits | ||||||
|  |         lims = clims(alim, mlim) | ||||||
|  |         # relative x axis | ||||||
|  |         x0 = lims[0] | ||||||
|  |         xmanu -= x0 | ||||||
|  |         xauto -= x0 | ||||||
|  |         lims = [lim - x0 for lim in lims] | ||||||
|  |         x0 = UTCDateTime(x0) | ||||||
|  | 
 | ||||||
|  |         # set annotation text | ||||||
|         mannotation = "probability density for manual pick\n" \ |         mannotation = "probability density for manual pick\n" \ | ||||||
|                       "expectation: {exp}\n" \ |                       "expectation: {exp}\n" \ | ||||||
|                       "std: {std}".format(std=stdmanu, exp=expmanu) |                       "std: {std}".format(std=stdmanu, | ||||||
|         _anno = _ax1.annotate(mannotation, xy=(.05, .5), xycoords='axes ' |                                           exp=expmanu-x0.timestamp) | ||||||
|                                                                   'fraction') |  | ||||||
|         bbox_props = dict(boxstyle='round', facecolor='lightgrey', alpha=.7) |  | ||||||
|         _anno.set_bbox(bbox_props) |  | ||||||
| 
 | 
 | ||||||
|         _ax2.plot(xauto, yauto) |  | ||||||
|         _ax2.set_xlim(pdf_a.limits()) |  | ||||||
|         _ax2.set_ylabel('time [s]') |  | ||||||
|         aannotation = "probability density for automatic pick\n" \ |         aannotation = "probability density for automatic pick\n" \ | ||||||
|                       "expectation: {exp}\n" \ |                       "expectation: {exp}\n" \ | ||||||
|                       "std: {std}".format(std=stdauto, exp=expauto) |                       "std: {std}".format(std=stdauto, | ||||||
|         _anno = _ax2.annotate(aannotation, xy=(.05, .5), xycoords='axes ' |                                           exp=expauto-x0.timestamp) | ||||||
|                                                                   'fraction') | 
 | ||||||
|         bbox_props = dict(boxstyle='round', facecolor='lightgrey', alpha=.7) |         _ax1 = plot_pdf(_ax1, xmanu, ymanu, mannotation, | ||||||
|         _anno.set_bbox(bbox_props) |                         bbox_props=bbox_props, xlabel='seconds since ' | ||||||
|  |                                                       '{0}'.format(x0), | ||||||
|  |                         ylabel='probability density [-]') | ||||||
|  |         _ax1.set_xlim(lims) | ||||||
|  | 
 | ||||||
|  |         _ax2 = plot_pdf(_ax2, xauto, yauto, aannotation, | ||||||
|  |                         bbox_props=bbox_props, xlabel='seconds since ' | ||||||
|  |                                                       '{0}'.format(x0)) | ||||||
|  |         _ax2.set_xlim(lims) | ||||||
| 
 | 
 | ||||||
|         _gs.update(wspace=0.5, hspace=0.5) |         _gs.update(wspace=0.5, hspace=0.5) | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user