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 EBSD.static_background property storing static background pattern #475

Merged
merged 5 commits into from
Nov 23, 2021

Conversation

hakonanes
Copy link
Member

Description of the change

Part of the effort to remove custom metadata from EBSD.metadata (#466).

  • Adds a EBSD.static_background property that is None by default, unless a static background could be successfully read from file. This is only the case for Bruker and kikuchipy h5ebsd files and the NORDIF binary file (when background pattern is stored in the same directory as Pattern.dat with the standard name as .bmp file). The property is settable, and a warning (not an error) is raised if the NumPy or Dask array's shape or data type is different from the signal's shape or data type.
  • API reference and user guide updated accordingly.
  • A warning is added to the user guide (cropping and load/save notebooks) informing the user that the xmap, detector and static_background EBSD properties aren't updated whenever a HyperSpy inherited method that changes the pattern shape and/or data type is called (like inav, isig, rebin etc.). This addresses issues raised in EBSD.xmap property needs vast improvements #227 and Rethinking the EBSD.detector attribute #277 by letting it be up to the user to update the properties...

Progress of the PR

Minimal example of the bug fix or new feature

>>> import numpy as np
>>> import kikuchipy as kp
>>> s = kp.data.nickel_ebsd_small()
>>> s
<EBSD, title: patterns My awes0m4 ..., dimensions: (3, 3|60, 60)>
>>> s.static_background
array([[84, 87, 90, ..., 27, 29, 30],
       [87, 90, 93, ..., 27, 28, 30],
       [92, 94, 97, ..., 39, 28, 29],
       ...,
       [80, 82, 84, ..., 36, 30, 26],
       [79, 80, 82, ..., 28, 26, 26],
       [76, 78, 80, ..., 26, 26, 25]], dtype=uint8)
>>> s.static_background = s.static_background.astype(np.uint16)
/home/hakon/kode/kikuchipy/kikuchipy/signals/ebsd.py:171: UserWarning: Background pattern has different data type from patterns
  warnings.warn("Background pattern has different data type from patterns")
>>> s2 = s.as_lazy()
>>> s2.static_background
dask.array<array, shape=(60, 60), dtype=uint16, chunksize=(60, 60), chunktype=numpy.ndarray>
>>> s2.compute()
[########################################] | 100% Completed |  0.1s
>>> s2.static_background
array([[84, 87, 90, ..., 27, 29, 30],
       [87, 90, 93, ..., 27, 28, 30],
       [92, 94, 97, ..., 39, 28, 29],
       ...,
       [80, 82, 84, ..., 36, 30, 26],
       [79, 80, 82, ..., 28, 26, 26],
       [76, 78, 80, ..., 26, 26, 25]], dtype=uint16)
>>> s2.remove_static_background()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/hakon/kode/kikuchipy/kikuchipy/signals/ebsd.py", line 548, in remove_static_background
    raise ValueError(
ValueError: Static background dtype_out uint16 is not the same as pattern dtype_out <class 'numpy.uint8'>
>>> s2.static_background = s2.static_background.astype(np.uint8)
>>> s2.remove_static_background()
[########################################] | 100% Completed |  0.2s

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 .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>
@hakonanes hakonanes added the enhancement New feature or request label Nov 23, 2021
@hakonanes hakonanes added this to the v0.6.0 milestone Nov 23, 2021
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes
Copy link
Member Author

Will merge after checks pass.

@hakonanes hakonanes merged commit bb71c76 into pyxem:develop Nov 23, 2021
@hakonanes hakonanes deleted the add-static-background-property branch November 23, 2021 14:12
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

1 participant