source: sasview/Invariant/test/utest_use_cases.py @ 2733188

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 2733188 was b6666d4, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

invariant: added comments to API and usage examples

  • Property mode set to 100644
File size: 6.0 KB
Line 
1"""
2   Implementation of the use-case from a usage perspective.
3   TODO: check the return values to perform actual unit testing.
4"""
5import unittest
6from DataLoader.loader import  Loader
7from sans.invariant import invariant
8
9
10class TestInvPolySphere(unittest.TestCase):
11    """
12        Test unsmeared data for invariant computation
13    """
14    def setUp(self):
15        self.data = Loader().load("PolySpheres.txt")
16       
17    def test_use_case_1(self):
18        """
19            Invariant without extrapolation
20        """
21        # Create invariant object. Background and scale left as defaults.
22        inv = invariant.InvariantCalculator(data=self.data)
23       
24        # We have to be able to tell the InvariantCalculator whether we want the
25        # extrapolation or not. By default, when the user doesn't specify, we
26        # should compute Q* without extrapolation. That's what should be done in __init__.
27       
28        # We call get_qstar() with no argument, which signifies that we do NOT
29        # want extrapolation.
30        qstar = inv.get_qstar()
31       
32        # The volume fraction and surface use Q*. That means that the following
33        # methods should check that Q* has been computed. If not, it should
34        # compute it by calling get_qstare(), leaving the parameters as default.
35        volume_fraction = inv.get_volume_fraction(contrast=1.0)
36        surface         = inv.get_surface(contrast=1.0, porod_const=1.0)
37       
38    def test_use_case_2(self):
39        """
40            Invariant without extrapolation. Invariant, volume fraction and surface
41            are given with errors.
42        """
43        # Create invariant object. Background and scale left as defaults.
44        inv = invariant.InvariantCalculator(data=self.data)
45       
46        # Get the invariant with errors
47        qstar, qstar_err = inv.get_qstar_with_error()
48        v, dv            = inv.get_volume_fraction_with_error(contrast=1.0)
49        s, ds            = inv.get_surface_with_error(contrast=1.0, porod_const=1.0)
50       
51    def test_use_case_3(self):
52        """
53            Invariant with low-Q extrapolation
54        """
55        # Create invariant object. Background and scale left as defaults.
56        inv = invariant.InvariantCalculator(data=self.data)
57       
58        # Set the extrapolation parameters for the low-Q range
59       
60        # The npts parameter should have a good default.
61        # The range parameter should be 'high' or 'low'
62        # The function parameter should default to None. If it is None,
63        #    the method should pick a good default (Guinier at low-Q and 1/q^4 at high-Q).
64        #    The method should also check for consistency of the extrapolate and function
65        #    parameters. For instance, you might not want to allow 'high' and 'guinier'.
66        # The power parameter (not shown below) should default to 4.
67        inv.set_extraplotation(range='low', npts=5, function='guinier')
68       
69        # The version of the call without error
70        # At this point, we could still compute Q* without extrapolation by calling
71        # get_qstar with arguments, or with extrapolate=None.
72        qstar = inv.get_qstar(extrapolate='low')
73       
74        # The version of the call with error
75        qstar, qstar_err = inv.get_qstar_with_error(extrapolate='low')
76
77        # Get the volume fraction and surface
78        v, dv            = inv.get_volume_fraction_with_error(contrast=1.0)
79        s, ds            = inv.get_surface_with_error(contrast=1.0, porod_const=1.0)
80       
81    def test_use_case_4(self):
82        """
83            Invariant with high-Q extrapolation
84        """
85        # Create invariant object. Background and scale left as defaults.
86        inv = invariant.InvariantCalculator(data=self.data)
87       
88
89        # Set the extrapolation parameters for the high-Q range
90       
91        # The npts parameter should have a good default.
92        # The range parameter should be 'high' or 'low'. Those should be stored separately.
93        # The function parameter should default to None. If it is None,
94        #    the method should pick a good default (Guinier at low-Q and 1/q^4 at high-Q).
95        #    The method should also check for consistency of the extrapolate and function
96        #    parameters. For instance, you might not want to allow 'high' and 'guinier'.
97        # The power parameter should default to 4.
98        inv.set_extraplotation(range='high', npts=5, function='power_law', power=4)
99       
100       
101        # The version of the call without error
102        # The function parameter defaults to None, then is picked to be 'power_law' for extrapolate='high'
103        qstar = inv.get_qstar(extrapolate='high')
104       
105        # The version of the call with error
106        qstar, qstar_err = inv.get_qstar_with_error(extrapolate='high')
107
108        # Get the volume fraction and surface
109        v, dv            = inv.get_volume_fraction_with_error(contrast=1.0)
110        s, ds            = inv.get_surface_with_error(contrast=1.0, porod_const=1.0)
111       
112    def test_use_case_5(self):
113        """
114            Invariant with both high- and low-Q extrapolation
115        """
116        # Create invariant object. Background and scale left as defaults.
117        inv = invariant.InvariantCalculator(data=self.data)
118       
119        # Set the extrapolation parameters for the low- and high-Q ranges
120        inv.set_extraplotation(range='low', npts=5, function='guinier')
121        inv.set_extraplotation(range='high', npts=5, function='power_law', power=4)
122       
123        # The version of the call without error
124        # The function parameter defaults to None, then is picked to be 'power_law' for extrapolate='high'
125        qstar = inv.get_qstar(extrapolate='both')
126       
127        # The version of the call with error
128        qstar, qstar_err = inv.get_qstar_with_error(extrapolate='both')
129
130        # Get the volume fraction and surface
131        v, dv            = inv.get_volume_fraction_with_error(contrast=1.0)
132        s, ds            = inv.get_surface_with_error(contrast=1.0, porod_const=1.0)
133       
134               
Note: See TracBrowser for help on using the repository browser.