Coverage for src\pytribeam\constants.py: 100%
91 statements
« prev ^ index » next coverage.py v7.5.1, created at 2025-03-04 17:41 -0800
« prev ^ index » next coverage.py v7.5.1, created at 2025-03-04 17:41 -0800
1#!/usr/bin/python3
3# Default python modules
4import os
5from pathlib import Path
6import time
7import warnings
8import math
9from typing import Dict, NamedTuple, Tuple, List
10import platform
12import pytest
13import numpy as np
14import h5py
16# import pytribeam.utilities as ut
17import pytribeam.types as tbt
20class Constants(NamedTuple):
21 # Software versions
22 module_short_name = "pyTriBeam"
23 autoscript_version = "4.8.1"
24 laser_api_version = "2.2.1"
25 yml_schema_version = "1.0" # max supported version #TODO convert to float
27 # Log file constants
28 logfile_extension = ".h5"
29 settings_dataset_name = "Experiment Settings"
30 pre_position_dataset_name = "Position Before"
31 post_position_dataset_name = "Position After"
32 pre_lasing_dataset_name = "Laser Power Before"
33 post_lasing_dataset_name = "Laser Power After"
34 specimen_current_dataset_name = "Specimen Current"
35 settings_dtype = np.dtype(
36 [
37 ("Slice", "<u4"),
38 ("Step", "<u4"),
39 ("Config File", h5py.special_dtype(vlen=str)),
40 ("Timestamp", h5py.special_dtype(vlen=str)),
41 ("UNIX time", "<u8"),
42 ]
43 )
44 position_dtype = np.dtype(
45 [
46 ("Slice", "<u4"),
47 ("X", "<f8"),
48 ("Y", "<f8"),
49 ("Z", "<f8"),
50 ("T", "<f8"),
51 ("R", "<f8"),
52 ("Timestamp", h5py.special_dtype(vlen=str)),
53 ("UNIX time", "<u8"),
54 ]
55 )
56 laser_power_dtype = np.dtype(
57 [
58 ("Slice", "<u4"),
59 ("Power", "<f8"),
60 ("Timestamp", h5py.special_dtype(vlen=str)),
61 ("UNIX time", "<u8"),
62 ]
63 )
64 specimen_current_dtype = np.dtype(
65 [
66 ("Slice", "<u4"),
67 ("Current", "<f8"),
68 ("Timestamp", h5py.special_dtype(vlen=str)),
69 ("UNIX time", "<u8"),
70 ]
71 )
73 # Beam (electron/ion) constants
74 beam_types = [
75 "electron",
76 "ion",
77 ]
78 voltage_tol_ratio = 0.05
79 current_tol_ratio = 0.05
80 beam_dwell_tol_ratio = 0.001
81 default_color_depth = tbt.ColorDepth.BITS_8
82 scan_resolution_limit = tbt.Limit(min=12, max=65535) # max of 2^16 - 1
84 # Detector constants
85 contrast_brightness_tolerance = 1.0e-4 # range is 0 to 1
87 # Laser constants
88 image_scan_rotation_for_laser_deg = 180.0 # requirement by TFS for laser milling
89 laser_objective_limit_mm = tbt.Limit(min=2.0, max=29.0)
90 laser_objective_retracted_mm = 2.5 # safe retracted position
91 laser_objective_tolerance_mm = 0.005
92 laser_beam_shift_tolerance_um = 0.5
93 laser_energy_tol_uj = 0.05
94 laser_delay_s = 3.0 # for measuring power and settings pulse divider/energy
96 # FIB constants
97 default_fib_rectangle_pattern = tbt.FIBRectanglePattern(
98 center_um=tbt.Point(
99 x=0.0,
100 y=0.0,
101 ),
102 width_um=10.0,
103 height_um=5.0,
104 depth_um=0.1,
105 scan_direction=tbt.FIBPatternScanDirection.TOP_TO_BOTTOM,
106 scan_type=tbt.FIBPatternScanType.RASTER,
107 )
108 stream_pattern_scale = (
109 2**12
110 ) # upscales fib image to this value / width for higher density of points
111 stream_pattern_y_shift = int(
112 2**16 / 6
113 ) # for correct centering of stream patterns, with scan control available only at 16 bit depth, must account for 3:2 aspect ratio for image length:width and cut off half the discrepancy on both top and bottom. Full equation: 2^16(1-(2/3)) / 2
114 stream_pattern_base_dwell_us = 0.025 # can be 25 or 100 ns, defaults to 25ns
116 # Stage constants
117 stage_move_delay_s = 0.5
118 stage_move_attempts = (
119 2 # generally higher accuracy on movement with 2 attempts for non-piezo stages
120 )
121 default_stage_tolerance = tbt.StageTolerance(
122 translational_um=0.5,
123 angular_deg=0.02,
124 )
125 slice_thickness_limit_um = tbt.Limit(min=0.0, max=30.0) # TODO revert to 0.5 micron
126 pre_tilt_limit_deg_generic = tbt.Limit(min=-60.0, max=60.0)
127 pre_tilt_limit_deg_non_Z_sectioning = tbt.Limit(min=0.0, max=0.0)
128 home_position = tbt.StagePositionUser(
129 x_mm=0.0, y_mm=0.0, z_mm=0.0, r_deg=0.0, t_deg=0.0
130 )
131 rotation_axis_limit_deg = tbt.Limit(
132 min=-180.0, max=180.0
133 ) # used as right-open internal: 180.0 is not valid and should be converted to -180.0
134 detector_collisions = [
135 [tbt.DetectorType.CBS, tbt.DetectorType.EDS],
136 [tbt.DetectorType.CBS, tbt.DetectorType.EBSD],
137 ]
139 # Mapping (EBSD/EDS) constants
140 min_map_time_s = 30
141 specimen_current_hfw_mm = 1.0e-3
142 specimen_current_delay_s = 2.0
144 # Test suite constants
145 test_hardware_movement = True
146 offline_machines = [
147 "S1099177",
148 ]
149 microscope_machines = ["HPN125v-MPC", "HPN276-MPC"]
151 # error message display constants
152 default_column_count = 3 # for printing large lists of values
153 default_column_width = 20 # characters
156class Conversions(NamedTuple):
157 # length
158 MM_TO_M = 1.0e-3
159 UM_TO_M = MM_TO_M / 1000.0
160 M_TO_MM = 1.0 / MM_TO_M
161 M_TO_UM = 1.0 / UM_TO_M
162 UM_TO_MM = UM_TO_M * M_TO_MM
163 MM_TO_UM = 1.0 / UM_TO_MM
165 # time
166 US_TO_S = 1.0e-6
167 S_TO_US = 1.0 / US_TO_S
168 S_TO_NS = S_TO_US * 1000.0
169 NS_TO_S = 1.0 / S_TO_NS
170 US_TO_NS = US_TO_S * S_TO_NS
171 NS_TO_US = 1.0 / US_TO_NS
173 # voltage
174 KV_TO_V = 1.0e3
175 V_TO_KV = 1.0 / KV_TO_V
177 # current
178 UA_TO_A = 1.0e-6
179 NA_TO_A = UA_TO_A / 1000.0
180 PA_TO_A = NA_TO_A / 1000.0
181 A_TO_UA = 1.0 / UA_TO_A
182 A_TO_NA = 1.0 / NA_TO_A
183 A_TO_PA = 1.0 / PA_TO_A
184 PA_TO_NA = PA_TO_A * A_TO_NA
185 PA_TO_UA = PA_TO_A * A_TO_UA
186 NA_TO_UA = NA_TO_A * A_TO_UA
187 NA_TO_PA = 1.0 / PA_TO_NA
188 UA_TO_NA = 1.0 / NA_TO_UA
189 UA_TO_PA = 1.0 / PA_TO_UA
191 # angle
192 DEG_TO_RAD = math.pi / 180.0 # convert degrees to radians
193 RAD_TO_DEG = 180.0 / math.pi