ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since d7bb526 was
b699768,
checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago
|
Initial commit of the refactored SasCalc? module.
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[efa5e44] | 1 | """ |
---|
| 2 | Unit tests for fitting module |
---|
| 3 | """ |
---|
| 4 | import unittest |
---|
| 5 | import math |
---|
[b699768] | 6 | from sas.sascalc.fit.BumpsFitting import BumpsFit as Fit |
---|
| 7 | from sas.sascalc.dataloader.loader import Loader |
---|
[efa5e44] | 8 | import bumps.fitters |
---|
| 9 | bumps.fitters.FIT_DEFAULT = 'lm' |
---|
| 10 | |
---|
| 11 | class testFitModule(unittest.TestCase): |
---|
| 12 | """ test fitting """ |
---|
| 13 | def test_cylinder_fit(self): |
---|
| 14 | """ Simple cylinder model fit """ |
---|
| 15 | |
---|
| 16 | out= Loader().load("cyl_400_20.txt") |
---|
| 17 | |
---|
[acf8e4a5] | 18 | fitter = Fit() |
---|
[efa5e44] | 19 | # Receives the type of model for the fitting |
---|
| 20 | from sas.models.CylinderModel import CylinderModel |
---|
| 21 | model = CylinderModel() |
---|
| 22 | model.setParam('sldCyl', 1) |
---|
| 23 | model.setParam('sldSolv', 0) |
---|
| 24 | model.setParam('scale', 1e-10) |
---|
| 25 | |
---|
| 26 | pars1 =['length','radius','scale'] |
---|
| 27 | fitter.set_data(out,1) |
---|
| 28 | fitter.set_model(model,1,pars1, constraints=()) |
---|
| 29 | fitter.select_problem_for_fit(id=1,value=1) |
---|
| 30 | result1, = fitter.fit() |
---|
| 31 | #print result1 |
---|
| 32 | #print result1.__dict__ |
---|
| 33 | |
---|
| 34 | self.assert_(result1) |
---|
| 35 | self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 ) |
---|
| 36 | self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0) |
---|
| 37 | |
---|
| 38 | self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] ) |
---|
| 39 | self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] ) |
---|
| 40 | self.assertTrue( math.fabs(result1.pvec[2]-9.0e-12)/3.0 < result1.stderr[2] ) |
---|
| 41 | self.assertTrue( result1.fitness < 1.0 ) |
---|
| 42 | |
---|
Note: See
TracBrowser
for help on using the repository browser.