STData¶
-
class
pyrost.STData(protocol, **kwargs)¶ Speckle Tracking algorithm data container class. Contains all the necessary data for the Robust Speckle Tracking algorithm (specified in attr_set and init_set), the list of all the
SpeckleTrackingobjects derived from it, and twoAbberationsFitobjects to fit the phase along the fast and slow detector axes.- Parameters
- Variables
- Raises
ValueError – If an attribute specified in attr_set has not been provided.
Notes
Necessary attributes:
basis_vectors : Detector basis vectors
data : Measured intensity frames.
distance : Sample-to-detector distance [m].
translations : Sample’s translations [m].
wavelength : Incoming beam’s wavelength [m].
x_pixel_size : Pixel’s size along the fast detector axis [m].
y_pixel_size : Pixel’s size along the slow detector axis [m].
Optional attributes:
defocus_ss : Defocus distance for the slow detector axis [m].
defocus_fs : Defocus distance for the fast detector axis [m].
error_frame : MSE (mean-squared-error) of the reference image and pixel mapping fit per pixel.
good_frames : An array of good frames’ indices.
mask : Bad pixels mask.
phase : Phase profile of lens’ abberations.
pixel_map : The pixel mapping between the data at the detector’s plane and the reference image at the reference plane.
pixel_abberations : Lens’ abberations along the fast and slow axes in pixels.
pixel_translations : Sample’s translations in the detector’s plane in pixels.
reference_image : The unabberated reference image of the sample.
roi : Region of interest in the detector’s plane.
whitefield : Measured frames’ whitefield.
-
make_mask(method='no-bad', percentile=99.99)¶ Return a new
STDataobject with the updated bad pixels mask.- Parameters
method ({'no-bad', 'eiger-bad', 'perc-bad'}, optional) –
Bad pixels masking methods:
’no-bad’ (default) : No bad pixels.
’eiger-bad’ : Mask the pixels which value are higher than 65535 a.u. (for EIGER detector).
’perc-bad’ : mask the pixels which values lie outside of the q-th percentile. Provide percentile value with percentile argument.
percentile (float, optional) – Percentile to compute. Defines the ‘perc-bad’ masking method.
- Returns
New
STDataobject with the updated mask.- Return type
-
update_defocus(defocus_fs, defocus_ss=None)¶ Return a new
STDataobject with the updated defocus distances defocus_fs and defocus_ss for the fast and slow detector axes accordingly. Update pixel_translations based on the new defocus distances.- Parameters
- Returns
New
STDataobject with the updated defocus_ss, defocus_fs, and pixel_translations.- Return type
-
defocus_sweep(defoci_fs, defoci_ss=None, ls_ri=30)¶ Calculate an array of reference_image for defoci and return fugures of merit of reference_image sharpness (the higher the value the sharper reference_image is). ls_ri should be large enough in order to supress high frequency noise.
- Parameters
defoci_fs (numpy.ndarray) – Array of defocus distances along the fast detector axis [m].
defoci_ss (numpy.ndarray, optional) – Array of defocus distances along the slow detector axis [m].
ls_ri (float, optional) – reference_image length scale in pixels.
- Returns
Array of the average values of reference_image gradients squared.
- Return type
See also
SpeckleTracking.update_referencereference_image update algorithm.
-
fit_phase(axis=1, max_order=2, xtol=1e-14, ftol=1e-14, loss='cauchy', roi=None)¶ Fit pixel_abberations with the polynomial function using nonlinear least-squares algorithm. The function uses least-squares algorithm from
scipy.optimize.least_squares().- Parameters
axis (int, optional) – Axis along which pixel_abberations is fitted.
max_order (int, optional) – Maximum order of the polynomial model function.
xtol (float, optional) – Tolerance for termination by the change of the independent variables.
ftol (float, optional) – Tolerance for termination by the change of the cost function.
loss ({'linear', 'soft_l1', 'huber', 'cauchy', 'arctan'}, optional) –
Determines the loss function. The following keyword values are allowed:
’linear’ :
rho(z) = z. Gives a standard least-squares problem.’soft_l1’ :
rho(z) = 2 * ((1 + z)**0.5 - 1). The smooth approximation of l1 (absolute value) loss. Usually a good choice for robust least squares.’huber’ :
rho(z) = z if z <= 1 else 2*z**0.5 - 1. Works similarly to ‘soft_l1’.’cauchy’ (default) :
rho(z) = ln(1 + z). Severely weakens outliers influence, but may cause difficulties in optimization process.’arctan’ :
rho(z) = arctan(z). Limits a maximum loss on a single residual, has properties similar to ‘cauchy’.
roi (iterable, optional) – Region of interest. Full region if roi is None.
- Returns
dictwith the following fields defined:alpha : Third order abberations ceofficient [rad/mrad^3].
fit : Array of the polynomial function coefficients of the pixel abberations fit.
ph_fit : Array of the polynomial function coefficients of the phase abberations fit.
rel_err : Vector of relative errors of the fit coefficients.
r_sq :
R**2goodness of fit.
- Return type
See also
-
get(attr, value=None)¶ Return a dataset with mask and roi applied. Return value if the attribute is not found.
- Parameters
- Returns
attr dataset with mask and roi applied. value if attr is not found.
- Return type
-
get_fit(axis=1)¶ Return an
AbberationsFitobject for parametric regression of the lens’ abberations profile. Return None if defocus_fs or defocus_ss doesn’t exist in the container.- Parameters
axis (int) – Detector axis along which the fitting is performed.
- Returns
An instance of
AbberationsFitclass. None if defocus_fs or defocus_ss is None.- Return type
-
get_st()¶ Return
SpeckleTrackingobject derived from the container. Return None if defocus_fs or defocus_ss doesn’t exist in the container.- Returns
An instance of
SpeckleTrackingderived from the container. None if defocus_fs or defocus_ss is None.- Return type
-
get_st_list()¶ Return a list of all the
SpeckleTrackingobjects bound to the container.- Returns
List of all the
SpeckleTrackingobjects bound to the container.- Return type
-
items()¶ Return (key, value) pairs of the datasets stored in the container.
- Returns
(key, value) pairs of the datasets stored in the container.
- Return type
dict_items
-
keys()¶ Return the list of attributes stored in the container.
- Returns
List of attributes stored in the container.
- Return type
dict_keys
-
update_phase(st_obj)¶ Update pixel_abberations, phase, and reference_image based on
SpeckleTrackingobject st_obj data. st_obj must be derived from theSTDataobject, an error is raised otherwise.- Parameters
st_obj (SpeckleTracking) –
SpeckleTrackingobject derived from theSTDataobject.- Returns
STDataobject with the updated pixel_abberations, phase, and reference_image.- Return type
- Raises
ValueError – If st_obj doesn’t belong to the
STDataobject.
-
values()¶ Return the attributes’ data stored in the container.
- Returns
List of data stored in the container.
- Return type
dict_values
-
write_cxi(cxi_file, overwrite=True)¶ Write all the attr to a CXI file cxi_file.
- Parameters
- Raises
ValueError – If overwrite is False and the data is already present in cxi_file.