-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
390 lines (316 loc) · 11.2 KB
/
Copy pathmodels.py
File metadata and controls
390 lines (316 loc) · 11.2 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
from __future__ import annotations
import math
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Optional
from pydantic import BaseModel, computed_field, field_validator
"""
=======================================================================================
General Models
=======================================================================================
Models used in multiple workflows.
"""
class Visit(BaseModel):
start: datetime
end: datetime
session_id: int
name: str
beamline: str
proposal_title: str
def __repr__(self) -> str:
return (
"Visit("
f"start='{self.start:%Y-%m-%d %H:%M}', "
f"end='{self.end:%Y-%m-%d %H:%M}', "
f"session_id='{self.session_id!r}',"
f"name={self.name!r}, "
f"beamline={self.beamline!r}, "
f"proposal_title={self.proposal_title!r}"
")"
)
class RegistrationMessage(BaseModel):
registration: str
params: Optional[Dict[str, Any]] = None
class File(BaseModel):
name: str
description: str
size: int
timestamp: datetime
full_path: str
@field_validator("size", mode="before")
@classmethod
def round_file_size_correctly(cls, v: Any) -> int:
if isinstance(v, float):
if v - math.floor(v) == 0.5:
return math.ceil(v)
return round(v)
return v
class ConnectionFileParameters(BaseModel):
filename: str
destinations: List[str]
class ClientInfo(BaseModel):
id: int
class RsyncerInfo(BaseModel):
source: str
destination: str
session_id: int
transferring: bool = True
increment_count: int = 1
bytes: int = 0
increment_data_count: int = 0
data_bytes: int = 0
tag: str = ""
class RsyncerSkippedFiles(BaseModel):
source: str
session_id: int
increment_count: int = 1
class UpstreamFileRequestInfo(BaseModel):
# Used in backend server for cross-instrument file download requests
upstream_instrument: str
upstream_visit_path: Path
"""
=======================================================================================
FIB
=======================================================================================
Models related to the FIB workflow.
"""
class StagePositionValues(BaseModel):
# Coordinates are in metres
x: float | None = None
y: float | None = None
z: float | None = None
# Angles are in degrees
rotation: float | None = None
tilt_alpha: float | None = None
@computed_field
def slot_number(self) -> int | None:
if self.x is None:
return None
return 1 if self.x < 0 else 2
class StagePositionInfo(BaseModel):
"""
Stage position values associated with the different stages of the milling
process. The XML paths they're associated with (with "Site" as the parent
node) are indicated in the comments.
The image acquisition steps have a "SiteLocationType" field that appear to
be associated with either "ChunkSiteLocation" or "ThinningSiteLocation".
"ThinningStagePosition" appears to be a duplicate of "ThinningSiteLocation"
so far, and it is unclear for now what stages "PreparationSiteLocation" and
"ChunkCoincidenceStagePosition" currently correspond to.
"""
# Top-level values
preparation: StagePositionValues | None = (
None # PreparationSiteLocation/StagePosition/StagePosition
)
chunk: StagePositionValues | None = (
None # ChunkSiteLocation/StagePosition/StagePosition
)
thinning_1: StagePositionValues | None = (
None # ThinningSiteLocation/StagePosition/StagePosition
)
# Stored under Parameters
chunk_coincidence: StagePositionValues | None = (
None # Parameters/ChunkCoincidenceStagePosition/StagePosition
)
thinning_2: StagePositionValues | None = (
None # Parameters/ThinningStagePosition/StagePosition
)
class MillingStepInfo(BaseModel):
"""
These are the parameters configured per milling step that we are interested
in tracking. Some attributes are present only for certain steps.
"""
# Step setup
step_name: str | None = None
recipe_name: str | None = None
is_enabled: bool | None = None
status: str | None = None
execution_time: float | None = None
# Associated stage position information
site_location_type: str | None = None
# Beam info
beam_type: str | None = None
voltage: float | None = None
current: float | None = None
# Milling info
milling_angle: float | None = None
depth_correction: float | None = None
lamella_offset: float | None = None
trench_height_front: float | None = None
trench_height_rear: float | None = None
width_overlap_front_left: float | None = None
width_overlap_front_right: float | None = None
width_overlap_rear_left: float | None = None
width_overlap_rear_right: float | None = None
class MillingSteps(BaseModel):
# Processing steps supported by AutoTEM
# Preparation stage
eucentric_tilt: MillingStepInfo | None = None
artificial_features: MillingStepInfo | None = None
milling_angle: MillingStepInfo | None = None
image_acquisition: MillingStepInfo | None = None
lamella_placement: MillingStepInfo | None = None
# Milling stage
delay_1: MillingStepInfo | None = None
reference_definition: MillingStepInfo | None = None
reference_definition_electron: MillingStepInfo | None = None
stress_relief_cuts: MillingStepInfo | None = None
reference_redefinition_1: MillingStepInfo | None = None
rough_milling: MillingStepInfo | None = None
rough_milling_electron: MillingStepInfo | None = None
reference_redefinition_2: MillingStepInfo | None = None
medium_milling: MillingStepInfo | None = None
medium_milling_electron: MillingStepInfo | None = None
fine_milling: MillingStepInfo | None = None
fine_milling_electron: MillingStepInfo | None = None
finer_milling: MillingStepInfo | None = None
finer_milling_electron: MillingStepInfo | None = None
# Thinning stage
delay_2: MillingStepInfo | None = None
polishing_1: MillingStepInfo | None = None
polishing_1_electron: MillingStepInfo | None = None
polishing_2: MillingStepInfo | None = None
polishing_2_ion: MillingStepInfo | None = None
polishing_2_electron: MillingStepInfo | None = None
class LamellaSiteInfo(BaseModel):
"""
Pydantic model that stores all the metadata of interest for a single lamella
site.
"""
# Values not associated with a single step
project_name: str | None = None
site_name: str | None = None
site_number: int | None = None
stage_info: StagePositionInfo | None = None
steps: MillingSteps | None = None
"""
=======================================================================================
Single Particle Analysis
=======================================================================================
Models related to the single-particle analysis workflow.
"""
class ProcessingParametersSPA(BaseModel):
tag: str
dose_per_frame: Optional[float] = None
gain_ref: Optional[str] = None
experiment_type: str
voltage: float
image_size_x: int
image_size_y: int
pixel_size_on_image: str
motion_corr_binning: int
file_extension: str
acquisition_software: str
symmetry: str
eer_fractionation_file: str = ""
magnification: Optional[int] = None
total_exposed_dose: Optional[float] = None
c2aperture: Optional[float] = None
exposure_time: Optional[float] = None
slit_width: Optional[float] = None
phase_plate: bool = False
class Base(BaseModel):
dose_per_frame: Optional[float] = None
gain_ref: Optional[str] = None
symmetry: str
eer_fractionation: int
class GridSquareParameters(BaseModel):
tag: str
image: str = ""
# Actual coordinates for image centre in real space
x_location: Optional[float] = None
y_location: Optional[float] = None
# Coordinates for image centre when overlaid on atlas (in pixels)
x_location_scaled: Optional[int] = None
y_location_scaled: Optional[int] = None
x_stage_position: Optional[float] = None
y_stage_position: Optional[float] = None
# Size of original image (in pixels)
readout_area_x: Optional[int] = None
readout_area_y: Optional[int] = None
# Size of thumbnail used (in pixels)
thumbnail_size_x: Optional[int] = None
thumbnail_size_y: Optional[int] = None
height: Optional[int] = None
width: Optional[int] = None
# Size of image when overlaid on atlas (in pixels)
height_scaled: Optional[int] = None
width_scaled: Optional[int] = None
pixel_size: Optional[float] = None
angle: Optional[float] = None
# Collection mode
collection_mode: Optional[str] = None
class FoilHoleParameters(BaseModel):
tag: str
name: int
x_location: Optional[float] = None
y_location: Optional[float] = None
x_stage_position: Optional[float] = None
y_stage_position: Optional[float] = None
readout_area_x: Optional[int] = None
readout_area_y: Optional[int] = None
thumbnail_size_x: Optional[int] = None
thumbnail_size_y: Optional[int] = None
pixel_size: Optional[float] = None
image: str = ""
diameter: Optional[float] = None
class SearchMapParameters(BaseModel):
tag: str
x_location: Optional[float] = None
y_location: Optional[float] = None
x_stage_position: Optional[float] = None
y_stage_position: Optional[float] = None
pixel_size: Optional[float] = None
image: Optional[str] = None
binning: Optional[float] = None
reference_matrix: Dict[str, float] = {}
stage_correction: Dict[str, float] = {}
image_shift_correction: Dict[str, float] = {}
height: Optional[int] = None
width: Optional[int] = None
height_on_atlas: Optional[int] = None
width_on_atlas: Optional[int] = None
class BatchPositionParameters(BaseModel):
tag: str
x_stage_position: float
y_stage_position: float
x_beamshift: float
y_beamshift: float
search_map_name: str
class MultigridWatcherSetup(BaseModel):
source: Path
destination_overrides: Dict[Path, str] = {}
rsync_restarts: List[str] = []
serialem: bool = False
class Token(BaseModel):
access_token: str
token_type: str
"""
=======================================================================================
Tomography
=======================================================================================
Models related to the tomographic reconstruction workflow.
"""
class ProcessingParametersTomo(BaseModel):
dose_per_frame: Optional[float] = None
frame_count: int
tilt_axis: float
gain_ref: Optional[str] = None
experiment_type: str
voltage: float
image_size_x: int
image_size_y: int
pixel_size_on_image: str
motion_corr_binning: int
file_extension: str
tag: str
tilt_series_tag: str
eer_fractionation_file: Optional[str] = None
eer_fractionation: int
class Base(BaseModel):
dose_per_frame: Optional[float] = None
gain_ref: Optional[str] = None
eer_fractionation: int
class CompletedTiltSeries(BaseModel):
tilt_series: List[str]
rsync_source: str