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

Handle custom EBSD class attributes in calls to Signal2D's inav, isig and more #578

Closed hakonanes closed 1 year ago

hakonanes commented 1 year ago

Description of the change

Attempt to crop and update EBSD class attributes xmap (an orix CrystalMap), static_background and detector (an EBSDDetector) upon calls to the following inherited methods from HyperSpy's Signal2D methods:

Handling of attributes in inav and isig is done by overwriting the private BaseSignal._slicer() method. This is dangerous, however most handling is done via try/except, falling back to old behavior if this doesn't work. Tests, my own testing and building the docs' tutorials and examples runs as desired.

Other changes:

Closes #227.

Progress of the PR

Minimal example of the bug fix or new feature

>>> import kikuchipy as kp
>>> s = kp.data.nickel_ebsd_small()
>>> s
<EBSD, title: patterns Scan 1, dimensions: (3, 3|60, 60)>
>>> s.xmap.shape
(3, 3)
>>> s.static_background.shape
(60, 60)
>>> s.detector
EBSDDetector (60, 60), px_size 1 um, binning 8, tilt 0, azimuthal 0, pc (0.425, 0.213, 0.501)

# Bin signal shape by a factor of 2 (can call remove_static_background() afterwards without modifications to
# background pattern)

>>> s2 = s.rebin(scale=(1, 1, 2, 2))
>>> s2
<EBSD, title: patterns Scan 1, dimensions: (3, 3|30, 30)>
>>> s2.xmap.shape
(3, 3)
>>> s2.static_background.shape
(30, 30)
>>> s2.detector
EBSDDetector (30, 30), px_size 1 um, binning 8, tilt 0, azimuthal 0, pc (0.425, 0.213, 0.501)

# Crop

>>> s.inav[:2, :1].xmap.shape
(1, 2)
>>> s.isig[10:50, 10:].static_background.shape
(50, 40)
>>> s.inav[:2, :3].detector.pc.shape
(3, 2, 3)

For reviewers