/
fei_tecnai_microscope.py
744 lines (576 loc) · 28.2 KB
/
fei_tecnai_microscope.py
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
import atexit
import logging
import time
import comtypes.client
from math import pi
from instamatic.exceptions import FEIValueError, TEMCommunicationError
from instamatic import config
_FUNCTION_MODES = {1: 'lowmag', 2: 'mag1', 3: 'samag', 4: 'mag2', 5: 'LAD', 6: 'diff'}
#diff=D, LAD=LAD, lowmag=LM, mag1=Mi, samag=SA, mag2=Mh in Functionmodes
#dict([('D', [0.0265, 0.035, 0.044, 0.062, 0.071, 0.089, 0.135, 0.175, 0.265, 0.43, 0.6, 0.86, 1.65, 2.65, 3.5, 4.1]),
# ('LAD', [4.5, 7.1, 9, 12.5, 18, 27, 36, 53, 71, 81, 130, 180, 245, 360, 530, 720, 790, 810, 960, 1100, 1300]),
# ('LM', [19, 25, 35, 50, 65, 82, 105, 145, 200, 300, 390, 500, 730, 980, 1350, 1850]),
# ('Mi', [2250, 3500, 4400]),
# ('SA', [6200, 8700, 13500, 17000, 26000, 34000, 38000, 63000, 86000, 125000, 175000, 250000, 350000, 400000]),
# ('Mh', [440000, 520000, 610000, 700000, 780000, 910000])])
class TecnaiMicroscope:
"""Python bindings to the Tecnai-G2 microscope using the COM scripting interface."""
def __init__(self, name:str=None):
try:
comtypes.CoInitializeEx(comtypes.COINIT_MULTITHREADED)
except OSError:
comtypes.CoInitialize()
print('FEI Scripting initializing...')
## TEM interfaces the GUN, stage etc
self._tem = comtypes.client.CreateObject('TEMScripting.Instrument', comtypes.CLSCTX_ALL)
## TEM enum constants
self._tem_constant = comtypes.client.Constants(self._tem)
self._t = 0
while True:
ht = self._tem.GUN.HTValue
if ht > 0:
break
time.sleep(1)
self._t += 1
if self._t > 3:
print('Waiting for microscope, t = %ss' % (_t))
if self._t > 30:
raise TEMCommunicationError('Cannot establish microscope connection (timeout).')
self._logger = logging.getLogger(__name__)
self._logger.info('Microscope connection established')
#close the network connection
atexit.register(self.release_connection)
self.name = name
self._conf = config(self.name)
self._mic_ranges = None
if self._conf.micr_interface == 'tecnai':
self._mic_ranges = self._conf.micr_ranges
self._rotation_speed = 1.0
self._tecnaiStage = TecnaiStageThread() #Thread für a-Movement
self._goniotool_available = False
###Stage-Functions
def getHolderType(self) -> int:
"""Return TEM-Holder type as enum constant."""
return self._tem.Stage.Holder
def getStagePosition(self) -> [float, float, float, float, float]:
"""Return Stageposition x, y, z in microns and alpha(a), beta(b) in degs."""
x = self._tem.Stage.Position.X * 1e6
y = self._tem.Stage.Position.Y * 1e6
z = self._tem.Stage.Position.Z * 1e6
A = self._tem.Stage.Position.A / pi * 180
B = self._tem.Stage.Position.B / pi * 180
return x, y, z, A, B
def getStageSpeed(self) -> float:
"""Return Stagespeed, can not be read on Tecnai = constant(0.5)."""
print('StageSpeed can not be read on Tecnai')
return 0.5
def is_goniotool_available(self) -> bool:
"""Return goniotool status, always False."""
return self._goniotool_available
def isAThreadAlive(self) -> bool:
"""Return goniotool status, always False."""
if self._tecnaiStage.is_alive():
return True
else:
return False
def isStageMoving(self) -> bool:
"""is Stage moving?, False if the Stage is ready, else it is True."""
if self._tem.Stage.Status != self._tem_constant.StageStatus['stReady']:
return True
pos1 = self.getStagePosition()
time.sleep(0.3)
pos2 = self.getStagePosition()
for i in range(len(pos1)):
diff = abs(pos1[i] - pos2[i])
#z-Value, gap of 0.4micrometer is okay
if (i == 2) and diff >= 0.4:
return True
#a, b-Value, gap of 0.1degree is okay
elif (3 <= i <= 4) and diff >= 0.1:
return True
return False
def setStagePosition(self, x: float=None, y: float=None, z: float=None, a: float=None, b: float=None, wait: bool=True, speed: float=1.0) -> None:
"""Set the Stageposition x, y, z in microns and alpha(a), beta(b) in degs."""
pos = self._tem.Stage.Position
axis = 0
enable_stage = False
enable_B = False
if (speed > 1.0) or (speed <= 0.0):
speed = 1.0
if self._tem.Stage.Holder in ( self._tem_constant.StageHolderType['hoSingleTilt'], self._tem_constant.StageHolderType['hoDoubleTilt'] ):
enable_stage = True
if self._tem.Stage.Holder == self._tem_constant.StageHolderType['hoDoubleTilt']:
enable_B = True
if x is not None and enable_stage:
pos.X = x * 1e-6
axis = axis | self._tem_constant.StageAxes['axisX']
if y is not None and enable_stage:
pos.Y = y * 1e-6
axis = axis | self._tem_constant.StageAxes['axisY']
if z is not None and enable_stage:
pos.Z = z * 1e-6
axis = axis | self._tem_constant.StageAxes['axisZ']
if a is not None and enable_stage:
pos.A = a / 180 * pi
axis = axis | self._tem_constant.StageAxes['axisA']
if b is not None and enable_B:
pos.B = b / 180 * pi
axis = axis | self._tem_constant.StageAxes['axisB']
if wait == True:
if axis != 0:
if speed == 1.0:
if (axis == self._tem_constant.StageAxes['axisA']) and (self._rotation_speed != 1.0):
self._tem.Stage.GoToWithSpeed(pos, axis, self._rotation_speed)
else:
self._tem.Stage.GoTo(pos, axis)
else:
self._tem.Stage.GoToWithSpeed(pos, axis, speed)
self.waitForStage()
elif (wait == False) and (self._tecnaiStage.is_alive() is False):
if (axis == self._tem_constant.StageAxes['axisA']):
#start Rotation in separate Thread and go on
stagePos = [pos.X, pos.Y, pos.Z, pos.A, pos.B]
self._tecnaiStage = TecnaiStageThread(self._tem, stagePos, axis, speed)
self._tecnaiStage.daemon=True
self._tecnaiStage.start()
#self._tem.Stage.GoToWithSpeed(pos, axis, 0.01) => 1grad in 4-5sec.
def setStageX(self, value: float=None, wait: bool=True) -> None:
"""Set the Stageposition x in microns."""
"""wait has no meaning, Jeol-API"""
pos = self._tem.Stage.Position
axis = 0
enable_stage = False
if self._tem.Stage.Holder in ( self._tem_constant.StageHolderType['hoSingleTilt'], self._tem_constant.StageHolderType['hoDoubleTilt'] ):
enable_stage = True
if value is not None:
pos.X = value * 1e-6
axis = self._tem_constant.StageAxes['axisX']
if enable_stage:
self._tem.Stage.GoTo(pos, axis)
self.waitForStage()
def setStageY(self, value: float=None, wait: bool=True) -> None:
"""Set the Stageposition y in microns."""
"""wait has no meaning, Jeol-API"""
pos = self._tem.Stage.Position
axis = 0
enable_stage = False
if self._tem.Stage.Holder in ( self._tem_constant.StageHolderType['hoSingleTilt'], self._tem_constant.StageHolderType['hoDoubleTilt'] ):
enable_stage = True
if value is not None:
pos.Y = value * 1e-6
axis = self._tem_constant.StageAxes['axisY']
if enable_stage:
self._tem.Stage.GoTo(pos, axis)
self.waitForStage()
def setStageZ(self, value: float=None, wait: bool=True) -> None:
"""Set the Stageposition z in microns."""
"""wait has no meaning, Jeol-API"""
pos = self._tem.Stage.Position
axis = 0
enable_stage = False
if self._tem.Stage.Holder in ( self._tem_constant.StageHolderType['hoSingleTilt'], self._tem_constant.StageHolderType['hoDoubleTilt'] ):
enable_stage = True
if value is not None:
pos.Z = value * 1e-6
axis = self._tem_constant.StageAxes['axisZ']
if enable_stage:
self._tem.Stage.GoTo(pos, axis)
self.waitForStage()
def setStageXY(self, x: float=None, y: float=None, wait: bool=True) -> None:
"""Set the Stageposition x, y in microns."""
"""wait has no meaning, Jeol-API"""
pos = self._tem.Stage.Position
axis = 0
enable_stage = False
if self._tem.Stage.Holder in ( self._tem_constant.StageHolderType['hoSingleTilt'], self._tem_constant.StageHolderType['hoDoubleTilt'] ):
enable_stage = True
if x is not None:
pos.X = x * 1e-6
axis = axis | self._tem_constant.StageAxes['axisX']
if y is not None:
pos.Y = y * 1e-6
axis = axis | self._tem_constant.StageAxes['axisY']
if enable_stage:
self._tem.Stage.GoTo(pos, axis)
self.waitForStage()
def setStageA(self, value: float=None, wait: bool=True) -> None:
"""Set the Stageposition alpha (A) in degrees."""
pos = self._tem.Stage.Position
axis = 0
enable_stage = False
if self._tem.Stage.Holder in ( self._tem_constant.StageHolderType['hoSingleTilt'], self._tem_constant.StageHolderType['hoDoubleTilt'] ):
enable_stage = True
if value is not None:
pos.A = value / 180 * pi
axis = self._tem_constant.StageAxes['axisA']
if enable_stage:
if wait == True:
self._tem.Stage.GoToWithSpeed(pos, axis, self._rotation_speed)
self.waitForStage()
elif (wait == False) and (self._tecnaiStage.is_alive() is False):
#start Rotation in separate Thread and go on
stagePos = [pos.X, pos.Y, pos.Z, pos.A, pos.B]
self._tecnaiStage = TecnaiStageThread(self._tem, stagePos, axis, self._rotation_speed)
self._tecnaiStage.daemon=True
self._tecnaiStage.start()
def setStageB(self, value: float=None, wait: bool=True) -> None:
"""Set the Stageposition beta (B) in degrees."""
"""wait has no meaning, Jeol-API"""
pos = self._tem.Stage.Position
axis = 0
enable_B = False
if self._tem.Stage.Holder == self._tem_constant.StageHolderType['hoDoubleTilt']:
enable_B = True
if value is not None:
pos.B = value / 180 * pi
axis = self._tem_constant.StageAxes['axisB']
if enable_B:
self._tem.Stage.GoTo(pos, axis)
self.waitForStage()
def waitForStage(self, delay: float=0.1) -> None:
"""helper function to wait, until the stage movement is finished."""
while self._tem.Stage.Status is not self._tem_constant.StageStatus['stReady']:
if delay > 0:
time.sleep(delay)
def setStageSpeed(self, value: float) -> None:
"""Set Stage speed, not available on Tecnai."""
print('StageSpeed can not be set on Tecnai')
def stopStage(self) -> None:
"""Stop Stage, not available on Tecnai."""
print('stopStage: not available on Tecnai.')
def setRotationSpeed(self, value: float) -> None:
"""Set rotationspeed of the alpha rotation."""
if 0.0 < value <= 1.0:
self._rotation_speed = value
def getRotationSpeed(self) -> float:
"""get the rotation speed of the alpha rotation"""
return self._rotation_speed
###Gun
def getGunShift(self) -> (float, float):
"""get the Gun-Shift values."""
return self._tem.GUN.Shift.X, self._tem.GUN.Shift.Y
def setGunShift(self, x: float, y: float) -> None:
"""set the Gun-Shift values, should be a number between -1 and 1."""
if abs(x) > 1 or abs(y) > 1:
raise FEIValueError('GunShift x/y must be a floating number between -1 an 1. Input: x=%s, y=%s' % (x, y))
gs = self._tem.GUN.Shift
if x is not None:
gs.X = x
if y is not None:
gs.Y = y
self._tem.GUN.Shift = gs
def getGunTilt(self) -> (float, float):
"""get the Gun-Tilt values."""
return self._tem.GUN.Tilt.X, self._tem.GUN.Tilt.Y
def setGunTilt(self, x: float, y: float) -> None:
"""set the Gun-Tilt values, should be a number between -1 and 1."""
if abs(x) > 1 or abs(y) > 1:
raise FEIValueError('GunTilt x/y must be a floating number between -1 an 1. Input: x=%s, y=%s' % (x, y))
gt = self._tem.Gun.Tilt
if x is not None:
gt.X = x
if y is not None:
gt.Y = y
self._tem.Gun.Tilt = gt
def getHTValue(self) -> int:
"""get the HT-value."""
return self._tem.GUN.HTValue
def setHTValue(self, htvalue: int) -> None:
"""set the HT-value."""
self._tem.GUN.HTValue = htvalue
def isBeamBlanked(self) -> bool:
"""is the Beam blanked? -> True/False."""
return self._tem.Illumination.BeamBlanked
def setBeamBlank(self, value: bool) -> None:
"""Blank the Beam: True/False."""
if isinstance(value, bool):
self._tem.Illumination.BeamBlanked = value
def setBeamUnblank(self) -> None:
"""unblank the Beam."""
self._tem.Illumination.BeamBlanked = False
def setNeutral(self, *args) -> None:
"""Neutralize all deflectors."""
self._tem.Projection.Normalize(self._tem_constant.ProjectionNormalization['pnmAll'])
self._tem.Illumination.Normalize(self._tem_constant.IlluminationNormalization['nmAll'])
time.sleep(4)
def getBeamAlignShift(self) -> (float, float):
"""get the Gun-Shift values."""
return self.getGunShift()
def setBeamAlignShift(self, x: float, y: float) -> None:
"""set Gun-Shift values."""
self.setGunShift(x, y)
###Illumination
def getSpotSize(self) -> int:
"""get the Spotsize."""
return self._tem.Illumination.SpotsizeIndex
def setSpotSize(self, value: int) -> None:
"""set the Spotsize"""
if isinstance(value, int):
self._tem.Illumination.SpotsizeIndex = value
def getBrightness(self) -> int:
"""get the Intensity value -> scaled to 0-65536"""
return int(self._tem.Illumination.Intensity * 65536)
def setBrightness(self, value: int) -> None:
"""set the Intensity value (0-65536)."""
if 0 <= value <= 65536:
it = float(value / 65536.0)
self._tem.Illumination.Intensity = it
def getBrightnessValue(self) -> float:
"""get the Intensity value."""
return self._tem.Illumination.Intensity
def setBrightnessValue(self, value: float) -> None:
"""set the Intensity value"""
self._tem.Illumination.Intensity = value
def getBeamShift(self) -> (float, float):
"""get the BeamShift values."""
return self._tem.Illumination.Shift.X, self._tem.Illumination.Shift.Y
def setBeamShift(self, x: float, y: float) -> None:
"""set the BeamShift values."""
bs = self._tem.Illumination.Shift
if x is not None:
bs.X = x
if y is not None:
bs.Y = y
self._tem.Illumination.Shift = bs
def getBeamTilt(self) -> (float, float):
"""get Rotation center."""
return self._tem.Illumination.RotationCenter.X, self._tem.Illumination.RotationCenter.Y
def setBeamTilt(self, x: float, y: float) -> None:
"""set Rotation center."""
if abs(x) > 0.4 or abs(y) > 0.4:
raise FEIValueError('BeamTilt x/y must be a floating number between -0.4 an 0.4. Input: x/y=%s/%s' % (x, y))
bt = self._tem.Illumination.RotationCenter
if x is not None:
bt.X = x
if y is not None:
bt.Y = y
self._tem.Illumination.RotationCenter = bt
def getCondensorLensStigmator(self) -> (float, float):
"""get Condensor lens stigmator."""
return self._tem.Illumination.CondenserStigmator.X, self._tem.Illumination.CondenserStigmator.Y
def setCondensorLensStigmator(self, x: float, y: float) -> None:
"""set Condensor lens stigmator."""
self._tem.Illumination.CondenserStigmator.X = x
self._tem.Illumination.CondenserStigmator.Y = y
###Projection
def getCurrentDensity(self) -> float:
"""Get the current density, not available on Tecnai."""
print('getCurrentDensity: not available on the Tecnai.')
return 0
def getScreenCurrent(self) -> float:
"""get the Screen current in nA."""
return (self._tem.Camera.ScreenCurrent * 1e9)
def isfocusscreenin(self) -> bool:
"""is small Screen down?"""
return self._tem.Camera.IsSmallScreenDown
def getScreenPosition(self) -> str:
"""is Screen 'up' or 'down'."""
while self._tem.Camera.MainScreen == self._tem_constant.ScreenPosition['spUnknown']:
time.sleep(1)
if self._tem.Camera.MainScreen == self._tem_constant.ScreenPosition['spUp']:
return 'up'
elif self._tem.Camera.MainScreen == self._tem_constant.ScreenPosition['spDown']:
return 'down'
else:
return ''
def setScreenPosition(self, value: str) -> None:
"""set Screen 'up' or 'down'."""
if value not in ('up', 'down'):
raise FEIValueError("No such screen position: %s ." % (value))
if value == 'up':
self._tem.Camera.MainScreen = self._tem_constant.ScreenPosition['spUp']
else:
self._tem.Camera.MainScreen = self._tem_constant.ScreenPosition['spDown']
while self._tem.Camera.MainScreen == self._tem_constant.ScreenPosition['spUnknown']:
time.sleep(1)
def getDiffFocus(self, confirm_mode: bool=True) -> int:
"""get the diffraction focus scaled between -1e4 (0) und 1e4 (65536)."""
if not self.getFunctionMode() == 'diff':
raise FEIValueError("Must be in 'diff' mode to get DiffFocus")
foc = self._tem.Projection.Defocus
val = int(32768.0 * 1.0e4 * (foc + 1.0e-4))
return val
def setDiffFocus(self, value: int, confirm_mode: bool=True) -> None:
"""set the diffraction focus value between -1e4 (0) und 1e4 (65536)."""
if not self.getFunctionMode() == 'diff':
raise FEIValueError("Must be in 'diff' mode to set DiffFocus")
if 0 <= value <= 65536:
foc = float((1.0e-4 / 32768.0 * value) - 1e-4)
self._tem.Projection.Defocus = foc
def getDiffFocusValue(self, confirm_mode: bool=True) -> float:
"""get the diffraction focus value."""
if not self.getFunctionMode() == 'diff':
raise FEIValueError("Must be in 'diff' mode to get DiffFocus")
return self._tem.Projection.Defocus
def setDiffFocusValue(self, value: float, confirm_mode: bool=True) -> None:
"""set the diffraction focus value."""
if not self.getFunctionMode() == 'diff':
raise FEIValueError("Must be in 'diff' mode to set DiffFocus")
self._tem.Projection.Defocus = value
def getFocus(self) -> float:
"""get the Defocus value."""
if not self.getFunctionMode() in ['lowmag', 'mag1', 'samag', 'mag2']:
raise FEIValueError("Must be in 'mag' mode to get Focus")
return self._tem.Projection.Defocus
def setFocus(self, value: float) -> None:
"""set the Defocus value."""
if not self.getFunctionMode() in ['lowmag', 'mag1', 'samag', 'mag2']:
raise FEIValueError("Must be in 'mag' mode to set Focus")
self._tem.Projection.Defocus = value
def getFunctionMode(self) -> str:
"""get the Function Mode. diff=D, lowmag=LM, mag1=Mi, samag=SA, mag2=Mh ."""
mode = self._tem.Projection.SubMode
return _FUNCTION_MODES[mode]
def setFunctionMode(self, value: str) -> None:
"""set the Function Mode. diff = diffraction mode, lowmag=mag1=samag=mag2 = imaging mode ."""
if isinstance(value, str):
try:
if value in list(_FUNCTION_MODES.values()):
if value in ['lowmag', 'mag1', 'samag', 'mag2']:
self._tem.Projection.Mode = self._tem_constant.ProjectionMode['pmImaging']
elif value == 'diff':
self._tem.Projection.Mode = self._tem_constant.ProjectionMode['pmDiffraction']
except ValueError:
raise FEIValueError('Unrecognized function mode: %s' % (value))
def getMagnification(self) -> float:
"""get Magnification/camera length."""
ind = self.getMagnificationIndex() - 1
if self.getFunctionMode() == 'diff':
return self._mic_ranges['D'][ind]
elif self.getFunctionMode() == 'LAD':
return self._mic_ranges['LAD'][ind]
else:
magni = self._mic_ranges['LM']
for k in ['Mi', 'SA', 'Mh']:
magni.extend(self._mic_ranges[k])
return magni[ind]
def setMagnification(self, value: float) -> None:
"""set Magnification/camera length."""
ind = None
try:
if self.getFunctionMode() == 'diff':
ind = self._mic_ranges['D'].index(value)
elif self.getFunctionMode() == 'LAD':
ind = self._mic_ranges['LAD'].index(value)
else:
magni = self._mic_ranges['LM']
for k in ['Mi', 'SA', 'Mh']:
magni.extend(self._mic_ranges[k])
ind = magni.index(value)
except ValueError:
raise FEIValueError('wrong Magnification: %s' % (value))
if ind != None:
self.setMagnificationIndex(ind + 1)
else:
pass
def getMagnificationRanges(self) -> dict:
"""get the MagnificationRanges from the config file"""
mag_ranges = {}
mag_ranges['diff'] = self._mic_ranges['D']
mag_ranges['LAD'] = self._mic_ranges['LAD']
mag_ranges['lowmag'] = self._mic_ranges['LM']
mag_ranges['mag1'] = self._mic_ranges['Mi']
mag_ranges['samag'] = self._mic_ranges['SA']
mag_ranges['mag2'] = self._mic_ranges['Mh']
return mag_ranges
def getMagnificationIndex(self) -> int:
"""get Magnification / camera length index."""
if self._tem.Projection.Mode == self._tem_constant.ProjectionMode['pmImaging']:
return self._tem.Projection.MagnificationIndex
elif self._tem.Projection.Mode == self._tem_constant.ProjectionMode['pmDiffraction']:
return self._tem.Projection.CameraLengthIndex
else:
return 0
def setMagnificationIndex(self, index: int) -> None:
"""set Magnification / camera length index."""
if self._tem.Projection.Mode == self._tem_constant.ProjectionMode['pmImaging']:
self._tem.Projection.MagnificationIndex = index
elif self._tem.Projection.Mode == self._tem_constant.ProjectionMode['pmDiffraction']:
self._tem.Projection.CameraLengthIndex = index
else:
raise FEIValueError("setMagnificationIndex: wrong MagnificationIndex / Mode.")
def getMagnificationAbsoluteIndex(self) -> None:
"""not implemented"""
raise NotImplementedError
def increaseMagnificationIndex(self) -> None:
"""increase Magnification by one step."""
try:
self._tem.Projection.MagnificationIndex += 1
except ValueError:
raise FEIValueError('Unrecognized Magnification Index.')
def getDarkFieldTilt(self) -> (float, float):
"""get the dark field tile value."""
return self._tem.Illumination.Tilt.X, self._tem.Illumination.Tilt.Y
def setDarkFieldTilt(self, x: float, y: float) -> None:
"""set the dark field tilt value."""
dt = self._tem.Illumination.Tilt
if x is not None:
dt.X = x
if y is not None:
dt.Y = y
self._tem.Illumination.Tilt = dt
def getImageShift1(self) -> (float, float):
"""get the image shift value"""
return self._tem.Projection.ImageShift.X, self._tem.Projection.ImageShift.Y
def setImageShift1(self, x: float, y: float) -> None:
"""set the image shift value."""
is1 = self._tem.Projection.ImageShift
if x is not None:
is1.X = x
if y is not None:
is1.Y = y
self._tem.Projection.ImageShift = is1
def getImageShift2(self) -> (float, float):
"""not implemented."""
return 0, 0
def setImageShift2(self, x: float, y: float) -> None:
"""not implemented."""
return None
def getImageBeamShift(self) -> (float, float):
"""get the beam shift value."""
return self._tem.Projection.ImageBeamShift.X, self._tem.Projection.ImageBeamShift.Y
def setImageBeamShift(self, x: float, y: float) -> None:
"""set the beam shift values."""
is1 = self._tem.Projection.ImageBeamShift
if x is not None:
is1.X = x
if y is not None:
is1.Y = y
self._tem.Projection.ImageBeamShift = is1
def getDiffShift(self) -> (float, float):
"""get the diffraction shift value in degree."""
return float(180 / pi * self._tem.Projection.DiffractionShift.X), float(180 / pi * self._tem.Projection.DiffractionShift.Y)
def setDiffShift(self, x: float, y: float) -> None:
"""set the diffraction shift values in degree."""
ds1 = self._tem.Projection.DiffractionShift
if x is not None:
ds1.X = float(x / 180 * pi)
if y is not None:
ds1.Y = float(y / 180 * pi)
self._tem.Projection.DiffractionShift = ds1
def getObjectiveLensStigmator(self) -> (float, float):
"""get the objective lens stigmator value."""
return self._tem.Projection.ObjectiveStigmator.X, self._tem.Projection.ObjectiveStigmator.Y
def setObjectiveLensStigmator(self, x: float, y: float) -> None:
"""set the objective lens stigmator value."""
self._tem.Projection.ObjectiveStigmator.X = x
self._tem.Projection.ObjectiveStigmator.Y = y
def getIntermediateLensStigmator(self) -> (float, float):
"""get the intermediate lens stigmator value."""
return self._tem.Projection.DiffractionStigmator.X, self._tem.Projection.DiffractionStigmator.Y
def setIntermediateLensStigmator(self, x: float, y: float) -> None:
"""set the intermediate lens stigmator value."""
self._tem.Projection.DiffractionStigmator.X = x
self._tem.Projection.DiffractionStigmator.Y = y
def release_connection(self) -> None:
"""release the COM-connection."""
comtypes.CoUninitialize()
self._logger.info('Connection to microscope released')
print('Connection to microscope released')
def getApertureSize(self, aperture: str) -> None:
"""not available on Tecnai."""
print('getApertureSize, not available on Tecnai.')
if __name__ == '__main__':
tem = TecnaiMicroscope()
from IPython import embed
embed()