Skip to content
Snippets Groups Projects
Commit 5f4d7454 authored by ChiWai Chan's avatar ChiWai Chan
Browse files

cbc_template_fir.movingmedian()

- add alternate, faster, implementation using pandas (fall back to current implementation if pandas is not available)
parent 885df3e1
No related branches found
No related tags found
No related merge requests found
......@@ -203,8 +203,15 @@ def compute_autocorrelation_mask( autocorrelation ):
def movingmedian(interval, window_size):
tmp = numpy.copy(interval)
for i in range(window_size, len(interval)-window_size):
tmp[i] = numpy.median(interval[i-window_size:i+window_size])
try:
# pandas version >= 0.18.1 is required
import pandas
s = pandas.Series(tmp)
out = s.rolling(2 * window_size).median()[2 * window_size - 1 : -1]
tmp[window_size : len(interval) - window_size] = numpy.array(out)
except (ImportError, AttributeError):
for i in range(window_size, len(interval) - window_size):
tmp[i] = numpy.median(interval[i - window_size : i + window_size])
return tmp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment