Skip to content

Commit 4b68fe3

Browse files
committed
add timings for tecnaiccd, improve speed test, fix safearray orientation
1 parent e29ba09 commit 4b68fe3

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

pytemscript/plugins/tecnai_ccd_plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ def acquire_image(self,
3939
#img = self.ccd_plugin.AcquireImageShown()
4040
#img = self.ccd_plugin.AcquireDarkSubtractedImage() # variant
4141

42+
t0 = time.time()
4243
img = self.ccd_plugin.AcquireRawImage() # variant / tuple
44+
t1 = time.time()
4345

4446
if kwargs.get('show', False):
4547
self.ccd_plugin.ShowAcquiredImage()
4648

4749
image = convert_image(img, name=cameraName, use_safearray=False, **self._img_params)
50+
t2 = time.time()
51+
logging.debug("\tAcquisition took %f s" % (t1 - t0))
52+
logging.debug("\tConverting image took %f s" % (t2 - t1))
53+
4854
return image
4955
else:
5056
raise Exception("Camera is busy acquiring...")

pytemscript/utils/misc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ def convert_image(obj,
132132
# Convert to a safearray and then to numpy
133133
from comtypes.safearray import safearray_as_ndarray
134134
with safearray_as_ndarray:
135-
data = obj.AsSafeArray.astype("uint16") # AsSafeArray always returns int32 array
135+
# AsSafeArray always returns int32 array
136+
# Also, transpose is required to match TIA orientation
137+
data = obj.AsSafeArray.astype("uint16").T
136138

137139
elif use_asfile:
138140
# Save into a temp file and read into numpy
139141
import imageio
140-
fn = "C:\\temp.tif"
142+
fn = r"C:/temp.tif"
141143
if os.path.exists(fn):
142144
os.remove(fn)
143145
obj.SaveToFile(fn) if advanced else obj.AsFile(fn, 0)

tests/test_speed.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def acquire_image(microscope: Microscope, camera: str, **kwargs) -> Image:
1414

1515
def main() -> None:
1616
""" Testing acquisition speed. """
17-
microscope = Microscope(debug=True)
17+
microscope = Microscope(debug=True, useTecnaiCCD=False)
1818

1919
print("Starting acquisition speed test")
2020
cameras = microscope.acquisition.cameras
@@ -23,14 +23,19 @@ def main() -> None:
2323
if camera in cameras:
2424

2525
print("\tUsing SafeArray")
26-
acquire_image(microscope, camera)
26+
img1 = acquire_image(microscope, camera)
27+
img1.save(r"C:/%s_safearray.mrc" % camera, overwrite=True)
2728

2829
print("\tUsing AsFile")
29-
acquire_image(microscope, camera, use_safearray=False, use_asfile=True)
30+
# This should be 3x faster than SafeArray method above
31+
img2 = acquire_image(microscope, camera, use_safearray=False, use_asfile=True)
32+
img2.save(r"C:/%s_asfile.mrc" % camera, overwrite=True)
3033

31-
if camera == "EF-CCD":
34+
if camera in ["EF-CCD", "BM-Orius"]:
3235
print("\tUsing TecnaiCCD/TIA")
33-
acquire_image(microscope, camera, use_tecnaiccd=True)
36+
# This is faster than std scripting for Gatan CCD cameras
37+
img3 = acquire_image(microscope, camera, use_tecnaiccd=True)
38+
img3.save(r"C:/%s_tecnaiccd.mrc" % camera, overwrite=True)
3439

3540

3641
if __name__ == '__main__':

0 commit comments

Comments
 (0)