hyperspy._signals.signal2d module¶
-
class
hyperspy._signals.signal2d.
LazySignal2D
(*args, **kwargs)¶ Bases:
hyperspy._signals.lazy.LazySignal
,hyperspy._signals.signal2d.Signal2D
-
class
hyperspy._signals.signal2d.
Signal2D
(*args, **kw)¶ Bases:
hyperspy.signal.BaseSignal
,hyperspy._signals.common_signal2d.CommonSignal2D
-
add_ramp
(ramp_x, ramp_y, offset=0)¶ Add a linear ramp to the signal.
- Parameters
ramp_x (float) – Slope of the ramp in x-direction.
ramp_y (float) – Slope of the ramp in y-direction.
offset (float, optional) – Offset of the ramp at the signal fulcrum.
Notes
The fulcrum of the linear ramp is at the origin and the slopes are given in units of the axis with the according scale taken into account. Both are available via the axes_manager of the signal.
-
align2D
(crop=True, fill_value=nan, shifts=None, expand=False, roi=None, sobel=True, medfilter=True, hanning=True, plot=False, normalize_corr=False, reference='current', dtype='float', correlation_threshold=None, chunk_size=30, interpolation_order=1, sub_pixel_factor=1, show_progressbar=None, parallel=None)¶ Align the images in place using user provided shifts or by estimating the shifts.
Please, see estimate_shift2D docstring for details on the rest of the parameters not documented in the following section
- Parameters
crop (bool) – If True, the data will be cropped not to include regions with missing data
fill_value (int, float, nan) – The areas with missing data are filled with the given value. Default is nan.
shifts (None or list of tuples) – If None the shifts are estimated using estimate_shift2D.
expand (bool) – If True, the data will be expanded to fit all data after alignment. Overrides crop.
interpolation_order (int, default 1.) – The order of the spline interpolation. Default is 1, linear interpolation.
parallel (None or bool) – If True, perform computation in parallel using multiple cores. If None the default from the preferences settings is used.
- Returns
shifts – The shifts are returned only if shifts is None
- Return type
np.array
Notes
The statistical analysis approach to the translation estimation when using `reference`=’stat’ roughly follows [1]_ . If you use it please cite their article.
References
- 1
Bernhard Schaffer, Werner Grogger and Gerald Kothleitner. “Automated Spatial Drift Correction for EFTEM Image Series.” Ultramicroscopy 102, no. 1 (December 2004): 27–36.
-
create_model
(dictionary=None)¶ Create a model for the current signal
- Parameters
dictionary ({None, dict}, optional) – A dictionary to be used to recreate a model. Usually generated using
hyperspy.model.as_dictionary()
- Returns
- Return type
A Model class
-
crop_image
(top=None, bottom=None, left=None, right=None, convert_units=False)¶ Crops an image in place.
- Parameters
bottom, left, right (top,) – If int the values are taken as indices. If float the values are converted to indices.
convert_units (bool) – Default is False If True, convert the signal units using the ‘convert_to_units’ method of the ‘axes_manager’. If False, does nothing.
also (See) –
--------- –
crop –
-
estimate_shift2D
(reference='current', correlation_threshold=None, chunk_size=30, roi=None, normalize_corr=False, sobel=True, medfilter=True, hanning=True, plot=False, dtype='float', show_progressbar=None, sub_pixel_factor=1)¶ Estimate the shifts in a image using phase correlation
This method can only estimate the shift by comparing bidimensional features that should not change position between frames. To decrease the memory usage, the time of computation and the accuracy of the results it is convenient to select a region of interest by setting the roi keyword.
- Parameters
reference ({'current', 'cascade' ,'stat'}) – If ‘current’ (default) the image at the current coordinates is taken as reference. If ‘cascade’ each image is aligned with the previous one. If ‘stat’ the translation of every image with all the rest is estimated and by performing statistical analysis on the result the translation is estimated.
correlation_threshold ({None, 'auto', float}) – This parameter is only relevant when reference is ‘stat’. If float, the shift estimations with a maximum correlation value lower than the given value are not used to compute the estimated shifts. If ‘auto’ the threshold is calculated automatically as the minimum maximum correlation value of the automatically selected reference image.
chunk_size ({None, int}) – If int and `reference`==’stat’ the number of images used as reference are limited to the given value.
roi (tuple of ints or floats (left, right, top, bottom)) – Define the region of interest. If int(float) the position is given axis index(value).
sobel (bool) – apply a sobel filter for edge enhancement
medfilter (bool) – apply a median filter for noise reduction
hanning (bool) – Apply a 2d hanning filter
plot (bool or "reuse") – If True plots the images after applying the filters and the phase correlation. If ‘reuse’, it will also plot the images, but it will only use one figure, and continuously update the images in that figure as it progresses through the stack.
dtype (str or dtype) – Typecode or data-type in which the calculations must be performed.
show_progressbar (None or bool) – If True, display a progress bar. If None the default from the preferences settings is used.
sub_pixel_factor (float) – Estimate shifts with a sub-pixel accuracy of 1/sub_pixel_factor parts of a pixel. Default is 1, i.e. no sub-pixel accuracy.
- Returns
- Return type
list of applied shifts
Notes
The statistical analysis approach to the translation estimation when using `reference`=’stat’ roughly follows [1]_ . If you use it please cite their article.
References
- 1
Schaffer, Bernhard, Werner Grogger, and Gerald
Kothleitner. “Automated Spatial Drift Correction for EFTEM Image Series.” Ultramicroscopy 102, no. 1 (December 2004): 27–36.
-
plot
(colorbar=True, scalebar=True, scalebar_color='white', axes_ticks=None, axes_off=False, saturated_pixels=0, vmin=None, vmax=None, no_nans=False, centre_colormap='auto', min_aspect=0.1, **kwargs)¶ Plot the signal at the current coordinates.
For multidimensional datasets an optional figure, the “navigator”, with a cursor to navigate that data is raised. In any case it is possible to navigate the data using the sliders. Currently only signals with signal_dimension equal to 0, 1 and 2 can be plotted.
- Parameters
navigator ({"auto", None, "slider", "spectrum", Signal}) – If “auto”, if navigation_dimension > 0, a navigator is provided to explore the data. If navigation_dimension is 1 and the signal is an image the navigator is a spectrum obtained by integrating over the signal axes (the image). If navigation_dimension is 1 and the signal is a spectrum the navigator is an image obtained by stacking horizontally all the spectra in the dataset. If navigation_dimension is > 1, the navigator is an image obtained by integrating the data over the signal axes. Additionaly, if navigation_dimension > 2 a window with one slider per axis is raised to navigate the data. For example, if the dataset consists of 3 navigation axes X, Y, Z and one signal axis, E, the default navigator will be an image obtained by integrating the data over E at the current Z index and a window with sliders for the X, Y and Z axes will be raised. Notice that changing the Z-axis index changes the navigator in this case. If “slider” and the navigation dimension > 0 a window with one slider per axis is raised to navigate the data. If “spectrum” and navigation_dimension > 0 the navigator is always a spectrum obtained by integrating the data over all other axes. If None, no navigator will be provided. Alternatively a Signal instance can be provided. The signal dimension must be 1 (for a spectrum navigator) or 2 (for a image navigator) and navigation_shape must be 0 (for a static navigator) or navigation_shape + signal_shape must be equal to the navigator_shape of the current object (for a dynamic navigator). If the signal dtype is RGB or RGBA this parameters has no effect and is always “slider”.
axes_manager ({None, axes_manager}) – If None axes_manager is used.
plot_markers (bool, default True) – Plot markers added using s.add_marker(marker, permanent=True). Note, a large number of markers might lead to very slow plotting.
norm ({‘auto’, ‘linear’, ‘log’, mpl Normalize instance or subclass},) – default is ‘auto’. Plot the intensity scale on a linear or logarithmic scale. If ‘auto’, plot the intensity on a linear scale except when power_spectrum is True, which can be used only for compatible signal. For Signal2D, a matplotlib Normalize subclass or instance can be provided.
colorbar (bool, optional) – If true, a colorbar is plotted for non-RGB images.
scalebar (bool, optional) – If True and the units and scale of the x and y axes are the same a scale bar is plotted.
scalebar_color (str, optional) – A valid MPL color string; will be used as the scalebar color.
axes_ticks ({None, bool}, optional) – If True, plot the axes ticks. If None axes_ticks are only plotted when the scale bar is not plotted. If False the axes ticks are never plotted.
saturated_pixels (scalar) – The percentage of pixels that are left out of the bounds. For example, the low and high bounds of a value of 1 are the 0.5% and 99.5% percentiles. It must be in the [0, 100] range.
vmax (vmin,) – vmin and vmax are used to normalize luminance data.
no_nans (bool, optional) – If True, set nans to zero for plotting.
centre_colormap ({"auto", True, False}) – If True the centre of the color scheme is set to zero. This is specially useful when using diverging color schemes. If “auto” (default), diverging color schemes are automatically centred.
min_aspect (float) – Set the minimum aspect ratio of the image and the figure. To keep the image in the aspect limit the pixels are made rectangular.
optional (**kwargs,) – Only for 2D signals: additional key word arguments for matplotlib.pyplot.imshow.
-
-
hyperspy._signals.signal2d.
estimate_image_shift
(ref, image, roi=None, sobel=True, medfilter=True, hanning=True, plot=False, dtype='float', normalize_corr=False, sub_pixel_factor=1, return_maxval=True)¶ Estimate the shift in a image using phase correlation
This method can only estimate the shift by comparing bidimensional features that should not change the position in the given axis. To decrease the memory usage, the time of computation and the accuracy of the results it is convenient to select a region of interest by setting the roi keyword.
- Parameters
ref (2D numpy.ndarray) – Reference image
image (2D numpy.ndarray) – Image to register
roi (tuple of ints (top, bottom, left, right)) – Define the region of interest
sobel (bool) – apply a sobel filter for edge enhancement
medfilter (bool) – apply a median filter for noise reduction
hanning (bool) – Apply a 2d hanning filter
plot (bool | matplotlib.Figure) – If True, plots the images after applying the filters and the phase correlation. If a figure instance, the images will be plotted to the given figure.
reference ('current' | 'cascade') – If ‘current’ (default) the image at the current coordinates is taken as reference. If ‘cascade’ each image is aligned with the previous one.
dtype (str or dtype) – Typecode or data-type in which the calculations must be performed.
normalize_corr (bool) – If True use phase correlation instead of standard correlation
sub_pixel_factor (float) – Estimate shifts with a sub-pixel accuracy of 1/sub_pixel_factor parts of a pixel. Default is 1, i.e. no sub-pixel accuracy.
- Returns
shifts (np.array) – containing the estimate shifts
max_value (float) – The maximum value of the correlation
Notes
The statistical analysis approach to the translation estimation when using `reference`=’stat’ roughly follows [1]_ . If you use it please cite their article.
References
- 1
Bernhard Schaffer, Werner Grogger and Gerald Kothleitner. “Automated Spatial Drift Correction for EFTEM Image Series.” Ultramicroscopy 102, no. 1 (December 2004): 27–36.
-
hyperspy._signals.signal2d.
fft_correlation
(in1, in2, normalize=False)¶ Correlation of two N-dimensional arrays using FFT.
Adapted from scipy’s fftconvolve.
- Parameters
in2 (in1,) –
normalize (bool) – If True performs phase correlation
-
hyperspy._signals.signal2d.
hanning2d
(M, N)¶ A 2D hanning window created by outer product.
-
hyperspy._signals.signal2d.
shift_image
(im, shift=0, interpolation_order=1, fill_value=nan)¶
-
hyperspy._signals.signal2d.
sobel_filter
(im)¶
-
hyperspy._signals.signal2d.
triu_indices_minus_diag
(n)¶ Returns the indices for the upper-triangle of an (n, n) array excluding its diagonal
- Parameters
n (int) – The length of the square array