Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

hakonanes
Copy link
Member

@hakonanes hakonanes commented Nov 15, 2022

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:

  • inav (crop xmap and EBSDDetector.pc)
  • isig (crop EBSDDetector.shape and static_background)
  • crop() (crop attributes)
  • crop_image() (crop EBSDDetector.shape and static_background)
  • rebin() (if nav dimensions change, the xmap and EBSDDetector.pc values are lost; if only sig dimensions change, EBSDDetector.pc values are lost while the static_background is binned similarly to the signal)

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:

  • Added crystal map and refined PC values to the nickel_ebsd_small() dataset HDF5 file. Indexing and PC refinement was done first with PyEBSDIndex, then using refine_orientation_projection_center().
  • Improved handling of detector PC values in the kikuchipy h5ebsd file reader

Closes #227.

Progress of the PR

  • Docstrings for all functions
  • Unit tests with pytest for all lines
  • Clean code style by running black via pre-commit
  • Update detector PC values correctly after cropping the signal shape (in isig, crop, crop_image)
  • Update detector binning when calling rebin()
  • Examples demonstrating selection of data (isig, inav, crop, crop_image)

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

  • The PR title is short, concise, and will make sense 1 year later.
  • New functions are imported in corresponding __init__.py.
  • New features, API changes, and deprecations are mentioned in the unreleased
    section in CHANGELOG.rst.
  • New contributors are added to release.py, .zenodo.json and
    .all-contributorsrc with the table regenerated.

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes added the enhancement New feature or request label Nov 15, 2022
@hakonanes hakonanes added this to the v0.8.0 milestone Nov 15, 2022
@hakonanes hakonanes marked this pull request as draft November 15, 2022 17:16
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes force-pushed the further-improve-use-custom-ebsd-attributes branch from 83ceaa6 to df1659c Compare November 15, 2022 21:53
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes marked this pull request as ready for review November 16, 2022 04:50
@hakonanes hakonanes merged commit 40eff4c into pyxem:develop Nov 16, 2022
@hakonanes hakonanes deleted the further-improve-use-custom-ebsd-attributes branch November 16, 2022 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EBSD.xmap property needs vast improvements
1 participant