67
67
right=yInterPrime[-1])
70
def average(self,xdata0,ydata0):
71
#check if all the x axis are identical (no interpolation needed)
75
if len(x0) == len(xaxis):
76
if numpy.alltrue(x0==xaxis):
70
def average(self, xarr, yarr, x=None):
72
:param xarr : List containing x values in 1-D numpy arrays
73
:param yarr : List containing y Values in 1-D numpy arrays
74
:param x: x values of the final average spectrum (or None)
75
:return: Average spectrum. In case of invalid input (None, None) tuple is returned.
77
From the spectra given in xarr & yarr, the method determines the overlap in
78
the x-range. For spectra with unequal x-ranges, the method interpolates all
79
spectra on the values given in x if provided or the first curve and averages them.
81
if (len(xarr) != len(yarr)) or\
82
(len(xarr) == 0) or (len(yarr) == 0):
84
print('specAverage -- invalid input!')
85
print('Array lengths do not match or are 0')
97
if numpy.all(x0 == x):
92
ydata.append(numpy.array(ydata0[i]))
95
finalx=numpy.array(x0)
97
finaly=numpy.zeros(finalx.shape ,numpy.float)
110
xdata.append(numpy.take(x,i1))
111
ydata.append(numpy.take(numpy.array(ydata0[i]),i1))
114
#get the max and the min x axis
122
#take the data in between
126
minimumLength = len(xdata[0])
128
i1=numpy.nonzero((x0>=xmin) & (x0<=xmax))[0]
129
x.append(numpy.take(x0,i1))
130
y.append(numpy.take(numpy.array(ydata[i]),i1))
131
if len(x0) < minimumLength:
132
minimumLength = len(x0)
135
if minimumLength < 2:
136
raise ValueError("Not enough points to take a meaningfull average")
137
#take as x axis the first
139
for i in range(len(x)):
140
if x[i][0] > finalx[0]:
142
finaly=numpy.zeros(finalx.shape, numpy.float)
145
for p in range(len(finalx)):
154
i1=max(numpy.nonzero(x0<=point)[0])
155
i2=min(numpy.nonzero(x0>=point)[0])
157
#take the point as it is
161
A=(x0[i2]-point)/(x0[i2]-x0[i1])
163
finaly[p]+=A*y[i][i1]+B*y[i][i2]
169
finaly=finaly[0:]/len(xdata0)
172
finaly=finaly[0:j]/len(xdata0)
108
for (x,y) in zip(xarr, yarr):
109
if numpy.all(numpy.diff(x) > 0.):
115
mask = numpy.argsort(x)
116
xsort.append(x.take(mask))
117
ysort.append(y.take(mask))
125
if (not same) or (not SUPPLIED):
126
# Determine global xmin0 & xmax0
136
print('specAverage -- ')
137
print('No overlap between spectra!')
138
return numpy.array([]), numpy.array([])
140
# Clip xRange to maximal overlap in spectra
141
mask = numpy.nonzero((x0 >= xmin0) &
143
xnew = numpy.take(x0, mask)
144
ynew = numpy.zeros(len(xnew))
147
for (x, y) in zip(xsort, ysort):
151
yinter = numpy.interp(xnew, x, y)
152
ynew += numpy.asarray(yinter)
176
157
def smooth(self, *var, **kw):