Skip to content
Snippets Groups Projects
Commit 6c3670ec authored by David Hoese's avatar David Hoese
Browse files

try it using mean

parent 3b38d844
Branches
No related tags found
No related merge requests found
"""Array filtering functions """Array filtering functions
""" """
from numpy import ndarray, array, diff from numpy import ndarray, array, diff, zeros
from numpy.ma import MaskedArray, masked_array, masked_where from numpy.ma import MaskedArray, masked_array, masked_where, zeros as mzeros
__docformat__ = 'Epytext' __docformat__ = 'Epytext'
__author__ = 'David Hoese' __author__ = 'David Hoese'
...@@ -19,15 +19,23 @@ def filter_arr(arr, threshold, fill_value=None): ...@@ -19,15 +19,23 @@ def filter_arr(arr, threshold, fill_value=None):
@param fill_value: Value to replace the filtered values with (ex. NaN) @param fill_value: Value to replace the filtered values with (ex. NaN)
@type fill_value: anything @type fill_value: anything
""" """
if type.arr != ndarray or type.arr != MaskedArray: if type(arr) != ndarray and type(arr) != MaskedArray:
if fill_value != None: arr = array(arr) if fill_value != None: arr = array(arr)
if fill_value == None: arr = masked_array(arr) if fill_value == None: arr = masked_array(arr)
if fill_value != None: diff_arr = zeros(arr.shape[0]) step = 10
if fill_value == None: diff_arr = ma.zeros(arr.shape[0]) m = zeros(arr.shape[0])
diff_arr[1:] = diff(arr, n=1) for i in range(0, arr.shape[0], step):
for j in range(step):
mean = (arr[i:(i+step)].cumsum()[-1] - arr[i+j])/(step-1)
df = abs(mean - arr[i+j])
if df > threshold: m[i+j] = 1
arr = masked_where(diff_arr >= threshold, arr) #if fill_value != None: diff_arr = zeros(arr.shape[0])
#if fill_value == None: diff_arr = mzeros(arr.shape[0])
#diff_arr[1:] = diff(arr, n=1)
arr = masked_array(data = arr, mask = m)
if fill_value != None: if fill_value != None:
arr.fill_value = fill_value arr.fill_value = fill_value
arr = arr.filled() arr = arr.filled()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment