Skip to content

Commit 2ebd855

Browse files
committed
fix Gun1 and beam tilt calls
1 parent 02720d2 commit 2ebd855

5 files changed

Lines changed: 26 additions & 27 deletions

File tree

pytemscript/modules/gun.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,28 @@ class GunObj(SpecialObj):
1515
""" Wrapper around Gun COM object specifically for the Gun1 interface. """
1616
def __init__(self, com_object):
1717
super().__init__(com_object)
18-
self.gun1 = None
19-
20-
def is_available(self) -> bool:
21-
""" Gun1 inherits from the Gun interface of the std scripting. """
2218
import comtypes.gen.TEMScripting as Ts
2319
if hasattr(Ts, "Gun1"):
2420
self.gun1 = self.com_object.QueryInterface(Ts.Gun1)
25-
return True
2621
else:
27-
return False
22+
self.gun1 = None
23+
24+
def is_available(self) -> bool:
25+
""" Gun1 inherits from the Gun interface of the std scripting. """
26+
return self.gun1 is not None
2827

2928
def get_hv_offset(self) -> float:
30-
if self.gun1 is None:
29+
if not self.is_available():
3130
raise NotImplementedError(ERR_MSG_GUN1)
3231
return self.gun1.HighVoltageOffset
3332

3433
def set_hv_offset(self, value: float) -> None:
35-
if self.gun1 is None:
34+
if not self.is_available():
3635
raise NotImplementedError(ERR_MSG_GUN1)
3736
self.gun1.HighVoltageOffset = value
3837

3938
def get_hv_offset_range(self) -> Tuple:
40-
if self.gun1 is None:
39+
if not self.is_available():
4140
raise NotImplementedError(ERR_MSG_GUN1)
4241
result = self.gun1.GetHighVoltageOffsetRange()
4342
return result[0], result[1]

pytemscript/modules/illumination.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,20 @@ def beam_tilt(self) -> Union[Vector, float]:
263263
depends on a calibration of the tilt angles. (read/write)
264264
"""
265265
dfmode = RequestBody(attr=self.__id + ".DFMode", validator=int)
266-
dftilt = RequestBody(attr=self.__id + ".Tilt")
266+
dftiltx = RequestBody(attr=self.__id + ".Tilt.X", validator=float)
267+
dftilty = RequestBody(attr=self.__id + ".Tilt.Y", validator=float)
267268

268269
mode = self.__client.call(method="get", body=dfmode)
269-
tilt = self.__client.call(method="get", body=dftilt)
270+
tiltx = self.__client.call(method="get", body=dftiltx) # rad
271+
tilty = self.__client.call(method="get", body=dftilty) # rad
270272

271273
if mode == DarkFieldMode.CONICAL:
272-
tilt *= 1e3
273-
return Vector(tilt.x * math.cos(tilt.y), tilt.x * math.sin(tilt.y))
274+
tilt = tiltx
275+
rot = tilty
276+
return Vector(tilt * math.cos(rot), tilt * math.sin(rot)) * 1e3
274277
elif mode == DarkFieldMode.CARTESIAN:
275-
return tilt * 1e3
276-
else:
278+
return Vector(tiltx, tilty) * 1e3
279+
else: # DF is off
277280
return Vector(0.0, 0.0) # Microscope might return nonsense if DFMode is OFF
278281

279282
@beam_tilt.setter
@@ -284,7 +287,7 @@ def beam_tilt(self, tilt: Union[Vector, float]) -> None:
284287
if isinstance(tilt, float):
285288
tilt = Vector(tilt, tilt)
286289

287-
tilt *= 1e-3
290+
tilt *= 1e-3 # mrad to rad
288291

289292
if tilt == (0.0, 0.0):
290293
body = RequestBody(attr=self.__id + ".Tilt", value=tilt)
@@ -299,13 +302,9 @@ def beam_tilt(self, tilt: Union[Vector, float]) -> None:
299302
body = RequestBody(attr=self.__id + ".Tilt", value=value)
300303
self.__client.call(method="set", body=body)
301304

302-
elif mode == DarkFieldMode.OFF:
303-
body = RequestBody(attr=self.__id + ".DFMode", value=DarkFieldMode.CARTESIAN)
304-
self.__client.call(method="set", body=body)
305-
306-
body = RequestBody(attr=self.__id + ".Tilt", value=tilt.x)
305+
elif mode == DarkFieldMode.CARTESIAN:
306+
body = RequestBody(attr=self.__id + ".Tilt", value=tilt)
307307
self.__client.call(method="set", body=body)
308308

309309
else:
310-
body = RequestBody(attr=self.__id + ".Tilt", value=tilt.x)
311-
self.__client.call(method="set", body=body)
310+
raise ValueError("Dark field mode is OFF. You cannot set beam tilt.")

tests/test_acquisition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def main(argv: Optional[List] = None) -> None:
139139
"BM-Falcon": {"exp_time": 3.0, "binning": 1, "align_image": True,
140140
"electron_counting": True, "save_frames": True, "group_frames": 2},
141141
"EF-Falcon": {"exp_time": 1.0, "binning": 1,
142-
"electron_counting": True, "save_frames": True},
142+
"electron_counting": True, "save_frames": True, "group_frames": 2},
143143
}
144144

145145
for cam, cam_dict in cameras.items():

tests/test_calgetter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ def main():
2020

2121
cameras = [
2222
"BM-Orius",
23-
"BM-Falcon"
23+
"BM-Falcon",
24+
"EF-Falcon"
2425
]
25-
kv = 200
26+
kv = 300
2627

2728
#camera = cg.get_reference_camera()
2829
for camera in cameras:

tests/test_speed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def main() -> None:
1919
print("Starting acquisition speed test")
2020
cameras = microscope.acquisition.cameras
2121

22-
for camera in ["BM-Ceta", "BM-Falcon", "EF-CCD"]:
22+
for camera in ["BM-Ceta", "BM-Falcon", "EF-Falcon", "EF-CCD"]:
2323
if camera in cameras:
2424

2525
print("\tUsing SafeArray")

0 commit comments

Comments
 (0)