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

half way there

parent 0650fd88
No related branches found
No related tags found
No related merge requests found
"""Array filtering functions
"""
from numpy import ndarray, array, diff
from numpy.ma import MaskedArray, masked_array
__docformat__ = 'Epytext'
__author__ = 'David Hoese'
__version__ = '$Revision: 1.0 $'
def filter_arr(arr, threshold, fill_value=None):
"""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.
@param arr: array to be filtered
@type arr: array or list
@param threshold: allowable change between values
@type threshold: int or float
@param fill_value: Value to replace the filtered values with (ex. NaN)
@type fill_value: anything
"""
if type.arr != ndarray or type.arr != MaskedArray:
if fill_value != None: arr = array(arr)
if fill_value == None: arr = masked_array(arr)
diff_arr = diff(arr, n=1)
if fill_value == None: arr = masked_where(diff_arr >= threshold, arr)
return arr
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment