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

Refinement Module #387

Merged
merged 60 commits into from Jul 31, 2021
Merged

Refinement Module #387

merged 60 commits into from Jul 31, 2021

Conversation

friedkitteh
Copy link
Collaborator

@friedkitteh friedkitteh commented Jun 24, 2021

Description of the change

Methods to refine:

  1. orientations
  2. projection centers
  3. both simultaneously

The initial orientations are stored in a CrystalMap, with the projection center estimates from an EBSDDetector. The refinement process is made into an optimization problem and uses the user-friendly and efficient numerical routines implemented in scipy.

Progress of the PR

Minimal example of the bug fix or new feature

>>> import kikuchipy as kp
>>> s = kp.data.nickel_ebsd_large(allow_download=True)
>>> s.remove_static_background()
>>> s.remove_dynamic_background()
>>> mp = kp.data.nickel_ebsd_master_pattern_small(projection="lambert", energy=20)
>>> r = sampling.get_sample_fundamental(
... resolution=4, space_group=mp.phase.space_group.number
... )
>>> detector = kp.detectors.EBSDDetector(
... shape=s.axes_manager.signal_shape[::-1],
... pc=[0.421, 0.7794, 0.5049],
... sample_tilt=70,
... convention="tsl",
... )
>>> sim = mp.get_patterns(
... rotations=r,
... detector=detector,
... energy=20,
... dtype_out=s.data.dtype,
... compute=True
... )
>>> xmap = s.dictionary_indexing(sim, n_slices=10, keep_n=10)
>>> refined_xmap = s.orientation_refinement(
... xmap=xmap, 
... master_pattern=mp, 
... detector=detector, 
... energy=20
... )

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 doc/changelog.rst.

Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
Signed-off-by: Lars Lervik <friedkitteh@gmail.com>
@friedkitteh friedkitteh marked this pull request as ready for review July 4, 2021 16:15
@friedkitteh
Copy link
Collaborator Author

Okay! Finally ready for the first review. I will be offline while I relocate and expect to be back online sometime around July 9th.

@hakonanes
Copy link
Member

Great! Good work. It'll be reviewed within then.

@hakonanes
Copy link
Member

I've tried out the functionality on the "large" Ni EBSD data set included in the kikuchipy.data module (user guide) and on the single crystal Si pattern used in the PC calibration moving screen user guide), and based on a qualitative assessment, I'm really stoked about the results!


Normalized cross correlation scores after dictionary indexing to 333 227 simulated Ni patterns (used EMsoft orientation sampling):

Before refinement After refinement
nickel_ebsd_large_di_scores nickel_ebsd_large_di_refined_scores

Histogram of the normalized cross correlation scores shown in the maps above:

nickel_ebsd_large_scores_di_ref


Geometrical simulations of Si as done in the PC calibration user guide ("Reference frames", link above). Note that the initial orientation is determined from TSL, while the PC is solely determined by the moving screen technique. PC in TSL's convention (x*, y*, z*) and the normalized cross correlation score are shown in the figure titles.

Moving screen (0.5123, 0.8606, 0.4981), r = 0.0199 PC refinement (0.5234, 0.8302, 0.4978), r = 0.3675 Orientation and PC refinement (0.5177, 0.8466, 0.4867), r = 0.4090
si_moving_screen_before_pc_refinement si_moving_screen_after_pc_refinement si_moving_screen_after_full_refinement

Quick comments I have, which we should include in this PR, after trying the functionality out are these (note that a thorough review is underway):

  1. Rescaling of experimental patterns to float32 should not be inplace, but of deep copies of them just before they are refined.
  2. I think we should always print the refinement information, like method and desirable parameters, to stdout (in general just your standard print), so that the user, even though they don't care about those, still get the information.

Apart from this I have several other suggestions for improvements, but I think that should be left for later PRs when we start to use the refinement and get a feel for the workflow and what things to store where etc. I suggest we leave updates of the pattern matching notebook to a later PR.

@friedkitteh
Copy link
Collaborator Author

  1. Rescaling of experimental patterns to float32 should not be inplace, but of deep copies of them just before they are refined.

Yep, I 100% agree with you on this.

  1. I think we should always print the refinement information, like method and desirable parameters, to stdout (in general just your standard print), so that the user, even though they don't care about those, still get the information.

Do you mean something like:

Refining 10 000 orientations, using Nelder-Mead with fatol=0.0001, xatol=0.0001, ..., :
[########################################] | 100% Completed

@hakonanes
Copy link
Member

Do you mean something like:

Refining 10 000 orientations, using Nelder-Mead with fatol=0.0001, xatol=0.0001, ..., :
[########################################] | 100% Completed

I was thinking more in the line of what HyperSpy does for their BaseSignal.decomposition() as shown in our multivariate analysis notebook from cell 7.

Copy link
Member

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really excited to try this out some more, great work!

There is a lot here, so this review is just the first of a few, I believe.

In general I agree with the structure and setup, and the requested changes relate more to specific details.

kikuchipy/indexing/__init__.py Outdated Show resolved Hide resolved
kikuchipy/indexing/_refinement.py Outdated Show resolved Hide resolved
kikuchipy/indexing/_refinement.py Outdated Show resolved Hide resolved
kikuchipy/indexing/_refinement.py Outdated Show resolved Hide resolved
kikuchipy/indexing/_refinement.py Outdated Show resolved Hide resolved
kikuchipy/indexing/_refinement.py Outdated Show resolved Hide resolved
kikuchipy/indexing/_refinement.py Show resolved Hide resolved
kikuchipy/signals/ebsd.py Show resolved Hide resolved
kikuchipy/signals/ebsd.py Show resolved Hide resolved
kikuchipy/signals/ebsd.py Outdated Show resolved Hide resolved
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Signed-off-by: Friedkitteh <friedkitteh@gmail.com>
Copy link
Member

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's lots of work in this PR, and the functionality is a huge boost to kikuchipy. Thanks again, @friedkitteh!

I'll create an issue to keep track of suggested changes and minor improvements to refinement which we can do bit by bit in other PRs until a v0.5 release sometime in September.

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.

None yet

2 participants