|
4 | 4 | import logging |
5 | 5 | import time |
6 | 6 | from datetime import datetime |
7 | | -from math import cos |
| 7 | +from pathlib import Path |
8 | 8 |
|
9 | 9 | import numpy as np |
10 | 10 |
|
11 | 11 | from instamatic import config |
| 12 | +from instamatic._typing import AnyPath |
12 | 13 | from instamatic.formats import read_tiff, write_adsc, write_mrc, write_tiff |
13 | 14 | from instamatic.processing.flatfield import apply_flatfield_correction |
| 15 | +from instamatic.processing.PETS_input_factory import PetsInputFactory |
14 | 16 | from instamatic.processing.stretch_correction import affine_transform_ellipse_to_circle |
15 | 17 | from instamatic.tools import ( |
16 | 18 | find_beam_center, |
@@ -131,6 +133,7 @@ def __init__( |
131 | 133 | rotation_axis: float, # radians, specifies the position of the rotation axis |
132 | 134 | acquisition_time: float, # seconds, acquisition time (exposure time + overhead) |
133 | 135 | flatfield: str = 'flatfield.tiff', |
| 136 | + method: str = 'continuous-rotation 3D ED', # or 'stills' or 'precession', used for CIF/documentation |
134 | 137 | ): |
135 | 138 | if flatfield is not None: |
136 | 139 | flatfield, h = read_tiff(flatfield) |
@@ -188,6 +191,7 @@ def __init__( |
188 | 191 | # self.rotation_speed = get_calibrated_rotation_speed(osc_angle / self.acquisition_time) |
189 | 192 |
|
190 | 193 | self.name = 'Instamatic' |
| 194 | + self.method = method |
191 | 195 |
|
192 | 196 | from .XDS_template import ( |
193 | 197 | XDS_template, # hook XDS_template here, because it is difficult to override as a global |
@@ -644,93 +648,36 @@ def write_beam_centers(self, path: str) -> None: |
644 | 648 |
|
645 | 649 | np.savetxt(path / 'beam_centers.txt', centers, fmt='%10.4f') |
646 | 650 |
|
647 | | - def write_pets_inp(self, path: str, tiff_path: str = 'tiff') -> None: |
648 | | - """Write PETS input file `pets.pts` in directory `path`""" |
649 | | - if self.start_angle > self.end_angle: |
650 | | - sign = -1 |
651 | | - else: |
652 | | - sign = 1 |
653 | | - |
654 | | - omega = np.degrees(self.rotation_axis) |
655 | | - |
656 | | - # for pets, 0 <= omega <= 360 |
657 | | - if omega < 0: |
658 | | - omega += 360 |
659 | | - elif omega > 360: |
660 | | - omega -= 360 |
661 | | - |
662 | | - with open(path / 'pets.pts', 'w') as f: |
663 | | - date = str(time.ctime()) |
664 | | - print( |
665 | | - '# PETS input file for Rotation Electron Diffraction generated by `instamatic`', |
666 | | - file=f, |
667 | | - ) |
668 | | - print(f'# {date}', file=f) |
669 | | - print('# For definitions of input parameters, see:', file=f) |
670 | | - print('# http://pets.fzu.cz/ ', file=f) |
671 | | - print('', file=f) |
672 | | - print(f'lambda {self.wavelength}', file=f) |
673 | | - print(f'Aperpixel {self.pixelsize}', file=f) |
674 | | - print(f'phi {float(self.osc_angle) / 2}', file=f) |
675 | | - print(f'omega {omega}', file=f) |
676 | | - print('bin 1', file=f) |
677 | | - print('reflectionsize 20', file=f) |
678 | | - print('noiseparameters 3.5 38', file=f) |
679 | | - print('', file=f) |
680 | | - # print("reconstructions", file=f) |
681 | | - # print("endreconstructions", file=f) |
682 | | - # print("", file=f) |
683 | | - # print("distortions", file=f) |
684 | | - # print("enddistortions", file=f) |
685 | | - # print("", file=f) |
686 | | - print('imagelist', file=f) |
687 | | - for i in self.observed_range: |
688 | | - fn = f'{i:05d}.tiff' |
689 | | - angle = self.start_angle + sign * self.osc_angle * i |
690 | | - print(f'{tiff_path}/{fn} {angle:10.4f} 0.00', file=f) |
691 | | - print('endimagelist', file=f) |
| 651 | + def write_pets_inp(self, path: AnyPath, tiff_path: str = 'tiff') -> None: |
| 652 | + sign = 1 if self.start_angle < self.end_angle else -1 |
| 653 | + omega = np.degrees(self.rotation_axis) % 360 |
692 | 654 |
|
693 | | - def write_pets2_inp(self, path: str, tiff_path: str = 'tiff') -> None: |
694 | | - """Write PETS 2 input file `pets.pts2` in directory `path`""" |
695 | | - path.mkdir(exist_ok=True, parents=True) |
696 | | - |
697 | | - if self.start_angle > self.end_angle: |
698 | | - sign = -1 |
| 655 | + if 'continuous' in self.method: |
| 656 | + geometry = 'continuous' |
| 657 | + elif 'precess' in self.method: |
| 658 | + geometry = 'precession' |
699 | 659 | else: |
700 | | - sign = 1 |
701 | | - |
702 | | - omega = np.degrees(self.rotation_axis) |
| 660 | + geometry = 'static' |
| 661 | + |
| 662 | + p = PetsInputFactory() |
| 663 | + p.add('geometry', geometry) |
| 664 | + p.add('lambda', self.wavelength) |
| 665 | + p.add('Aperpixel', self.pixelsize) |
| 666 | + p.add('phi', float(self.osc_angle) / 2) |
| 667 | + p.add('omega', omega) |
| 668 | + p.add('bin', 1) |
| 669 | + p.add('reflectionsize', 20) |
| 670 | + p.add('noiseparameters', 3.5, 38) |
| 671 | + p.add('') |
| 672 | + |
| 673 | + s = [] |
| 674 | + for i in self.observed_range: |
| 675 | + angle = self.start_angle + sign * self.osc_angle * i |
| 676 | + s.append(f'{tiff_path}/{i:05d}.tiff {angle:10.4f} 0.00') |
| 677 | + p.add('imagelist', *s) |
703 | 678 |
|
704 | | - with open(path / 'pets.pts2', 'w') as f: |
705 | | - date = str(time.ctime()) |
706 | | - print( |
707 | | - '# PETS 2 input file for Rotation Electron Diffraction generated by `instamatic`', |
708 | | - file=f, |
709 | | - ) |
710 | | - print(f'# {date}', file=f) |
711 | | - print('# For definitions of input parameters, see:', file=f) |
712 | | - print('# http://pets.fzu.cz/ ', file=f) |
713 | | - print('', file=f) |
714 | | - print('geometry continuous', file=f) |
715 | | - print(f'lambda {self.wavelength}', file=f) |
716 | | - print(f'Aperpixel {self.pixelsize}', file=f) |
717 | | - print(f'phi {float(self.osc_angle) / 2}', file=f) |
718 | | - print(f'omega {omega}', file=f) |
719 | | - print('bin 1', file=f) |
720 | | - print('reflectionsize 15', file=f) |
721 | | - print('noiseparameters 25 10', file=f) |
722 | | - print('i/sigma 5.00 10.00', file=f) |
723 | | - print('', file=f) |
724 | | - print('imagelist', file=f) |
725 | | - tiff_set = {0} |
726 | | - last_img = len(self.observed_range) |
727 | | - tiff_set.update(self.observed_range) |
728 | | - tiff_set.remove(last_img) |
729 | | - for i in tiff_set: |
730 | | - fn = f'{i:04d}.tiff' |
731 | | - angle = self.start_angle + sign * self.osc_angle * i |
732 | | - print(f'{tiff_path}/{fn} {angle:10.4f} 0.00', file=f) |
733 | | - print('endimagelist', file=f) |
| 679 | + with open(Path(path) / 'pets.pts', 'w') as f: |
| 680 | + f.write(str(p.compile(self.__dict__))) |
734 | 681 |
|
735 | 682 | def write_REDp_shiftcorrection(self, path: str) -> None: |
736 | 683 | """Write .sc (shift correction) file for REDp in directory `path`""" |
|
0 commit comments