Smoothing without losing array length

311 views Asked by At

I wish to smooth my data without the effects of transients and losing the length of the original data array.

Using the following code I can obtain a smoothing with no array length loss but I get transients at the ends.

import numpy as np

def continuum(y,N):
        return np.convolve(y, np.ones((N,))/N, mode='same')

plt.figure()
plt.errorbar(x1,y1,yerr=err1,zorder=1)
cont = continuum(y1,10)
plt.plot(x1,cont,'r-',zorder=2)

enter image description here

Using the following, I can get smoothing without the transients but it reduces the resulting array length.

def continuum(x,y,N):
        contin = np.convolve(y, np.ones((N,))/N, mode='valid')
        x_new = np.linspace(x[0],x[-1],len(contin))        
        return x_new,contin

plt.figure()
plt.errorbar(x1,y1,yerr=err1,zorder=1)

enter image description here

This is certainly nicer but it means that when I smooth further for continuum subtraction, I won't be able to subtract it from the original data as the array lengths will be different.

Any ideas on how I could combine the two for the best smoothing function?

0

There are 0 answers