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 EMsoft ECP/TKD master pattern readers, improve handling of custom properties #564

Merged
merged 21 commits into from
Sep 22, 2022

Conversation

hakonanes
Copy link
Member

@hakonanes hakonanes commented Sep 21, 2022

Description of the change

This PR adds readers for EMsoft's ECP and TKD master patterns. The former returns a new ECPMasterPattern signal, which is similar to EBSDMasterPattern without get_patterns(), while the latter returns a EBSDMasterPattern.

In the process of generalizing the master pattern class, I reimplemented the private CommonImage class in KikuchipySignal2D and LazyKikuchipySignal2D . The new class handles custom properties (not in HyperSpy), like EBSD.static_background() and EBSDMasterPattern.phase, and wraps calls to methods as_lazy(), change_dtype(), compute(), squeeze() and deepcopy() so that these properties carry over to or are removed in new signals as appropriate. All custom properties are also carried over when switching between ECPMasterPattern and EBSDMasterPattern using set_signal_type().

Finally, logging is added via kikuchipy.set_log_level() (same as in HyperSpy), since I needed this to debug the wrapped Signal2D methods mentioned above.

Replaces #476.

Closes #512, #386 and #16.

Progress of the PR

Minimal example of the bug fix or new feature

>>> import numpy as np
>>> import dask.array as da
>>> import kikuchipy as kp

# Set log level to DEBUG to show new messages added in KikuchipySignal2D

>>> kp.set_log_level("DEBUG")
>>> s = kp.data.nickel_ebsd_small()
>>> s2 = s.deepcopy()
DEBUG:kikuchipy.signals._kikuchipy_signal:Transfer custom properties when deep copying
>>> np.may_share_memory(s.static_background, s2.static_background()
False
>>> kp.set_log_level("WARNING")

# Static background is handled correctly

>>> isinstance(s.static_background, np.ndarray)
True
>>> s3 = s.as_lazy()
>>> isinstance(s3.static_background, da.Array)
True
>>> s3.compute()
[########################################] | 100% Completed | 100.36 ms
>>> isinstance(s3.static_background, np.ndarray)
True
>>> print(s.data.dtype, s.static_background.dtype)
uint8 uint8
>>> s.change_dtype("float32")
>>> print(s.data.dtype, s.static_background.dtype)
float32 float32

# Switching between master patterns carries over properties

>>> mp = kp.data.nickel_ebsd_master_pattern_small()
>>> mp
<EBSDMasterPattern, title: ni_mc_mp_20kv_uint8_gzip_opts9, dimensions: (|401, 401)>
>>> mp.phase
<name: ni. space group: Fm-3m. point group: m-3m. proper point group: 432. color: tab:blue>
>>> mp.set_signal_type("ECPMasterPattern")
>>> mp
<ECPMasterPattern, title: ni_mc_mp_20kv_uint8_gzip_opts9, dimensions: (|401, 401)>
>>> mp.phase
<name: ni. space group: Fm-3m. point group: m-3m. proper point group: 432. color: tab:blue>

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 and .all-contributorsrc and the table
    is 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>
…tom properties

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>
…dling

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>
…done

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes merged commit 41b2409 into pyxem:develop Sep 22, 2022
@hakonanes hakonanes deleted the ecp-tkd-master-pattern-reader branch September 22, 2022 10:04
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
1 participant