Fits peaks to IR spectra with noise and many peaks
In [6]:
%matplotlib inline
from __future__ import division
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
sys.path.append('..')
from spectra import getxy, find_peaks, fit_data, output_results, copy_range
In [8]:
x1, y1 = getxy('../tests/data/ir.txt')
plt.plot(x1, y1,'r-')
Out[8]:
In [16]:
x, y2 = copy_range(x1, y1, 1730,1860)
y = y2 - min(y2)
plt.plot(x, y,'r-')
print len(x), len(y)
In [19]:
peak_pos = find_peaks(x, y, width=4, threshold=2)
plt.plot(x, y, 'b-', x[peak_pos], y[peak_pos], 'oy')
Out[19]:
In [20]:
out1 = fit_data(x, y, peak_pos, bg_ord=2)
In [21]:
output_results(out1)
Out[21]:
In [23]:
plt.plot(x, y, 'r-', x, out1.init_fit, 'b-')
Out[23]:
In [24]:
plt.plot(x, y, 'r-', x, out1.best_fit, 'b-')
Out[24]: