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

Make kikuchipy compatible with PyEBSDIndex 0.2 #652

Merged
merged 46 commits into from
Nov 3, 2023

Conversation

hakonanes
Copy link
Member

@hakonanes hakonanes commented Aug 9, 2023

Description of the change

This PR aims at making kikuchipy compatible with just released PyEBSDIndex v0.2.0 and to exploit its many new features. New features of main interest are:

  • Improved PC optimization via particle swarm optimization (PSO), allowing broader search limits in the PC values (default is 0.2 or 20% of the detector dimensions; quite wide!)
  • Hough indexing of all Laue classes (not only FCC or BCC). So far, only FCC and BCC (m-3m), HCP (6/mmm), and the triclinic case (-1) have been tested.

kikuchipy v0.8.* has PyEBSDIndex as an optional dependency with a compatible release specification (~= 0.1.2), so people installing this release from PyPI will only get PyEBSDIndex v0.1.2. However, our conda-forge feedstock only asks for >= 0.1.2... People installing from conda-forge will most likely get PyEBSDIndex v0.2.0, which does not work with the current kikuchipy release. A big problem. So we should get this merged and released as 0.9.0 quickly. I plan to get this done within Tuesday next week.

Progress of the PR

What we should do but perhaps don't have time:

  • [ ] Add patterns from crystals having symmetries from all Laue classes to the data module
  • [ ] Test HI of these new patterns
  • [ ] Add examples showing how to index each of these patterns to the docs

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>
…d PSO from PyEBSDIndex 0.2

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 bug Something isn't working enhancement New feature or request documentation This relates to the documentation labels Aug 9, 2023
@hakonanes hakonanes added this to the v0.9.0 milestone Aug 9, 2023
@hakonanes hakonanes marked this pull request as draft August 9, 2023 15:11
@hakonanes hakonanes mentioned this pull request Aug 9, 2023
4 tasks
@CSSFrancis
Copy link
Member

@hakonanes Have you considered adding https://github.com/apps/review-notebook-app to kikchipy. It is fairly good at showing diffs for jupyter notebooks?

I can review this if you want someone to (superficially) look at the changes.

@hakonanes
Copy link
Member Author

Thanks for the suggestions, @CSSFrancis. I'll consider ReviewNB. I'll ask you for a review once the PR's ready!

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 support-pyebsdindex-0-2 branch from 0f354b5 to 8c9b16a Compare October 25, 2023 17:24
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
… of phase lists compatibility

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>
…e syntax

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes marked this pull request as ready for review November 1, 2023 16: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>
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
Copy link
Member Author

@CSSFrancis, this work is ready for merging. If you want to have a quick look, that would be very much appreciated! I plan to merge tomorrow Friday.

I'll get to reviewing and answering your stuff in orix, diffsims, and pyxem shortly!

The only outward API changes are the possibility to (listed in the changelog):

  • pass a reflector list per phase for use in Hough indexing
  • pass parameters for particle swarm optimization (PSO) of projection/pattern center (detector-sample geometry calibration)
  • optimizing one projection center at a time with PSO

Other changes:

  • Tutorial notebooks: use improvements to optimization and indexing accuracy in PyEBSDIndex v0.2; improve explanations of many steps and analyses.
  • Replace interactive EBSD master pattern 3D plot with a static plot in tutorials for visualization and kinematic simulations. This was needed because PyVista have discontinued support for the Jupyter backend we used, Panel. The currently supported Jupyter backends cannot provide interactive 3D plots. But they're working on it!

@hakonanes
Copy link
Member Author

And thank you for suggesting ReviewNB. It sure beats me comparing the changes to rendered tutorial pages in current docs and the newly built docs from a PR by eye!

Copy link
Member

@CSSFrancis CSSFrancis left a comment

Choose a reason for hiding this comment

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

@hakonanes The code looks good here! I'll try and go through the Jupyter notebooks as well. I added a couple of suggestions, but none of them are things that would stop this from merging. Seems like a good addition!

Comment on lines +1609 to +1610
List of phases. The list must correspond to the phase list
in the passed.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
List of phases. The list must correspond to the phase list
in the passed.
List of phases. The list must correspond to the passed phase list argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Our code style says:

Comment lines should preferably be limited to 72 characters.

I consider docstrings to be comment lines. I'll update this sentence in the docs to make this clearer.

Comment on lines +1676 to +1680
# Check indexer (but not the reflectors)
_ = _indexer_is_compatible_with_kikuchipy(
indexer, sig_shape, nav_size, raise_if_not=True
)
if indexer.phaselist != phase_list_pei:
raise ValueError(
f"`indexer.phaselist` {indexer.phaselist} and the list determined from"
f" `phase_list` {phase_list_pei} must be the same"
)
_ = _phase_lists_are_compatible(phase_list, indexer, raise_if_not=True)
Copy link
Member

Choose a reason for hiding this comment

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

If these functions take any decent time you could consider caching the results but if they are quick I wouldn't worry about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

An IPython %timeit returned:

  • _indexer_is_compatible_with_kikuchipy(): 1.61 us +/- 264 ns
  • _phase_lists_are_compatible(): 54 us +/- 1.51 us

These Hough indexing methods of the EBSD class are not meant to be called hunderds of times in a loop, so I think this is OK.

@@ -53,6 +50,9 @@ jobs:
name: ${{ matrix.os }}-py${{ matrix.python-version }}${{ matrix.LABEL }}
runs-on: ${{ matrix.os }}
timeout-minutes: 15
env:
MPLBACKEND: agg
PYTEST_ARGS: --pyargs kikuchipy --reruns 2 -n 2 --cov=kikuchipy
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific test or reason to add in the reruns? It might be better to just add the @pytest.mark.flaky(reruns=2) to the tests which are flaky and might fail?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the reason was a flaky test on a macOS run (here). The test check availability of datasets on Zenodo. I've experienced some flaky-ness in the past, so I figured this change was overdue.

Co-authored-by: Carter Francis <csfrancis@wisc.edu>
@hakonanes
Copy link
Member Author

hakonanes commented Nov 2, 2023

Now that you've both reviewed and contributed to the docs, is it OK if I add you to the package credits? This includes the kikuchipy/release.py file, the all-contributors table in the README, and in the Zenodo file. You'll be listed as "Carter Francis" with the following entry in the Zenodo file

   {
      "name": "Carter Francis",
      "orcid": "0000-0003-2564-1851",
      "affiliation": "University of Wisconsin Madison"
    },

…2 characters

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
Copy link
Member Author

I plan to release 0.9.0 once this PR is merged and some other smaller things are done 🚀

@CSSFrancis
Copy link
Member

Now that you've both reviewed and contributed to the docs, is it OK if I add you to the package credits? This includes the kikuchipy/release.py file, the all-contributors table in the README, and in the Zenodo file. You'll be listed as "Carter Francis" with the following entry in the Zenodo file


   {

      "name": "Carter Francis",

      "orcid": "0000-0003-2564-1851",

      "affiliation": "University of Wisconsin Madison"

    },

Yea that works for me :)

@hakonanes hakonanes merged commit 7e0425a into pyxem:develop Nov 3, 2023
10 checks passed
@hakonanes hakonanes deleted the support-pyebsdindex-0-2 branch November 3, 2023 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation This relates to the documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants