Changes in src/sas/sascalc/pr/invertor.py [57e48ca:dbfd307] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/pr/invertor.py
r57e48ca rdbfd307 6 6 FIXME: The way the Invertor interacts with its C component should be cleaned up 7 7 """ 8 from __future__ import division9 8 10 9 import numpy as np … … 18 17 from numpy.linalg import lstsq 19 18 from scipy import optimize 20 from sas.sascalc.pr. _pr_inversion import Cinvertor19 from sas.sascalc.pr.core.pr_inversion import Cinvertor 21 20 22 21 logger = logging.getLogger(__name__) … … 72 71 A[j][i] = (Fourier transformed base function for point j) 73 72 74 We the nchoose a number of r-points, n_r, to evaluate the second73 We them choose a number of r-points, n_r, to evaluate the second 75 74 derivative of P(r) at. This is used as our regularization term. 76 75 For a vector r of length n_r, the following n_r rows are set to :: … … 145 144 x, y, err, d_max, q_min, q_max and alpha 146 145 """ 147 if name == 'x':146 if name == 'x': 148 147 if 0.0 in value: 149 148 msg = "Invertor: one of your q-values is zero. " … … 269 268 A[i][j] = (Fourier transformed base function for point j) 270 269 271 We the nchoose a number of r-points, n_r, to evaluate the second270 We them choose a number of r-points, n_r, to evaluate the second 272 271 derivative of P(r) at. This is used as our regularization term. 273 272 For a vector r of length n_r, the following n_r rows are set to :: … … 417 416 A[i][j] = (Fourier transformed base function for point j) 418 417 419 We the nchoose a number of r-points, n_r, to evaluate the second418 We them choose a number of r-points, n_r, to evaluate the second 420 419 derivative of P(r) at. This is used as our regularization term. 421 420 For a vector r of length n_r, the following n_r rows are set to :: … … 474 473 475 474 # Perform the inversion (least square fit) 476 c, chi2, _, _ = lstsq(a, b, rcond=-1) 475 # CRUFT: numpy>=1.14.0 allows rcond=None for the following default 476 rcond = np.finfo(float).eps * max(a.shape) 477 c, chi2, _, _ = lstsq(a, b, rcond=rcond) 477 478 # Sanity check 478 479 try: … … 497 498 try: 498 499 cov = np.linalg.pinv(inv_cov) 499 err = math.fabs(chi2 / (npts - nfunc)) * cov500 except Exception as exc:500 err = math.fabs(chi2 / float(npts - nfunc)) * cov 501 except: 501 502 # We were not able to estimate the errors 502 503 # Return an empty error matrix 503 logger.error( exc)504 logger.error(sys.exc_value) 504 505 505 506 # Keep a copy of the last output … … 538 539 539 540 """ 540 from .num_term import NTermEstimator541 from num_term import NTermEstimator 541 542 estimator = NTermEstimator(self.clone()) 542 543 try: 543 544 return estimator.num_terms(isquit_func) 544 except Exception as exc:545 except: 545 546 # If we fail, estimate alpha and return the default 546 547 # number of terms 547 548 best_alpha, _, _ = self.estimate_alpha(self.nfunc) 548 logger.warning("Invertor.estimate_numterms: %s" % exc)549 logger.warning("Invertor.estimate_numterms: %s" % sys.exc_value) 549 550 return self.nfunc, best_alpha, "Could not estimate number of terms" 550 551 … … 632 633 return best_alpha, message, elapsed 633 634 634 except Exception as exc:635 message = "Invertor.estimate_alpha: %s" % exc635 except: 636 message = "Invertor.estimate_alpha: %s" % sys.exc_value 636 637 return 0, message, elapsed 637 638 … … 749 750 self.cov[i][i] = float(toks2[1]) 750 751 751 except Exception as exc:752 msg = "Invertor.from_file: corrupted file\n%s" % exc752 except: 753 msg = "Invertor.from_file: corrupted file\n%s" % sys.exc_value 753 754 raise RuntimeError(msg) 754 755 else:
Note: See TracChangeset
for help on using the changeset viewer.