1 | """ |
---|
2 | Implementation of the use-case from a usage perspective. |
---|
3 | """ |
---|
4 | |
---|
5 | import unittest |
---|
6 | import numpy |
---|
7 | from DataLoader.loader import Loader |
---|
8 | from sans.invariant import invariant |
---|
9 | from sans.invariant.invariant_mapper import InvariantMapper |
---|
10 | |
---|
11 | N_INVARIANT = 10 |
---|
12 | CONTRAST = 2.6e-6 |
---|
13 | POROD_CONSTANT = 2.0 |
---|
14 | |
---|
15 | class TestInvPolySphere(unittest.TestCase): |
---|
16 | """ |
---|
17 | Test iteration through unsmeared data for invariant computation |
---|
18 | """ |
---|
19 | def setUp(self): |
---|
20 | self.list_of_invariant = [] |
---|
21 | self.list_of_contrast = [] |
---|
22 | self.list_of_porod_const = [] |
---|
23 | #Define an invariant mapper |
---|
24 | self.mapper = InvariantMapper() |
---|
25 | for i in range(N_INVARIANT): |
---|
26 | data = Loader().load("PolySpheres.txt") |
---|
27 | # Create invariant object. Background and scale left as defaults. |
---|
28 | inv = invariant.InvariantCalculator(data=data) |
---|
29 | self.list_of_invariant.append(inv) |
---|
30 | self.list_of_contrast.append(CONTRAST) |
---|
31 | self.list_of_porod_const.append(POROD_CONSTANT) |
---|
32 | |
---|
33 | def test_use_case_1(self): |
---|
34 | """ |
---|
35 | Invariant without extrapolation |
---|
36 | """ |
---|
37 | qstar_list = map(self.mapper.get_qstar, self.list_of_invariant) |
---|
38 | |
---|
39 | for qstar in qstar_list: |
---|
40 | self.assertAlmostEquals(qstar, 7.48959e-5, 2) |
---|
41 | |
---|
42 | v_list = map(self.mapper.get_volume_fraction_with_error, |
---|
43 | self.list_of_invariant, self.list_of_contrast) |
---|
44 | for v, dv in v_list: |
---|
45 | self.assertAlmostEquals(v, 0.005644689, 4) |
---|
46 | |
---|
47 | s_list = map(self.mapper.get_surface_with_error, |
---|
48 | self.list_of_invariant, |
---|
49 | self.list_of_contrast, |
---|
50 | self.list_of_porod_const) |
---|
51 | for s, ds in s_list: |
---|
52 | self.assertAlmostEquals(s , 941.7452, 3) |
---|
53 | |
---|
54 | |
---|