add function integration, tests and docs
This commit is contained in:
@@ -1,15 +1,53 @@
|
||||
"""Test of fit module.
|
||||
|
||||
:Date: 2019-05-29
|
||||
|
||||
.. module:: test_fit
|
||||
:platform: *nix, Windows
|
||||
:synopsis: Test of fit module.
|
||||
|
||||
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
|
||||
"""
|
||||
import unittest
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pylab import array, argmax, subplot, plot, title, xlim, show, gradient, linspace
|
||||
sys.path.insert(0, os.path.abspath('../src'))
|
||||
import fit
|
||||
from data import data_read
|
||||
from numerical.fit import gauss_fit
|
||||
|
||||
|
||||
class TestFit(unittest.TestCase):
|
||||
|
||||
def test_property(self):
|
||||
self.assertEqual()
|
||||
def test_gauss(self):
|
||||
"""test function"""
|
||||
file_name = "test_fit.dat"
|
||||
x, y = data_read(file_name, 3, 2)
|
||||
|
||||
subplot(2,2,1)
|
||||
plot(x, y, '.-')
|
||||
|
||||
subplot(2,2,2)
|
||||
dx = x[1] - x[0]
|
||||
dydx = gradient(y, dx) # central differences
|
||||
x_fit = linspace(x[0], x[-1], 150 if len(x) < 50 else len(x)*3)
|
||||
y_fit, popt, FWHM = gauss_fit(list(reversed(x)), list(reversed(dydx)), x_fit=x_fit, verbose=True) # x must increase!
|
||||
plot(x, dydx, '.-')
|
||||
plot(x_fit, y_fit, 'r:')
|
||||
title('FWHM: %f' % FWHM)
|
||||
|
||||
subplot(2,2,3)
|
||||
plot(x, y, '.-')
|
||||
xlim(popt[1]-2*FWHM, popt[1]+2*FWHM)
|
||||
|
||||
subplot(2,2,4)
|
||||
plot(x, dydx, '.-')
|
||||
plot(x_fit, y_fit, 'r:')
|
||||
xlim(popt[1]-2*FWHM, popt[1]+2*FWHM)
|
||||
|
||||
show()
|
||||
self.assertEqual(FWHM, 0.12975107355013618)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user