Skip to content
Snippets Groups Projects
Commit 96ae965f authored by Francois POLACK's avatar Francois POLACK
Browse files

feat: Spline_interpolate changed to interpolate and filter either in rows or cols

	Keyword parameter 'rowwise' added. It can take value True or False
parent 109e204e
No related branches found
No related tags found
No related merge requests found
......@@ -190,8 +190,8 @@ def holey_periodogram(data, fs=1.0, window='boxcar', FFTlength=None, detrend='co
return ( np.linspace(0, 0.5*fs, num= N2, endpoint=False), np.square(np.abs(F[:,N2:])/N))
else :
return ( np.linspace((-0.5+1/N)*fs, 0.5*fs, num= N2, endpoint=True), np.square(np.abs(F)/N))
def spline_interpolate(data, window=('tukey', 0.2) ):
'''
def spline_interpolateA(data, window=('tukey', 0.2) ):
windata=data*scipy.signal.get_window(window, data.shape[1])
xbase=np.arange(0., data.shape[1],dtype=float)
outrow=0
......@@ -229,6 +229,64 @@ def spline_interpolate(data, window=('tukey', 0.2) ):
print("output shape", outdata.shape)
return outdata
'''
def spline_interpolate(data, rowwise=True, window=('tukey', 0.2) ):
if rowwise:
segment_size=data.shape[1]
segment_num=data.shape[0]
else:
segment_size=data.shape[0]
segment_num=data.shape[1]
windata=data*scipy.signal.get_window(window, segment_size)
xbase=np.arange(0., segment_size,dtype=float)
index_out=0
invalids=0
outdata=np.ma.empty(dtype=float, shape=data.shape)
for index_in in range(segment_num):
segment=np.ma.array(windata[index_in, :], mask=windata[index_in, :].mask) if rowwise else \
ma.array(windata[:,index_in], mask=windata[:,index_in].mask)
if segment.mask[0]:
segment[0]=0
segment.mask[0]=False
if segment.mask[-1]:
segment[-1]=0
segment.mask[-1]=False
num_invalid=segment[segment.mask].size
if num_invalid :
print (index_in, ":" , num_invalid, "invalid data points")
if num_invalid > 0.2 * segment_size :
print( " too many datapoints, row/col will be skipped from computation")
invalids+=segment_size
continue
invalids+=num_invalid
x=xbase[~ segment.mask]
y=segment[~ segment.mask]
# defining 1st derivative null at ends since Tuckey window was applied (periodic is not working)
spline3=scipy.interpolate.make_interp_spline(x, y, bc_type=([(1, 0.0)], [(1, 0.0)]))
if rowwise:
outdata[index_out,:]=spline3(xbase, extrapolate='periodic')
else:
outdata[:,index_out]=spline3(xbase, extrapolate='periodic')
else:
if rowwise:
outdata[index_out,:]=windata[index_in,:]
else:
outdata[:,index_out]=windata[:,index_in]
index_out+=1
if rowwise:
np.ma.resize(outdata, (index_out,))
else:
np.ma.resize(outdata, (data.shape[0],index_out))
print ("percent of invalid data=", 100*invalids/(data.shape[0]*data.shape[1]) )
print("output shape", outdata.shape)
return outdata
def makePowerList(nx,ny, N):
"""! Create a power list suitable for use with fit2D_poly where
@param nx is the maximum degree in X
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment