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 saving and loading an EBSD detector to/from a text file #595

Merged
merged 3 commits into from
Jan 23, 2023

Conversation

hakonanes
Copy link
Member

Description of the change

This PR adds saving and loading an EBSD detector to/from a text file using NumPy's loadtxt(). The method EBSDDetector.save() saves to file, while the classmethod EBSDDetector.load() returns an EBSDDetector from a text file.

Progress of the PR

Minimal example of the bug fix or new feature

>>> import kikuchipy as kp
>>> det = kp.detectors.EBSDDetector(shape=(60, 60), pc=[0.3, 0.2, 0.6])
>>> det
EBSDDetector (60, 60), px_size 1 um, binning 1, tilt 0, azimuthal 0, pc (0.3, 0.2, 0.6)
>>> fname = "det.txt"
>>> det.save(fname, convention="tsl", fmt="%.5f")
>>> header = []
>>> with open(fname, mode="r") as f:
>>>     for line in f.readlines():
>>>         if line.startswith("#"):
>>>             header.append(line)
>>>         else:
>>>             break
>>> header
['# EBSDDetector\n',
 '#   shape: (60, 60)\n',
 '#   px_size: 1\n',
 '#   binning: 1\n',
 '#   tilt: 0 deg\n',
 '#   azimuthal: 0 deg\n',
 '#   sample_tilt: 70 deg\n',
 '#   convention: tsl\n',
 '#   navigation_shape: (1,)\n',
 '# \n',
 '# kikuchipy version: 0.8.dev0\n',
 '# Time: 2023-01-23 13:04:34\n',
 '# \n',
 '# Column names: PCx, PCy, PCz\n']
>>> det2 = kp.detectors.EBSDDetector.load(fname)
>>> det2
EBSDDetector (60, 60), px_size 1 um, binning 1, tilt 0, azimuthal 0, pc (0.3, 0.2, 0.6)

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>
@hakonanes hakonanes added the enhancement New feature or request label Jan 23, 2023
@hakonanes hakonanes added this to the v0.8.0 milestone Jan 23, 2023
@hakonanes hakonanes merged commit fed8f05 into pyxem:develop Jan 23, 2023
@hakonanes hakonanes deleted the ebsd-detector-save-load branch January 23, 2023 12:19
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