Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/pr/invertor.py

    r57e48ca rdbfd307  
    66FIXME: The way the Invertor interacts with its C component should be cleaned up 
    77""" 
    8 from __future__ import division 
    98 
    109import numpy as np 
     
    1817from numpy.linalg import lstsq 
    1918from scipy import optimize 
    20 from sas.sascalc.pr._pr_inversion import Cinvertor 
     19from sas.sascalc.pr.core.pr_inversion import Cinvertor 
    2120 
    2221logger = logging.getLogger(__name__) 
     
    7271        A[j][i] = (Fourier transformed base function for point j) 
    7372 
    74     We then choose a number of r-points, n_r, to evaluate the second 
     73    We them choose a number of r-points, n_r, to evaluate the second 
    7574    derivative of P(r) at. This is used as our regularization term. 
    7675    For a vector r of length n_r, the following n_r rows are set to :: 
     
    145144        x, y, err, d_max, q_min, q_max and alpha 
    146145        """ 
    147         if name == 'x': 
     146        if   name == 'x': 
    148147            if 0.0 in value: 
    149148                msg = "Invertor: one of your q-values is zero. " 
     
    269268            A[i][j] = (Fourier transformed base function for point j) 
    270269 
    271         We then choose a number of r-points, n_r, to evaluate the second 
     270        We them choose a number of r-points, n_r, to evaluate the second 
    272271        derivative of P(r) at. This is used as our regularization term. 
    273272        For a vector r of length n_r, the following n_r rows are set to :: 
     
    417416            A[i][j] = (Fourier transformed base function for point j) 
    418417 
    419         We then choose a number of r-points, n_r, to evaluate the second 
     418        We them choose a number of r-points, n_r, to evaluate the second 
    420419        derivative of P(r) at. This is used as our regularization term. 
    421420        For a vector r of length n_r, the following n_r rows are set to :: 
     
    474473 
    475474        # 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) 
    477478        # Sanity check 
    478479        try: 
     
    497498        try: 
    498499            cov = np.linalg.pinv(inv_cov) 
    499             err = math.fabs(chi2 / (npts - nfunc)) * cov 
    500         except Exception as exc: 
     500            err = math.fabs(chi2 / float(npts - nfunc)) * cov 
     501        except: 
    501502            # We were not able to estimate the errors 
    502503            # Return an empty error matrix 
    503             logger.error(exc) 
     504            logger.error(sys.exc_value) 
    504505 
    505506        # Keep a copy of the last output 
     
    538539 
    539540        """ 
    540         from .num_term import NTermEstimator 
     541        from num_term import NTermEstimator 
    541542        estimator = NTermEstimator(self.clone()) 
    542543        try: 
    543544            return estimator.num_terms(isquit_func) 
    544         except Exception as exc: 
     545        except: 
    545546            # If we fail, estimate alpha and return the default 
    546547            # number of terms 
    547548            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) 
    549550            return self.nfunc, best_alpha, "Could not estimate number of terms" 
    550551 
     
    632633                return best_alpha, message, elapsed 
    633634 
    634         except Exception as exc: 
    635             message = "Invertor.estimate_alpha: %s" % exc 
     635        except: 
     636            message = "Invertor.estimate_alpha: %s" % sys.exc_value 
    636637            return 0, message, elapsed 
    637638 
     
    749750                        self.cov[i][i] = float(toks2[1]) 
    750751 
    751             except Exception as exc: 
    752                 msg = "Invertor.from_file: corrupted file\n%s" % exc 
     752            except: 
     753                msg = "Invertor.from_file: corrupted file\n%s" % sys.exc_value 
    753754                raise RuntimeError(msg) 
    754755        else: 
Note: See TracChangeset for help on using the changeset viewer.