ncempy.algo.distortion module¶
Module to handle distortions in diffraction patters.
-
ncempy.algo.distortion.
filter_ring
(points, center, rminmax)[source]¶ Filter points to be in a certain radial distance range from center.
Parameters: - points (np.ndarray) – Candidate points.
- center (np.ndarray/tuple) – Center position.
- rminmax (tuple) – Tuple of min and max radial distance.
Returns: List of filtered points, two column array.
Return type: (np.ndarray)
-
ncempy.algo.distortion.
optimize_center
(points, center, maxfev=1000, verbose=None)[source]¶ Optimize the center by minimizing the sum of square deviations from the mean radial distance.
Parameters: - points (np.ndarray) – The points to which the optimization is done (x,y coords in org image).
- center (np.ndarray/tuple) – Initial center guess.
- maxfev (int) – Max number of iterations forwarded to scipy.optimize.leastsq().
- verbose (bool) – Set to get verbose output.
Returns: The optimized center.
Return type: (np.ndarray)
-
ncempy.algo.distortion.
optimize_distortion
(points, ns, maxfev=1000, verbose=False)[source]¶ Optimize distortions.
The orders in the list ns are first fitted subsequently and the result is refined in a final fit simultaneously fitting all orders.
Parameters: - points (np.ndarray) – Points to optimize to (in polar coords).
- ns (tuple) – List of orders to correct for.
- maxfev (int) – Max number of iterations forwarded to scipy.optimize.leastsq().
- verbose (bool) – Set for verbose output.
Returns: Optimized parameters according to ns.
Return type: (np.ndarray)
-
ncempy.algo.distortion.
plot_distpolar
(points, dims, dists, ns, show=False)[source]¶ Plot the results of distortion fitting in polar coordinates.
Parameters: - points (np.ndarray) – Points in polar coords.
- dims (tuple) – Dimensions, necessary to have unit information.
- dists (np.ndarray) – Results of dist fitting, length according to ns.
- ns (list) – List of used orders.
- show (bool) – Set to directly show the plot in interactive mode.
Returns: Image of the plot.
Return type: (np.ndarray)
-
ncempy.algo.distortion.
plot_ringpolar
(points, dims, show=False)[source]¶ Plot points in polar coordinate system.
Parameters: - points (np.ndarrad) – Positions in polar coords.
- dims (tuple) – Dimension information to plot labels.
- show (bool) – Set to directly show plot in interactive mode.
Returns: Image of the plot.
Return type: (np.ndarray)
-
ncempy.algo.distortion.
points_topolar
(points, center)[source]¶ Convert points to polar coordinate system.
Can be either in pixel or real dim, but should be the same for points and center.
Parameters: - points (np.ndarray) – Positions as two column array.
- center (np.ndarray/tuple) – Origin of the polar coordinate system.
Returns: Positions in polar coordinate system as two column array (r, theta).
Return type: (np.ndarray)
-
ncempy.algo.distortion.
rad_dis
(theta, alpha, beta, order=2)[source]¶ Radial distortion due to ellipticity or higher order distortion.
Relative distortion, to be multiplied with radial distance.
Parameters: - theta (np.ndarray/float) – Angles at which to evaluate.
- alpha (float) – Orientation of major axis.
- beta (float) – Strength of distortion (beta = (1-r_min/r_max)/(1+r_min/r_max).
- order (int) – Order of distortion.
Returns: Distortion factor.
Return type: (np.ndarray/float)
-
ncempy.algo.distortion.
residuals_center
(param, data)[source]¶ Residual function for minimizing the deviations from the mean radial distance.
Parameters: - param (np.ndarray) – The center to optimize.
- data (np.ndarray) – The points in x,y coordinates of the original image.
Returns: Residuals.
Return type: (np.ndarray)