get_linear_plane#
- BeamShift.get_linear_plane(mask=None, fit_corners=None, initial_values=None, constrain_magnitude_variance=False)[source]#
Fit linear planes to the beam shifts, and returns a BeamShift signal with the planes.
In many scanning transmission electron microscopes, the center position of the diffraction pattern will change as a function of the scan position. This is most apparent when scanning over large regions (100+ nanometers). Thus, when working with datasets, it is typically necessary to correct for this. However, other effects can also affect the apparent center point, like diffraction contrast. So while it is possible to correct for the beam shift by finding the center position in each diffraction pattern, this can lead to features such as interfaces or grain boundaries affecting the centering of the diffraction pattern. As the shift caused by the scan system is slow and monotonic, it can often be approximated by fitting linear planes to the x- and y- beam shifts.
In addition, for regions within the scan where the center point of the direct beam is hard to ascertain precisely, for example in very thick or heavily diffracting regions, a mask can be used to ignore fitting the plane to these regions.
This method does this, and returns a new BeamShift signal with these fitted planes. The beam shift signal can then be directly used in the
center_direct_beam()
method.Note that for very large regions, this linear plane will probably not approximate the beam shift very well. In those cases a higher order plane will likely be necessary. Alternatively, a vacuum scan with exactly the same scanning parameters should be used.
- Parameters:
mask (HyperSpy signal, optional) – Must be the same shape as the navigation dimensions of the beam shift signal. The True values will be masked.
fit_corners (float, optional) – Make a mask so that the planes are fitted to the corners of the signal. This mush be set with a number, like 0.05 (5%) or 0.10 (10%).
initial_values (array of floats, optional) – Initial guess for the plane parameters. Useful to vary if the plane fitting does not give desirable results. The horizontal- and vertical-shifts are described by two linear planes with three parameters. The two first parameters, d/dx and d/dy, are the changes in horizontal-shift as you move one position in the navigation space in respectively the x- and y-directions. I. e. they are the steps in horizontal-shift as you change x- or y-coordinates. The third parameter, shift_0, is the horizontal-shift in the (0, 0) navigation position. The vertical-shift are described by similar parameters. In this argument supply the plane parameters in the following way, with the first three being for the horizontal-shift and the rest for the vertical-shift: [d/dx, d/dy, shift_0, d/dx, d/dy, shift_0] Currently only implemented for the case when constrain_magnitude_variance is True.
constrain_magnitude_variance (bool, optional) – Fits the linear planes to deflections with constant magnitude. By default set to False. In the presence of electromagnetic fields in the sample area, least squares fitting can give inaccurate results. If the region is expected to have uniform field strength, we can fit planes by trying to minimise the variance of the magnitudes, giving a constant deflection magnitude. Note that for this to work several field directions must be present. Extra care must be taken in presence of significant noise, such as with a mask. If desirable results are not found, try varying the initial_values parameter.
Examples
>>> s = pxm.signals.BeamShift(np.random.randint(0, 99, (100, 120, 2))) >>> s_mask = hs.signals.Signal2D(np.zeros((100, 120), dtype=bool)) >>> s_mask.data[20:-20, 20:-20] = True >>> s_linear_plane = s.get_linear_plane(mask=s_mask)
For magnetic DPC signals, one would typically want to subtract these linear planes from the original signal
>>> s_corr = s - s_linear_plane