[7d8c41f] | 1 | |
---|
[d84a90c] | 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 | ################################################################################ |
---|
[7d8c41f] | 11 | |
---|
| 12 | """ |
---|
[d84a90c] | 13 | Module to explore the P(r) inversion results for a range |
---|
| 14 | of D_max value. User picks a number of points and a range of |
---|
| 15 | distances, then get a series of outputs as a function of D_max |
---|
| 16 | over that range. |
---|
| 17 | """ |
---|
| 18 | |
---|
[7d8c41f] | 19 | import numpy |
---|
| 20 | import math |
---|
| 21 | import sys |
---|
| 22 | |
---|
| 23 | class Results: |
---|
| 24 | """ |
---|
[d84a90c] | 25 | Class to hold the inversion output parameters |
---|
| 26 | as a function of D_max |
---|
[7d8c41f] | 27 | """ |
---|
| 28 | def __init__(self): |
---|
| 29 | """ |
---|
[d84a90c] | 30 | Initialization. Create empty arrays |
---|
| 31 | and dictionary of labels. |
---|
[7d8c41f] | 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 | |
---|
| 45 | class DistExplorer(object): |
---|
| 46 | """ |
---|
[d84a90c] | 47 | The explorer class |
---|
[7d8c41f] | 48 | """ |
---|
| 49 | |
---|
| 50 | def __init__(self, pr_state): |
---|
| 51 | """ |
---|
[d84a90c] | 52 | Initialization. |
---|
| 53 | |
---|
| 54 | :param pr_state: sans.pr.invertor.Invertor object |
---|
| 55 | |
---|
[7d8c41f] | 56 | """ |
---|
| 57 | self.pr_state = pr_state |
---|
[1db4a53] | 58 | self._default_min = 0.8 * self.pr_state.d_max |
---|
| 59 | self._default_max = 1.2 * self.pr_state.d_max |
---|
[7d8c41f] | 60 | |
---|
| 61 | |
---|
| 62 | def __call__(self, dmin=None, dmax=None, npts=10): |
---|
| 63 | """ |
---|
[d84a90c] | 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 | |
---|
[7d8c41f] | 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: |
---|
[e83c75a] | 86 | out, cov = self.pr_state.invert(self.pr_state.nfunc) |
---|
| 87 | |
---|
| 88 | # Store results |
---|
[7d8c41f] | 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 |
---|
[1db4a53] | 105 | msg = "ExploreDialog: inversion failed for " |
---|
| 106 | msg += "D_max=%s\n %s" % (str(d), sys.exc_value) |
---|
| 107 | results.errors.append(msg) |
---|
[7d8c41f] | 108 | |
---|
| 109 | return results |
---|
| 110 | |
---|