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

Add virtual backscatter electron image generator #170

Merged
merged 4 commits into from
May 18, 2020

Conversation

hakonanes
Copy link
Member

@hakonanes hakonanes commented May 15, 2020

Signed-off-by: Håkon Wiik Ånes hwaanes@gmail.com

Description

Adds a VirtualBSEGenerator, following the workflow in pyxem (https://github.com/pyxem/pyxem/blob/master/pyxem/generators/vdf_generator.py). The generator is initialized with an EBSD or LazyEBSD signal, and has methods to get a virtual backscatter electron (BSE) RGB image or a stack of images from a detector grid, (5, 5) default. The grid can also be plotted, and three tiles/regions of interest (ROIs) in the grid can be coloured red, green and blue if desired, to indicate which tiles were used to generate an RGB image.

It generates a VirtualBSEImage signal object, which is introduced in this PR. This is a thin wrapper around HyperSpy's Signal2D. This class has no lazy implementation, which is considered unnecessary for now.

Also renames EBSD.virtual_backscatter_electron_imaging to EBSD.virtual_bse_imaging and EBSD.get_virtual_image to EBSD.get_virtual_bse_image.

Checklist

Minimal example of the bug fix or new feature

>>> import kikuchipy as kp
>>> import numpy as np
>>> s = kp.signals.EBSD(np.random.random(1600).reshape((2, 2, 20, 20)))
# Initialize generator
>>> vbse_gen = kp.generators.VirtualBSEGenerator(s)
# Set grid shape and plot superimposed on a pattern
>>> vbse_gen.grid_shape = (4, 4)
>>> p = vbse_gen.plot_grid()
>>> p
<EBSD, title: , dimensions: (|20, 20)>
# Get ROI from grid row and column (from upper left)
>>> roi22 = vbse_gen.roi_from_grid(2, 2)
>>> roi22
RectangularROI(left=5, top=0, right=10, bottom=5)
>>> roi00 = vbse_gen.roi_from_grid(0, 0)
>>> roi10 = vbse_gen.roi_from_grid(1, 0)
>>> vbse_imgs = vbse_gen.get_images_from_grid()
>>> vbse_imgs
<VirtualBSEImage, title: , dimensions: (4, 4|2, 2)>
>>> vbse_rgb_img = vbse_gen.get_rgb_image(
    red=roi00,  # Can also pass grid tile indices (0, 0)
    green=roi10,  # (1, 0)
    blue=roi22,  # (2, 2)
)
>>> vbse_rgb_img
<VirtualBSEImage, title: , dimensions: (4, 4|2, 2)>
>>> vbse_rgb_img.data.dtype
dtype([('R', 'u1'), ('G', 'u1'), ('B', 'u1')])

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    the unreleased section in doc/changelog.rst.

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes added enhancement New feature or request documentation This relates to the documentation tests This relates to the tests labels May 15, 2020
@hakonanes hakonanes added this to the v0.3.0 milestone May 15, 2020
@coveralls
Copy link

coveralls commented May 15, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 2251be0 on hakonanes:improve-virtual-imaging into 6df76a5 on kikuchipy:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.5%) to 97.523% when pulling a301f24 on hakonanes:improve-virtual-imaging into 6df76a5 on kikuchipy:master.

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes modified the milestones: v0.3.0, v0.2.0 May 18, 2020
@hakonanes hakonanes changed the title Add virtual backscatter electron image generator (thanks, pyxem!) Add virtual backscatter electron image generator May 18, 2020
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes merged commit 3663921 into pyxem:master May 18, 2020
@hakonanes hakonanes deleted the improve-virtual-imaging branch May 18, 2020 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This relates to the documentation enhancement New feature or request tests This relates to the tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants