I have measured peaks that I want to integrate in a certain range.
The data I want to integrate is in the form of numpy arrays with wavenumbers and intensities:
peakQ1_2500_smoothened =
array([[ 1.95594400e+04, -3.70074342e-17, 3.26000000e+00],
[ 1.95594500e+04, 1.66666667e-03, 4.81500000e+00],
[ 1.95594600e+04, 2.83333333e-02, 4.80833333e+00],
[ 1.95594700e+04, 1.33333333e-02, 4.82166667e+00],
[ 1.95594800e+04, 5.00000000e-03, 4.92416667e+00],
[ 1.95594900e+04, 5.55555556e-04, 4.99305556e+00],
[ 1.95595100e+04, -7.77777778e-03, 5.03972222e+00],
[ 1.95595200e+04, -5.55555556e-03, 4.96888889e+00],
[ 1.95595300e+04, -1.77777778e-02, 4.91333333e+00],
[ 1.95595400e+04, 1.38888889e-02, 4.82500000e+00],
[ 1.95595500e+04, 7.05555556e-02, 4.85722222e+00],
[ 1.95595600e+04, 1.43888889e-01, 4.86638889e+00],
[ 1.95595700e+04, 1.98888889e-01, 4.85138889e+00],
[ 1.95595800e+04, 2.84444444e-01, 4.90694444e+00],
[ 1.95595900e+04, 4.64444444e-01, 4.93611111e+00],
[ 1.95596000e+04, 6.61111111e-01, 4.98166667e+00],
[ 1.95596100e+04, 9.61666667e-01, 4.96722222e+00],
[ 1.95596200e+04, 1.23222222e+00, 4.94388889e+00],
[ 1.95596400e+04, 1.43555556e+00, 5.02166667e+00],
[ 1.95596500e+04, 1.53222222e+00, 5.00500000e+00],
[ 1.95596600e+04, 1.59833333e+00, 5.03666667e+00],
[ 1.95596700e+04, 1.66388889e+00, 4.94555556e+00],
[ 1.95596800e+04, 1.60111111e+00, 4.92777778e+00],
[ 1.95596900e+04, 1.42333333e+00, 4.94666667e+00],
[ 1.95597000e+04, 1.14111111e+00, 5.00777778e+00],
[ 1.95597100e+04, 9.52222222e-01, 5.08555556e+00],
[ 1.95597200e+04, 7.25555556e-01, 5.09222222e+00],
[ 1.95597300e+04, 5.80555556e-01, 5.08055556e+00],
[ 1.95597400e+04, 3.92777778e-01, 5.09611111e+00],
[ 1.95597500e+04, 2.43222222e-01, 5.01655556e+00],
[ 1.95597600e+04, 1.36555556e-01, 4.99822222e+00],
[ 1.95597700e+04, 6.32222222e-02, 4.87044444e+00],
[ 1.95597800e+04, 3.88888889e-02, 4.91944444e+00],
[ 1.95597900e+04, 3.22222222e-02, 4.93611111e+00],
[ 1.95598000e+04, 2.44444444e-02, 5.10277778e+00],
[ 1.95598100e+04, 5.11111111e-02, 5.11277778e+00],
[ 1.95598200e+04, 4.44444444e-02, 5.21944444e+00],
[ 1.95598300e+04, 4.33333333e-02, 5.05333333e+00],
[ 1.95598400e+04, 3.58333333e-02, 5.08750000e+00],
[ 1.95598500e+04, 7.50000000e-03, 5.12750000e+00],
[ 1.95598600e+04, 4.16666667e-03, 5.22916667e+00],
[ 1.95598800e+04, -1.33333333e-02, 3.51000000e+00]])
I found that I can do an integration over the whole array with:
def integratePeak(yvals, xvals):
I = np.trapz(yvals, x = xvals)
return I
But how do I make an integration with x-limits, for example from 19559.52 to 19559.78?
def integratePeak(yvals, xvals, xlower, xupper):
'''integrate y over x from xlower to xupper'''
return I
I could of course give the x- and y-values by explicitly referring to array elements as peakQ1_2500_smoothened[7:33,0]
and peakQ1_2500_smoothened[7:33,1]
but obviously I do not want to refer to array elements but define the integration limits as wavenumbers because the different measured peaks have different array lengths.
Functions for reducing to one data point per wavenumber and then taking a running average:
def averagePerWavenumber(data):
wavenum, intensity, power = data[:,0], data[:,1], data[:,2]
wavenum_unique, intensity_mean = npi.group_by(wavenum).mean(intensity)
wavenum_unique, power_mean = npi.group_by(wavenum).mean(power)
output = np.zeros(shape=(len(wavenum_unique), 3))
output[:,0] = wavenum_unique
output[:,1] = intensity_mean
output[:,2] = power_mean
return output
def smoothening(data, bins):
output = np.zeros(shape=(len(data[:,0]), 3))
output[:,0] = data[:,0]
output[:,1] = np.convolve(data[:,1], np.ones(bins), mode='same') / bins
output[:,2] = np.convolve(data[:,2], np.ones(bins), mode='same') / bins
return output
peakQ1_2500_smoothened[7:33,0] and peakQ1_2500_smoothened[7:33,1]
with a variablepeakQ1_2500_smoothened[start:end, 0]
.