invertor

sans.pr.invertor

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

class sans.pr.invertor.Invertor

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

basefunc_ft
Returns the value of the nth Fourier transofrmed base function @param args: c-parameters, n and q @return: nth Fourier transformed base function, evaluated at q
clone()
Return a clone of this instance
estimate_alpha(nfunc)

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)

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)

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
get_alpha
Gets the alpha parameter
get_dmax
Gets the maximum distance
get_err

Function to get the err data Takes an array of doubles as input.

@return: number of entries found
get_has_bck
Gets background flag
get_nerr
Gets the number of err points
get_nx
Gets the number of x points
get_ny
Gets the number of y points
get_peaks

Returns the number of peaks in the output P(r) distrubution for the given set of coefficients.

@param args: c-parameters @return: number of P(r) peaks
get_pos_err

Returns the fraction of P(r) that is 1 standard deviation above zero over the full range of r for the given set of coefficients.

@param args: c-parameters @return: fraction of P(r) that is positive
get_positive

Returns the fraction of P(r) that is positive over the full range of r for the given set of coefficients.

@param args: c-parameters @return: fraction of P(r) that is positive
get_pr_err
Function to call to evaluate P(r) with errors @param args: c-parameters and r @return: (P(r),dP(r))
get_qmax
Gets the maximum q
get_qmin
Gets the minimum q
get_slit_height
Gets the slit height
get_slit_width
Gets the slit width
get_x

Function to get the x data Takes an array of doubles as input.

@return: number of entries found
get_y

Function to get the y data Takes an array of doubles as input.

@return: number of entries found
invert(nfunc=10, nr=20)

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)

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)

Function to call to evaluate the scattering intensity

Parameters:
  • args – c-parameters, and q
Returns:

I(q)

iq0
Returns the value of I(q=0). @param args: c-parameters @return: I(q=0)
iq_smeared

Function to call to evaluate the scattering intensity. The scattering intensity is slit-smeared. @param args: c-parameters, and q

@return: I(q)
is_valid
Check the validity of the stored data @return: Returns the number of points if it’s all good, -1 otherwise
lstsq(nfunc=5, nr=20)

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.

oscillations

Returns the value of the oscillation figure of merit for the given set of coefficients. For a sphere, the oscillation figure of merit is 1.1.

@param args: c-parameters @return: oscillation figure of merit
pr
Function to call to evaluate P(r) @param args: c-parameters and r @return: P(r)
pr_err(c, c_cov, r)

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)

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.

pr_residuals

Function to call to evaluate the residuals for P(r) minimization (for testing purposes)

@param args: input parameters @return: list of residuals
residuals

Function to call to evaluate the residuals for P(r) inversion

@param args: input parameters @return: list of residuals
rg
Returns the value of the radius of gyration Rg. @param args: c-parameters @return: Rg
set_alpha
Sets the alpha parameter
set_dmax
Sets the maximum distance
set_err

Function to set the err data Takes an array of doubles as input.

@return: number of entries found
set_has_bck
Sets background flag
set_qmax
Sets the maximum q
set_qmin
Sets the minimum q
set_slit_height
Sets the slit height in units of q [A-1]
set_slit_width
Sets the slit width in units of q [A-1]
set_x

Function to set the x data Takes an array of doubles as input.

@return: number of entries found
set_y

Function to set the y data Takes an array of doubles as input.

@return: number of entries found
to_file(path, npts=100)

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
sans.pr.invertor.help()
Provide general online help text Future work: extend this function to allow topic selection

Table Of Contents

Previous topic

distance_explorer

Next topic

num_term

This Page