[bugfixes] made some fixes to the subtraction method; in some cases ValueErrors are raised which are now handled but raised as Warning
This commit is contained in:
		
							parent
							
								
									9f7f00314a
								
							
						
					
					
						commit
						db4dd47daa
					
				| @ -1,6 +1,7 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| 
 | 
 | ||||||
|  | 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 | ||||||
| @ -9,6 +10,13 @@ from pylot.core.util.version import get_git_version as _getVersionString | |||||||
| __version__ = _getVersionString() | __version__ = _getVersionString() | ||||||
| __author__ = 'sebastianw' | __author__ = 'sebastianw' | ||||||
| 
 | 
 | ||||||
|  | def broadcast(pdf, si, ei, data): | ||||||
|  |     try: | ||||||
|  |         pdf[si:ei] = data | ||||||
|  |     except ValueError as e: | ||||||
|  |         warnings.warn(str(e), Warning) | ||||||
|  |         return broadcast(pdf, si, ei, data[:-1]) | ||||||
|  |     return pdf | ||||||
| 
 | 
 | ||||||
| def create_axis(x0, incr, npts): | def create_axis(x0, incr, npts): | ||||||
|     ax = np.zeros(npts) |     ax = np.zeros(npts) | ||||||
| @ -16,11 +24,6 @@ def create_axis(x0, incr, npts): | |||||||
|         ax[i] = x0 + incr * i |         ax[i] = x0 + incr * i | ||||||
|     return ax |     return ax | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| def find_nearest_index(array, value): |  | ||||||
|     return (np.abs(array-value)).argmin() |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def gauss_parameter(te, tm, tl, eta): | def gauss_parameter(te, tm, tl, eta): | ||||||
|     ''' |     ''' | ||||||
|     takes three onset times and returns the parameters sig1, sig2, a1 and a2 |     takes three onset times and returns the parameters sig1, sig2, a1 and a2 | ||||||
| @ -265,6 +268,7 @@ class ProbabilityDensityFunction(object): | |||||||
|         plt.plot(self.axis, self.data) |         plt.plot(self.axis, self.data) | ||||||
|         plt.xlabel('x') |         plt.xlabel('x') | ||||||
|         plt.ylabel('f(x)') |         plt.ylabel('f(x)') | ||||||
|  |         plt.autoscale(axis='x', tight=True) | ||||||
|         if self: |         if self: | ||||||
|             plt.title('Probability density function') |             plt.title('Probability density function') | ||||||
|         else: |         else: | ||||||
| @ -346,13 +350,13 @@ class ProbabilityDensityFunction(object): | |||||||
| 
 | 
 | ||||||
|         x = create_axis(x0, incr, npts) |         x = create_axis(x0, incr, npts) | ||||||
| 
 | 
 | ||||||
|         sstart = find_nearest_index(x, self.x0) |         sstart = find_nearest(x, self.x0) | ||||||
|         s_end = sstart + self.data.size |         s_end = sstart + self.data.size | ||||||
|         ostart = find_nearest_index(x, other.x0) |         ostart = find_nearest(x, other.x0) | ||||||
|         o_end = ostart + other.data.size |         o_end = ostart + other.data.size | ||||||
| 
 | 
 | ||||||
|         pdf_self[sstart:s_end] = self.data |         broadcast(pdf_self, sstart, s_end, self.data) | ||||||
|         pdf_other[ostart:o_end] = other.data |         broadcast(pdf_other, ostart, o_end, other.data) | ||||||
| 
 | 
 | ||||||
|         return x0, incr, npts, pdf_self, pdf_other |         return x0, incr, npts, pdf_self, pdf_other | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user