welly
welly copied to clipboard
despike gives type error for samples=True
First of all, splendid work on the open source geoscience toolset. I am trying to characterise a local well, but am running into some troubles while trying to despike the caliper log. Any tips on how to solve it would be more than welcome.
See output below, if needed happy to supply a minimum working example. Even with samples=True, despike fails to despike the curve. Running welly version '0.4.2' and sys.version_info(major=3, minor=7, micro=1, releaselevel='final', serial=0).
TypeError Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\envs\rock\lib\site-packages\welly\curve.py in despike(self, window_length, samples, z) 806 window_length //= 1 if samples else self.step 807 z *= np.nanstd(self) # Transform to curve's units --> 808 curve_sm = self._rolling_window(window_length, np.median) 809 spikes = np.where(np.nan_to_num(self - curve_sm) > z)[0] 810 spukes = np.where(np.nan_to_num(curve_sm - self) > z)[0]
~\AppData\Local\Continuum\anaconda3\envs\rock\lib\site-packages\welly\curve.py in _rolling_window(self, window_length, func1d, step, return_rolled) 783 rolled = np.lib.stride_tricks.as_strided(data, 784 shape=shape, --> 785 strides=strides) 786 result = np.apply_along_axis(func1d, -1, rolled) 787 result[np.isnan(self)] = np.nan
~\AppData\Local\Continuum\anaconda3\envs\rock\lib\site-packages\numpy\lib\stride_tricks.py in as_strided(x, shape, strides, subok, writeable)
101 interface['strides'] = tuple(strides)
102
--> 103 array = np.asarray(DummyArray(interface, base=x))
104 # The route via __interface__
does not preserve structured
105 # dtypes. Since dtype should remain unchanged, we set it explicitly.
~\AppData\Local\Continuum\anaconda3\envs\rock\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order) 536 537 """ --> 538 return array(a, dtype, copy=False, order=order) 539 540
TypeError: 'numpy.float64' object cannot be interpreted as an integer
Hi Peter, thanks for this... I don't have an easy fix I'm afraid. I've never been very satisfied with the despike method on curves -- it seems to just clip spikes, not actually remove them. You might have more luck with a median filter (something like p.data['HGR_edited'].smooth(window_length=10, samples=True, func_1d=np.median)
. Often, the median will remove spikes, but still preserve 'edges' in the curve (unlike a mean smoother).
If that doesn't work, let me know... the other option is trying a convervative filter like this one in bruges
: https://github.com/agile-geoscience/bruges/blob/master/bruges/filters/filters.py#L197-L239
Thanks for the help Matt, I had already given the median filter a try with decent results, and will definitely also look into what the bruges filters have to offer.