Created
November 2, 2017 15:59
-
-
Save daguiam/1046aed15358d7f7550ec23964001342 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Calculate mean std of clipped array""" | |
import numpy as np | |
from scipy import interpolate | |
def calc_func_clipped(X, Y, func=np.mean, npoints=None, verbose=False): | |
""" Calculates func of Y values, where Y is clipped to the longest continuous | |
values of X to prevent aliasing | |
""" | |
# Size of each data vector | |
npoints = npoints or Y.shape[1] | |
# Finding consecutive value measurements | |
xmax = np.inf | |
xmin = -np.inf | |
for x in X: | |
if x.max() < xmax: | |
xmax = x.max() | |
if x.min() > xmin: | |
xmin = x.min() | |
if verbose: | |
print 'Clipped to:', xmin,xmax | |
# Clipping data | |
newx = np.linspace(xmin, xmax, npoints) | |
newy = [] | |
for x,y in zip(X,Y): | |
valid_idx = (x>xmin)*(x<xmax) | |
f = interpolate.interp1d(x,y) | |
yi = f(newx) | |
newy.append(yi) | |
if verbose: | |
print newy | |
# Calculating function | |
newy = np.array(newy) | |
newy = func(newy, axis=0) | |
return newx, newy | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment