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

added step parameter

parent 4703235f
Branches
Tags
No related merge requests found
......@@ -7,7 +7,7 @@ __docformat__ = 'Epytext'
__author__ = 'David Hoese'
__version__ = '$Revision: 1.0 $'
def filter_arr(arr, threshold, fill_value=None):
def filter_arr(arr, threshold, fill_value=None, step=10):
"""Filter array arr of values that have a difference from the trend of
threshold. If fill_value is None(default) then a numpy.ma.masked_array will
be returned with the filtered values being masked.
......@@ -18,12 +18,13 @@ def filter_arr(arr, threshold, fill_value=None):
@type threshold: int or float
@param fill_value: Value to replace the filtered values with (ex. NaN)
@type fill_value: anything
@param step: filters step points at a time
@type step: int
"""
if type(arr) != ndarray and type(arr) != MaskedArray:
if fill_value != None: arr = array(arr)
if fill_value == None: arr = masked_array(arr)
step = 10
m = zeros(arr.shape[0])
for i in range(0, arr.shape[0], step):
if arr.shape[0] - i < step: step = arr.shape[0] - i
......@@ -32,10 +33,6 @@ def filter_arr(arr, threshold, fill_value=None):
df = abs(mean - arr[i+j])
if df > threshold: m[i+j] = 1
#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:
arr.fill_value = fill_value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment