forked from instamatic-dev/instamatic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImgConversionTPX.py
More file actions
91 lines (68 loc) · 3.47 KB
/
Copy pathImgConversionTPX.py
File metadata and controls
91 lines (68 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from __future__ import annotations
from .ImgConversion import *
class ImgConversionTPX(ImgConversion):
"""This class is for post RED/cRED data collection image conversion. Files
can be generated for REDp, DIALS, XDS, and PETS.
The image buffer is passed as a list of tuples, where each tuple
contains the index (int), image data (2D numpy array),
metadata/header (dict). The buffer index must start at 1.
"""
def __init__(
self,
buffer: list, # image buffer, list of (index [int], image data [2D numpy array], header [dict])
osc_angle: float, # degrees, oscillation angle of the rotation
start_angle: float, # degrees, start angle of the rotation
end_angle: float, # degrees, end angle of the rotation
rotation_axis: float, # radians, specifies the position of the rotation axis
acquisition_time: float, # seconds, acquisition time (exposure time + overhead)
flatfield: str = 'flatfield.tiff',
pixelsize: float = None, # p/Angstrom, size of the pixels (overrides camera_length)
physical_pixelsize: float = None, # mm, physical size of the pixels (overrides camera length)
wavelength: float = None, # Angstrom, relativistic wavelength of the electron beam
stretch_amplitude=0.0, # Stretch correction amplitude, %
stretch_azimuth=0.0, # Stretch correction azimuth, degrees
method: str = 'continuous-rotation 3D ED', # or 'stills' or 'precession', used for CIF/documentation
):
if flatfield is not None:
flatfield, h = read_tiff(flatfield)
self.flatfield = flatfield
self.headers = {}
self.data = {}
self.smv_subdrc = 'data'
self.untrusted_areas = [
('rectangle', ((0, 255), (517, 262))),
('rectangle', ((255, 0), (262, 517))),
]
while len(buffer) != 0:
i, img, h = buffer.pop(0)
self.headers[i] = h
if self.flatfield is not None:
self.data[i] = apply_flatfield_correction(img, self.flatfield)
else:
self.data[i] = img
self.observed_range = set(self.data.keys())
self.complete_range = set(range(min(self.observed_range), max(self.observed_range) + 1))
self.missing_range = self.observed_range ^ self.complete_range
self.data_shape = img.shape
self.pixelsize = pixelsize
self.physical_pixelsize = physical_pixelsize
self.wavelength = wavelength
self.use_beamstop = False
self.mean_beam_center, self.beam_center_std = self.get_beam_centers()
# Stretch correction parameters
self.stretch_azimuth = config.camera.stretch_azimuth
self.stretch_amplitude = config.camera.stretch_amplitude
self.do_stretch_correction = self.stretch_amplitude != 0
self.distance = (1 / self.wavelength) * (self.physical_pixelsize / self.pixelsize)
self.osc_angle = osc_angle
self.start_angle = start_angle
self.end_angle = end_angle
self.rotation_axis = rotation_axis
self.acquisition_time = acquisition_time
# self.rotation_speed = get_calibrated_rotation_speed(osc_angle / self.acquisition_time)
logger.debug(f'Primary beam at: {self.mean_beam_center}')
self.name = 'TimePix_SU'
self.method = method
from .XDS_template import XDS_template_TPX as XDS_template
self.XDS_template = XDS_template
self.check_settings()