Ignore:
File:
1 edited

Legend:

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

    r2469df7 r57e48ca  
    66FIXME: The way the Invertor interacts with its C component should be cleaned up 
    77""" 
     8from __future__ import division 
    89 
    910import numpy as np 
     
    1718from numpy.linalg import lstsq 
    1819from scipy import optimize 
    19 from sas.sascalc.pr.core.pr_inversion import Cinvertor 
     20from sas.sascalc.pr._pr_inversion import Cinvertor 
    2021 
    2122logger = logging.getLogger(__name__) 
     
    7172        A[j][i] = (Fourier transformed base function for point j) 
    7273 
    73     We them choose a number of r-points, n_r, to evaluate the second 
     74    We then choose a number of r-points, n_r, to evaluate the second 
    7475    derivative of P(r) at. This is used as our regularization term. 
    7576    For a vector r of length n_r, the following n_r rows are set to :: 
     
    144145        x, y, err, d_max, q_min, q_max and alpha 
    145146        """ 
    146         if   name == 'x': 
     147        if name == 'x': 
    147148            if 0.0 in value: 
    148149                msg = "Invertor: one of your q-values is zero. " 
     
    268269            A[i][j] = (Fourier transformed base function for point j) 
    269270 
    270         We them choose a number of r-points, n_r, to evaluate the second 
     271        We then choose a number of r-points, n_r, to evaluate the second 
    271272        derivative of P(r) at. This is used as our regularization term. 
    272273        For a vector r of length n_r, the following n_r rows are set to :: 
     
    416417            A[i][j] = (Fourier transformed base function for point j) 
    417418 
    418         We them choose a number of r-points, n_r, to evaluate the second 
     419        We then choose a number of r-points, n_r, to evaluate the second 
    419420        derivative of P(r) at. This is used as our regularization term. 
    420421        For a vector r of length n_r, the following n_r rows are set to :: 
     
    473474 
    474475        # Perform the inversion (least square fit) 
    475         c, chi2, _, _ = lstsq(a, b) 
     476        c, chi2, _, _ = lstsq(a, b, rcond=-1) 
    476477        # Sanity check 
    477478        try: 
     
    496497        try: 
    497498            cov = np.linalg.pinv(inv_cov) 
    498             err = math.fabs(chi2 / float(npts - nfunc)) * cov 
    499         except: 
     499            err = math.fabs(chi2 / (npts - nfunc)) * cov 
     500        except Exception as exc: 
    500501            # We were not able to estimate the errors 
    501502            # Return an empty error matrix 
    502             logger.error(sys.exc_value) 
     503            logger.error(exc) 
    503504 
    504505        # Keep a copy of the last output 
     
    537538 
    538539        """ 
    539         from num_term import NTermEstimator 
     540        from .num_term import NTermEstimator 
    540541        estimator = NTermEstimator(self.clone()) 
    541542        try: 
    542543            return estimator.num_terms(isquit_func) 
    543         except: 
     544        except Exception as exc: 
    544545            # If we fail, estimate alpha and return the default 
    545546            # number of terms 
    546547            best_alpha, _, _ = self.estimate_alpha(self.nfunc) 
    547             logger.warning("Invertor.estimate_numterms: %s" % sys.exc_value) 
     548            logger.warning("Invertor.estimate_numterms: %s" % exc) 
    548549            return self.nfunc, best_alpha, "Could not estimate number of terms" 
    549550 
     
    631632                return best_alpha, message, elapsed 
    632633 
    633         except: 
    634             message = "Invertor.estimate_alpha: %s" % sys.exc_value 
     634        except Exception as exc: 
     635            message = "Invertor.estimate_alpha: %s" % exc 
    635636            return 0, message, elapsed 
    636637 
     
    748749                        self.cov[i][i] = float(toks2[1]) 
    749750 
    750             except: 
    751                 msg = "Invertor.from_file: corrupted file\n%s" % sys.exc_value 
     751            except Exception as exc: 
     752                msg = "Invertor.from_file: corrupted file\n%s" % exc 
    752753                raise RuntimeError(msg) 
    753754        else: 
Note: See TracChangeset for help on using the changeset viewer.