|
6 | 6 | from typing import Callable, Generator, Optional, Tuple |
7 | 7 |
|
8 | 8 | import numpy as np |
| 9 | +import yaml |
9 | 10 |
|
10 | 11 | from instamatic import config |
11 | 12 | from instamatic.camera import Camera |
|
15 | 16 | from instamatic.image_utils import rotate_image |
16 | 17 | from instamatic.microscope import components |
17 | 18 | from instamatic.microscope.base import MicroscopeBase |
| 19 | +from instamatic.microscope.components.deflectors import DeflectorTuple |
18 | 20 | from instamatic.microscope.microscope import get_microscope |
19 | 21 |
|
20 | 22 | _ctrl = None # store reference of ctrl so it can be accessed without re-initializing |
@@ -795,17 +797,14 @@ def store(self, name: str = 'stash', keys: tuple = None, save_to_file: bool = Fa |
795 | 797 | Multiple settings can be stored under different names. Specify |
796 | 798 | which settings should be stored using `keys` |
797 | 799 | """ |
798 | | - if not keys: |
799 | | - keys = () |
800 | | - d = self.to_dict(*keys) |
| 800 | + d = self.to_dict(*keys if keys else ()) |
801 | 801 | d.pop('StagePosition', None) |
802 | 802 | self._saved_alignments[name] = d |
803 | 803 |
|
804 | 804 | if save_to_file: |
805 | | - import yaml |
806 | | - |
807 | 805 | fn = config.alignments_drc / (name + '.yaml') |
808 | | - yaml.dump(d, stream=open(fn, 'w')) |
| 806 | + d2 = {k: list(v) if isinstance(v, DeflectorTuple) else v for k, v in d.items()} |
| 807 | + yaml.safe_dump(d2, stream=open(fn, 'w')) |
809 | 808 | print(f'Saved alignment to file `{fn}`') |
810 | 809 |
|
811 | 810 | def restore(self, name: str = 'stash'): |
|
0 commit comments