Closed hakonanes closed 1 year ago
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.
loadtxt()
EBSDDetector.save()
EBSDDetector.load()
EBSDDetector
>>> 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)
__init__.py
CHANGELOG.rst
release.py
.zenodo.json
.all-contributorsrc
Description of the change
This PR adds saving and loading an EBSD detector to/from a text file using NumPy's
loadtxt()
. The methodEBSDDetector.save()
saves to file, while the classmethodEBSDDetector.load()
returns anEBSDDetector
from a text file.Progress of the PR
Minimal example of the bug fix or new feature
For reviewers
__init__.py
.CHANGELOG.rst
.release.py
,.zenodo.json
and.all-contributorsrc
with the table regenerated.