Skip to content
Snippets Groups Projects
Commit 51b193b6 authored by Peter Swain's avatar Peter Swain
Browse files

fix(butterfilter): robustly deals with NaN now

parent 33ec71c6
No related branches found
No related tags found
No related merge requests found
......@@ -24,5 +24,14 @@ def butterfilter(timeseries, params=None):
timeseries_norm = timeseries - np.nanmean(timeseries, axis=1).reshape(
timeseries.shape[0], 1
)
filtered_timeseries = signal.sosfiltfilt(sos, timeseries_norm, axis=1)
if np.any(np.isnan(timeseries_norm)):
# filter one at a time because of NaNs at different times
filtered_timeseries = np.nan * np.ones(timeseries_norm.shape)
for i in range(timeseries_norm.shape[0]):
data = timeseries_norm[i, :]
filtered = signal.sosfiltfilt(sos, data[~np.isnan(data)])
filtered_timeseries[i, ~np.isnan(data)] = filtered
else:
# filter all at once
filtered_timeseries = signal.sosfiltfilt(sos, timeseries_norm, axis=1)
return filtered_timeseries
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