Module to perform P(r) inversion. The module contains the Invertor class.
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 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
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
Return a clone of this instance
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
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 |
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 |
---|
Gets the alpha parameter
Gets the maximum distance
Function to get the err data Takes an array of doubles as input.
@return: number of entries found
Gets background flag
Gets the number of err points
Gets the number of x points
Gets the number of y points
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
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
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
Function to call to evaluate P(r) with errors @param args: c-parameters and r @return: (P(r),dP(r))
Gets the maximum q
Gets the minimum q
Gets the slit height
Gets the slit width
Function to get the x data Takes an array of doubles as input.
@return: number of entries found
Function to get the y data Takes an array of doubles as input.
@return: number of entries found
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 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: |
|
---|---|
Returns: | c_out, c_cov - the coefficients with covariance matrix |
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: |
|
---|---|
Returns: | c_out, c_cov - the coefficients with covariance matrix |
Function to call to evaluate the scattering intensity
Parameters: | args – c-parameters, and q |
---|---|
Returns: | I(q) |
Returns the value of I(q=0). @param args: c-parameters @return: I(q=0)
Function to call to evaluate the scattering intensity. The scattering intensity is slit-smeared. @param args: c-parameters, and q
@return: I(q)
Check the validity of the stored data @return: Returns the number of points if it’s all good, -1 otherwise
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 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: |
|
---|
If the result does not allow us to compute the covariance matrix, a matrix filled with zeros will be returned.
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
Function to call to evaluate P(r) @param args: c-parameters and r @return: P(r)
Returns the value of P(r) for a given r, and base function coefficients, with error.
Parameters: |
|
---|---|
Returns: | P(r) |
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.
Function to call to evaluate the residuals for P(r) minimization (for testing purposes)
@param args: input parameters @return: list of residuals
Function to call to evaluate the residuals for P(r) inversion
@param args: input parameters @return: list of residuals
Returns the value of the radius of gyration Rg. @param args: c-parameters @return: Rg
Sets the alpha parameter
Sets the maximum distance
Function to set the err data Takes an array of doubles as input.
@return: number of entries found
Sets background flag
Sets the maximum q
Sets the minimum q
Sets the slit height in units of q [A-1]
Sets the slit width in units of q [A-1]
Function to set the x data Takes an array of doubles as input.
@return: number of entries found
Function to set the y data Takes an array of doubles as input.
@return: number of entries found
Save the state to a file that will be readable by SliceView.
Parameters: |
|
---|
Provide general online help text Future work: extend this function to allow topic selection