source: sasview/pr_inversion/distance_explorer.py @ 3cd5806

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 3cd5806 was 1db4a53, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on pylint

  • Property mode set to 100644
File size: 3.5 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"""
18
19import numpy
20import math
21import sys
22
23class Results:
24    """
25    Class to hold the inversion output parameters
26    as a function of D_max
27    """
28    def __init__(self):
29        """
30        Initialization. Create empty arrays
31        and dictionary of labels.
32        """
33        # Array of output for each inversion
34        self.chi2 = []
35        self.osc = []
36        self.pos = []
37        self.pos_err = []
38        self.rg = []
39        self.iq0 = []
40        self.bck = []
41        self.d_max = []
42        ## List of errors found during the last exploration       
43        self.errors = []
44       
45class DistExplorer(object):
46    """
47    The explorer class
48    """
49   
50    def __init__(self, pr_state):
51        """
52        Initialization.
53       
54        :param pr_state: sans.pr.invertor.Invertor object
55       
56        """
57        self.pr_state  = pr_state
58        self._default_min = 0.8 * self.pr_state.d_max
59        self._default_max = 1.2 * self.pr_state.d_max
60
61       
62    def __call__(self, dmin=None, dmax=None, npts=10):
63        """
64        Compute the outputs as a function of D_max.
65       
66        :param dmin: minimum value for D_max
67        :param dmax: maximum value for D_max
68        :param npts: number of points for D_max
69       
70        """
71        # Take care of the defaults if needed
72        if dmin is None:
73            dmin = self._default_min
74           
75        if dmax is None:
76            dmax = self._default_max
77           
78        # Results object to store the computation outputs.
79        results = Results()
80       
81        # Loop over d_max values
82        for i in range(npts):   
83            d = dmin + i * (dmax - dmin)/(npts-1.0)
84            self.pr_state.d_max = d
85            try:
86                out, cov = self.pr_state.invert(self.pr_state.nfunc)   
87           
88                # Store results
89                iq0 = self.pr_state.iq0(out)
90                rg = self.pr_state.rg(out)
91                pos = self.pr_state.get_positive(out)
92                pos_err = self.pr_state.get_pos_err(out, cov)
93                osc = self.pr_state.oscillations(out)
94           
95                results.d_max.append(self.pr_state.d_max)
96                results.bck.append(self.pr_state.background)
97                results.chi2.append(self.pr_state.chi2)
98                results.iq0.append(iq0)
99                results.rg.append(rg)
100                results.pos.append(pos)
101                results.pos_err.append(pos_err)
102                results.osc.append(osc)           
103            except:
104                # This inversion failed, skip this D_max value
105                msg = "ExploreDialog: inversion failed for "
106                msg += "D_max=%s\n %s" % (str(d), sys.exc_value)
107                results.errors.append(msg)
108           
109        return results
110       
Note: See TracBrowser for help on using the repository browser.