source: sasview/pr_inversion/distance_explorer.py @ eb575b0

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

pr_inversion: catch previously uncaught exception when exploring d_max values.

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