ncempy.algo.radial_profile module

Module to calculate radial profiles.

The settings dict used for the evaluation has the following entries:

  • lmax_r (int): Radius used for local maximum detection in [px].
  • lmax_thresh (int): Threshold for local maximum detection in [intensity].
  • lmax_cinit (int, int): Initial guess for center in [px].
  • lmax_range (float, float): r range to cinit used to filter local maxima [dims].
  • ns (int, …): Distortion orders to correct.
  • fit_rrange (float, float): r range used to fit radial profile [dims].
  • back_xs (float, …): Fixpoints for fitting background [dims].
  • back_xswidth (float): Range around fixpoints to take into account [dims].
  • back_init (float): Initial guess for subtracting background.
  • fit_funcs (str, …): List of functions to model radial profile.
  • fit_init (float, …): Initial guess for fitting.

optional (set to None to use defaults):

  • plt_imgminmax (float, float): Relative range to plot the img.
  • rad_rmax (float): Max r to be used in radial profile [dims].
  • rad_dr (float): Stepsize for r-axis in radial profile [dims].
  • rad_sigma (float): Sigma for Gaussian used as kernel density estimator [dims].
  • mask (np.ndarray): Binary image as img, 0 for pixels to exclude.
  • fit_maxfev (int): Maxfev forwarded to scipy optimize.
ncempy.algo.radial_profile.calc_polarcoords(center, dims, ns=None, dists=None)[source]

Calculate the polar coordinates for an image of given shape.

Center is assumed to be in real coordinates (if not just fake the dims). Distortions are corrected if ns and corresponding dists are given.

Parameters:
  • center (np.ndarray/tuple) – Center of polar coordinate system.
  • dims (tuple) – Tuple of dimensions.
  • ns (tuple) – List of distortion orders to correct for.
  • dists (np.ndarray) – Parameters for distortions.
Returns:

Polarcoordinates (r, theta) of polar coordinate system as two np.ndarrays with same dimensions as original image.

Return type:

(tuple)

ncempy.algo.radial_profile.calc_radialprofile(img, rs, rMax, dr, rsigma, mask=None)[source]

Calculate the radial profile using Gaussian kernel density estimator.

It is suggested to use an rMax such that all directions are still in the image, otherwise outer areas will contribute differently and lead to different signal-to-noise. A value of dr corresponding to 1/10 px and rsigma corresponding to 1 px are good parameters.

Parameters:
  • img (np.ndarray) – Image to take radial profile of intensity from.
  • rs (np.ndarray) – Array containing the radial distance, same shape as img.
  • rMax (float) – Maximum radial distance used for the radial profile.
  • dr (float) – Stepsize for r-axis of radial distance.
  • rsigma (float) – Sigma for Gaussian used as kernel density estimator.
  • mask (np.ndarray) – Mask image, values at 0 are excluded from radial profile.
Returns:

Tuple of radial and intensity axes.

Return type:

(tuple)

ncempy.algo.radial_profile.correct_distortion(img, dims, center, ns, dists)[source]

Give corrected version of img with respect to distortions.

Parameters:
  • img (np.ndarray) – Image (2D).
  • dims (tuple) – Dimensions tuple.
  • center (np.ndarray/tuple) – Center to be used.
  • ns (tuple) – List of distortion orders.
  • dists (np.ndarray) – Distortion parameters.
Returns:

Corrected image.

Return type:

(np.ndarray)

ncempy.algo.radial_profile.fit_radialprofile(r, intens, funcs, init_guess, maxfev=None)[source]

Fit the radial profile.

Convenience wrapper for fitting.

Parameters:
  • r (np.ndarray) – r-axis of radial profile.
  • intens (np.ndarray) – Intensity-axis of radial profile.
  • funcs (tuple) – List of functions.
  • init_guess (np.ndarray) – Initial guess for parameters of functions in funcs.
Returns:

Optimized parameters.

Return type:

(np.ndarray)

ncempy.algo.radial_profile.plot_fit(r, intens, dims, funcs, param, show=False)[source]

Plot the fit results to the radial profile.

Parameters:
  • r (np.ndarray) – r-axis of radial profile.
  • intens (np.ndarray) – Intensity-axis of radial profile.
  • dims (tuple) – Dimensions of original image to read out units.
  • funcs (tuple) – List of functions.
  • param (np.ndarray) – Parameters for functions in funcs.
  • show (bool) – Set to directly show plot interactively.
Returns:

Image of the plot.

Return type:

(np.ndarray)

ncempy.algo.radial_profile.plot_radialprofile(r, intens, dims, show=False)[source]

Plot radial profile.

Parameters:
  • r (np.ndarray) – r-axis of radial profile.
  • intens (np.ndarray) – Intensity-axis of radial profile.
  • dims (tuple) – Dimensions of original image to read out units.
  • show (bool) – Set to directly show plot interactively.
Returns:

Image of the plot.

Return type:

(np.ndarray)

ncempy.algo.radial_profile.residuals_fit(param, r, intens, funcs)[source]

Residual function to fit radial profile with flexibility.

The arguments for the single functions are automatically cut from the fit parameters.

Parameters:
  • param (np.ndarray) – Fit parameters.
  • r (np.ndarray) – r-axis.
  • intens (np.ndarray) – Intensity-axis.
  • funcs (tuple) – List of functions to include.
Returns:

Residuals.

Return type:

(np.ndarray)

ncempy.algo.radial_profile.run_singleImage(img, dims, settings, show=False)[source]

Evaluate a single ring diffraction pattern with given settings.

Parameters:
  • img (np.ndarray) – Image.
  • dims (tuple) – Corresponding dim vectors.
  • settings (dict) – Dict of settings necessary for the evaluation.
  • show (bool) – Set to directly show plots interactively.
Returns:

Optimized parameters of fitting the radial profile according to the settings.

Return type:

(np.ndarray)