source: sasview/src/sas/sascalc/pr/distance_explorer.py @ 2760662

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2760662 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: 3.3 KB
Line 
1
2################################################################################
3#This software was developed by the University of Tennessee as part of the
4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
5#project funded by the US National Science Foundation.
6#
7#See the license text in license.txt
8#
9#copyright 2009, University of Tennessee
10################################################################################
11
12"""
13Module to explore the P(r) inversion results for a range
14of D_max value. User picks a number of points and a range of
15distances, then get a series of outputs as a function of D_max
16over that range.
17"""
18import sys
19
20
21class Results(object):
22    """
23    Class to hold the inversion output parameters
24    as a function of D_max
25    """
26    def __init__(self):
27        """
28        Initialization. Create empty arrays
29        and dictionary of labels.
30        """
31        # Array of output for each inversion
32        self.chi2 = []
33        self.osc = []
34        self.pos = []
35        self.pos_err = []
36        self.rg = []
37        self.iq0 = []
38        self.bck = []
39        self.d_max = []
40        ## List of errors found during the last exploration
41        self.errors = []
42
43
44class DistExplorer(object):
45    """
46    The explorer class
47    """
48
49    def __init__(self, pr_state):
50        """
51        Initialization.
52
53        :param pr_state: sas.sascalc.pr.invertor.Invertor object
54
55        """
56        self.pr_state = pr_state
57        self._default_min = 0.8 * self.pr_state.d_max
58        self._default_max = 1.2 * self.pr_state.d_max
59
60    def __call__(self, dmin=None, dmax=None, npts=10):
61        """
62        Compute the outputs as a function of D_max.
63
64        :param dmin: minimum value for D_max
65        :param dmax: maximum value for D_max
66        :param npts: number of points for D_max
67
68        """
69        # Take care of the defaults if needed
70        if dmin is None:
71            dmin = self._default_min
72
73        if dmax is None:
74            dmax = self._default_max
75
76        # Results object to store the computation outputs.
77        results = Results()
78
79        # Loop over d_max values
80        for i in range(npts):
81            d = dmin + i * (dmax - dmin) / (npts - 1.0)
82            self.pr_state.d_max = d
83            try:
84                out, cov = self.pr_state.invert(self.pr_state.nfunc)
85
86                # Store results
87                iq0 = self.pr_state.iq0(out)
88                rg = self.pr_state.rg(out)
89                pos = self.pr_state.get_positive(out)
90                pos_err = self.pr_state.get_pos_err(out, cov)
91                osc = self.pr_state.oscillations(out)
92
93                results.d_max.append(self.pr_state.d_max)
94                results.bck.append(self.pr_state.background)
95                results.chi2.append(self.pr_state.chi2)
96                results.iq0.append(iq0)
97                results.rg.append(rg)
98                results.pos.append(pos)
99                results.pos_err.append(pos_err)
100                results.osc.append(osc)
101            except:
102                # This inversion failed, skip this D_max value
103                msg = "ExploreDialog: inversion failed for "
104                msg += "D_max=%s\n %s" % (str(d), sys.exc_value)
105                results.errors.append(msg)
106
107        return results
Note: See TracBrowser for help on using the repository browser.