sas.pr package

Submodules

sas.pr.distance_explorer module

Module to explore the P(r) inversion results for a range of D_max value. User picks a number of points and a range of distances, then get a series of outputs as a function of D_max over that range.

class sas.pr.distance_explorer.DistExplorer(pr_state)[source]

Bases: object

The explorer class

class sas.pr.distance_explorer.Results[source]

Class to hold the inversion output parameters as a function of D_max

sas.pr.invertor module

Module to perform P(r) inversion. The module contains the Invertor class.

class sas.pr.invertor.Invertor[source]

Bases: Cinvertor

Invertor class to perform P(r) inversion

The problem is solved by posing the problem as Ax = b, where x is the set of coefficients we are looking for.

Npts is the number of points.

In the following i refers to the ith base function coefficient. The matrix has its entries j in its first Npts rows set to

A[j][i] = (Fourier transformed base function for point j)

We them choose a number of r-points, n_r, to evaluate the second derivative of P(r) at. This is used as our regularization term. For a vector r of length n_r, the following n_r rows are set to

A[j+Npts][i] = (2nd derivative of P(r), d**2(P(r))/d(r)**2,
evaluated at r[j])

The vector b has its first Npts entries set to

b[j] = (I(q) observed for point j)

The following n_r entries are set to zero.

The result is found by using scipy.linalg.basic.lstsq to invert the matrix and find the coefficients x.

Methods inherited from Cinvertor:

  • get_peaks(pars): returns the number of P(r) peaks
  • oscillations(pars): returns the oscillation parameters for the output P(r)
  • get_positive(pars): returns the fraction of P(r) that is above zero
  • get_pos_err(pars): returns the fraction of P(r) that is 1-sigma above zero
background = 0
chi2 = 0
clone()[source]

Return a clone of this instance

cov = None
elapsed = 0
estimate_alpha(nfunc)[source]

Returns a reasonable guess for the regularization constant alpha

Parameters:nfunc – number of terms to use in the expansion.
Returns:alpha, message, elapsed

where alpha is the estimate for alpha, message is a message for the user, elapsed is the computation time

estimate_numterms(isquit_func=None)[source]

Returns a reasonable guess for the number of terms

Parameters:isquit_func – reference to thread function to call to check whether the computation needs to be stopped.
Returns:number of terms, alpha, message
from_file(path)[source]

Load the state of the Invertor from a file, to be able to generate P(r) from a set of parameters.

Parameters:path – path of the file to load
info = {}
invert(nfunc=10, nr=20)[source]

Perform inversion to P(r)

The problem is solved by posing the problem as Ax = b, where x is the set of coefficients we are looking for.

Npts is the number of points.

In the following i refers to the ith base function coefficient. The matrix has its entries j in its first Npts rows set to

A[i][j] = (Fourier transformed base function for point j)

We them choose a number of r-points, n_r, to evaluate the second derivative of P(r) at. This is used as our regularization term. For a vector r of length n_r, the following n_r rows are set to

A[i+Npts][j] = (2nd derivative of P(r), d**2(P(r))/d(r)**2, evaluated at r[j])

The vector b has its first Npts entries set to

b[j] = (I(q) observed for point j)

The following n_r entries are set to zero.

The result is found by using scipy.linalg.basic.lstsq to invert the matrix and find the coefficients x.

Parameters:
  • nfunc – number of base functions to use.
  • nr – number of r points to evaluate the 2nd derivative at for the reg. term.
Returns:

c_out, c_cov - the coefficients with covariance matrix

invert_optimize(nfunc=10, nr=20)[source]

Slower version of the P(r) inversion that uses scipy.optimize.leastsq.

This probably produce more reliable results, but is much slower. The minimization function is set to sum_i[ (I_obs(q_i) - I_theo(q_i))/err**2 ] + alpha * reg_term, where the reg_term is given by Svergun: it is the integral of the square of the first derivative of P(r), d(P(r))/dr, integrated over the full range of r.

Parameters:
  • nfunc – number of base functions to use.
  • nr – number of r points to evaluate the 2nd derivative at for the reg. term.
Returns:

c_out, c_cov - the coefficients with covariance matrix

iq(out, q)[source]

Function to call to evaluate the scattering intensity

Parameters:args – c-parameters, and q
Returns:I(q)
lstsq(nfunc=5, nr=20)[source]

The problem is solved by posing the problem as Ax = b, where x is the set of coefficients we are looking for.

Npts is the number of points.

In the following i refers to the ith base function coefficient. The matrix has its entries j in its first Npts rows set to

A[i][j] = (Fourier transformed base function for point j)

We them choose a number of r-points, n_r, to evaluate the second derivative of P(r) at. This is used as our regularization term. For a vector r of length n_r, the following n_r rows are set to

A[i+Npts][j] = (2nd derivative of P(r), d**2(P(r))/d(r)**2,
evaluated at r[j])

The vector b has its first Npts entries set to

b[j] = (I(q) observed for point j)

The following n_r entries are set to zero.

The result is found by using scipy.linalg.basic.lstsq to invert the matrix and find the coefficients x.

Parameters:
  • nfunc – number of base functions to use.
  • nr – number of r points to evaluate the 2nd derivative at for the reg. term.

If the result does not allow us to compute the covariance matrix, a matrix filled with zeros will be returned.

nfunc = 10
out = None
pr_err(c, c_cov, r)[source]

Returns the value of P(r) for a given r, and base function coefficients, with error.

Parameters:
  • c – base function coefficients
  • c_cov – covariance matrice of the base function coefficients
  • r – r-value to evaluate P(r) at
Returns:

P(r)

pr_fit(nfunc=5)[source]

This is a direct fit to a given P(r). It assumes that the y data is set to some P(r) distribution that we are trying to reproduce with a set of base functions.

This method is provided as a test.

suggested_alpha = 0
to_file(path, npts=100)[source]

Save the state to a file that will be readable by SliceView.

Parameters:
  • path – path of the file to write
  • npts – number of P(r) points to be written
sas.pr.invertor.help()[source]

Provide general online help text Future work: extend this function to allow topic selection

sas.pr.num_term module

class sas.pr.num_term.Num_terms(invertor)[source]
compare_err()[source]
get0_out()[source]
is_odd(n)[source]
ls_osc()[source]
median_osc()[source]
num_terms(isquit_func=None)[source]
sort_osc()[source]
sas.pr.num_term.load(path)[source]

Module contents

P(r) inversion for SAS

Table Of Contents

Previous topic

sas.plottools package

Next topic

sas.pr.core package

This Page