Testing out background and peak fitting on Raman data with strong background

Background finding/subtracting not implemented yet

Fitting fails due to very strong background


In [1]:
%matplotlib inline
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

In [2]:
x, y = getxy(os.path.join('..', 'tests', 'data', 'raman-785nm.txt'))
plt.plot(x, y)


Out[2]:
[<matplotlib.lines.Line2D at 0x7f911cc40990>]

In [3]:
# To implement
#
# find_background(cutoff=1.0/1000,order=2)
# plt.plot(x, bg, 'b-')

In [4]:
peak_pos = find_peaks(x, y, width=5, threshold=5, limit=20)
plt.plot(x, y, 'b-', x[peak_pos], y[peak_pos], 'ro')


Out[4]:
[<matplotlib.lines.Line2D at 0x7f911cbc4990>,
 <matplotlib.lines.Line2D at 0x7f911cbc4b90>]

In [5]:
out1 = fit_data(x, y, peak_pos)

In [6]:
plt.plot(x, y, 'b-', x, out1.best_fit, 'r-')


Out[6]:
[<matplotlib.lines.Line2D at 0x7f911c975110>,
 <matplotlib.lines.Line2D at 0x7f911c975310>]

In [7]:
output_results(out1)


Out[7]:
array([['bg_c0', '241212.031079', 'nan'],
       ['bg_c1', '247.447799566', '12663757.2835'],
       ['bg_c2', '-0.275300297714', '2567.26350473'],
       ['p0_x0', '1515.61975493', '2321.5641551'],
       ['p0_amp', '260533.771309', '32822963.199'],
       ['p0_fwhm', '-878.631499314', '17123.2156042'],
       ['p1_x0', '-192.971945894', '166183.627559'],
       ['p1_amp', '-5752034.71973', '8277542697.92'],
       ['p1_fwhm', '-405.566282149', '169381.888193'],
       ['p2_x0', '2532.99667926', '199199539.531'],
       ['p2_amp', '-187378.694401', '13219935831.8'],
       ['p2_fwhm', '-3243.64356445', 'nan'],
       ['p3_x0', '58.4908680974', '8435.29544275'],
       ['p3_amp', '1376670.23405', '369952306.762'],
       ['p3_fwhm', '-457.9235394', '11183.6410447'],
       ['p4_x0', '1849.54258734', '24901356.9196'],
       ['p4_amp', '477298.608008', 'nan'],
       ['p4_fwhm', '-3183.46593875', 'nan'],
       ['p5_x0', '717.126410169', 'nan'],
       ['p5_amp', '-76918.1416425', '8359534424.84'],
       ['p5_fwhm', '-3232.90865317', '118554392.339'],
       ['p6_x0', '-1854.06047412', '93771067.3586'],
       ['p6_amp', '1025268.66731', '12859376055.0'],
       ['p6_fwhm', '-3244.51955019', '10525355339.1'],
       ['p7_x0', '4408.35249202', '605997691.169'],
       ['p7_amp', '398925.058615', '38193534448.3'],
       ['p7_fwhm', '-2174.18581162', 'nan'],
       ['p8_x0', '-1942.07576808', '184751929.218'],
       ['p8_amp', '-1407279.78534', '141037815665.0'],
       ['p8_fwhm', '-574.441064707', '299081700.384'],
       ['p9_x0', '2114.27065766', 'nan'],
       ['p9_amp', '1394719.12427', 'nan'],
       ['p9_fwhm', '-1041.18176415', 'nan'],
       ['p10_x0', '2328.5948078', 'nan'],
       ['p10_amp', '-1440382.68019', 'nan'],
       ['p10_fwhm', '-2842.17429138', 'nan'],
       ['p11_x0', '3031.37780655', '53391631.9222'],
       ['p11_amp', '-2827895.98717', '657612488087.0'],
       ['p11_fwhm', '-439.489565168', '76310833.2209'],
       ['p12_x0', '3189.29688208', '55059891.4446'],
       ['p12_amp', '-633105.522884', 'nan'],
       ['p12_fwhm', '-3015.50846234', 'nan'],
       ['p13_x0', '2876.36791068', '58786194.8669'],
       ['p13_amp', '-723179.698985', '35221544152.7'],
       ['p13_fwhm', '-3244.18326058', 'nan'],
       ['p14_x0', '-3646.07798706', '961117486.752'],
       ['p14_amp', '-956400.593591', '251714670042.0'],
       ['p14_fwhm', '-405.56944422', '282445863.358'],
       ['p15_x0', '-6836.84683288', '1642495783.47'],
       ['p15_amp', '-30816.5029236', '7637491142.66'],
       ['p15_fwhm', '-1560.10107911', '15954056387.1'],
       ['p16_x0', '19628.1714754', '5175002508.65'],
       ['p16_amp', '-836250.364711', '223067956657.0'],
       ['p16_fwhm', '-405.565042029', '4618621537.3'],
       ['p17_x0', '-4160.88127028', '1049979479.36'],
       ['p17_amp', '-2158450.75213', '525640233440.0'],
       ['p17_fwhm', '-411.213307259', '1561961621.46'],
       ['p18_x0', '-10530.3995665', '2707777993.52'],
       ['p18_amp', '-2151565.10359', '531617025295.0'],
       ['p18_fwhm', '-408.538596936', '2751910367.81'],
       ['p19_x0', '5421.9968495', 'nan'],
       ['p19_amp', '6967652.21472', 'nan'],
       ['p19_fwhm', '-2935.89851531', 'nan']], 
      dtype='|S15')