pyxem / kikuchipy

Toolbox for analysis of electron backscatter diffraction (EBSD) patterns
https://kikuchipy.org
GNU General Public License v3.0
79 stars 30 forks source link

Add method to downsample EBSD patterns while maintaining data type range #592

Closed hakonanes closed 1 year ago

hakonanes commented 1 year ago

Description of the change

HyperSpy's Signal2D.rebin() is a powerful tool for binning, but it does not rescale intensities. This can lead to memory problems. This PR adds a EBSD.downsample() method which rescales intensities after binning before overwriting each pattern inplace. It only supports one integer binning factor which must be a divisor of both detector dimensions. Which data type to rescale intensities to can be specified. This of course leads to contrast between patterns being lost.

Calling EBSD.rebin() followed by EBSD.rescale_intensity() effectively gives the same result as calling EBSD.downsample().

I also sorted EBSD methods into groups based on "types" (tools, feature maps, intensity processing [including downsample()], indexing etc.). This is the reason for the relatively large git diff.

Closes #464.

Progress of the PR

Minimal example of the bug fix or new feature

>>> import matplotlib.pyplot as plt
>>> import kikuchipy as kp
>>> s = kp.data.silicon_ebsd_moving_screen_in()
>>> s.remove_static_background()
>>> s2 = s.rebin(scale=(2, 2), dtype=s.data.dtype)
>>> s3 = s.deepcopy()
>>> s3.downsample(2)
>>> fig, (ax0, ax1) = plt.subplots(ncols=2)
>>> ax0.imshow(s2.data)
>>> ax1.imshow(s3.data)

test

For reviewers