Components

This section covers the main components of Pytemscript.

Microscope class

The microscope class provides the main interface to the microscope. It is used to connect to the instrument locally or over the network.

Events

You can receive events from hand panel buttons when using the local client on the microscope PC. See events page for details.

Enumerations

Many of the attributes set and return values from enumerations. This minimizes typos when dealing with integer or string static values. The complete list can be found on the enumerations page.

Images

Two main acquisition methods acquire_tem_image() and acquire_stem_image() return an Image() object that has the following methods and properties:

class pytemscript.modules.Image(data: ndarray, name: str, metadata: Dict)[source]

Acquired image basic object.

Parameters:
  • data (numpy.ndarray) – uint16 numpy array

  • name (str) – name of the image

  • metadata (dict) – image metadata

  • timestamp (str) – acquisition timestamp in “%Y:%m:%d %H:%M:%S” format

save(fn: Path | str, thumbnail: bool = False, overwrite: bool = False) None[source]

Save acquired image to a file as uint16. Supported formats: mrc, tif, png, jpg.

Parameters:
  • fn (Path or str) – Filepath

  • thumbnail (bool) – Create a 512px-wide 8-bit thumbnail, height is adjusted to keep the aspect ratio. Only for non-MRC formats

  • overwrite (bool) – Overwrite existing file

Vectors

Some attributes handle two dimensional vectors that have X and Y values (e.g. image shift or gun tilt). These attributes accept and return a Vector() of two floats. Vectors can be multiplied, subtracted etc. as shown below. You can also use a list or a tuple to set vector attributes.

from pytemscript.modules import Vector
shift = Vector(0.5,-0.5)
shift += (0.4, 0.2)
shift *= 2
microscope.optics.illumination.beam_shift = shift
projection.image_shift = (0.05, 0.1)
projection.image_shift = [0.05, 0.1]
class pytemscript.modules.Vector(x: float, y: float)[source]

Utility object with two float attributes.

Parameters:
  • x (float) – X value

  • y (float) – Y value

Usage:
>>> from pytemscript.modules import Vector
>>> vector = Vector(0.03, 0.02)
>>> microscope.optics.illumination.beam_shift = vector
>>> vector *= 2
>>> print(vector)
(0.06, 0.04)
>>> vector.set(-0.5, -0.06)
>>> print(vector)
(-0.5, -0.06)
check_limits() None[source]

Validate that the vector’s values are within the set limits.

get() Tuple[source]

Return the vector components as a tuple.

set(value: Tuple[float, float] | List[float] | Vector) None[source]

Update current values from a tuple, list or another Vector.

set_limits(min_value: float, max_value: float) None[source]

Set the range limits for the vector for both X and Y.

The COM interface

The Python API of pytemscript provides a wrapper (via comtypes library) around COM methods of scripting interfaces. If you would like to know more, the standard scripting manual of your microscope (scripting.pdf) can be located in the C:\Titan\Tem_help\manual or C:\Tecnai\tem_help\manual directory. Advanced scripting manual can be found in C:\Titan\Scripting\Advanced TEM Scripting User Guide.pdf. Below is the list of COM interfaces used by pytemscript.

Relative to the standard scripting library v1.9:

  • Acquisition

  • ApertureMechanismCollection (untested)

  • AutoLoader

  • BlankerShutter

  • Camera

  • Configuration

  • Gun

  • Gun1

  • Illumination

  • InstrumentModeControl

  • Projection

  • Stage

  • TemperatureControl

  • UserButtons (with event handling)

  • Vacuum

Relative to the advanced scripting library v1.2:

  • Acquisitions

  • Autoloader

  • EnergyFilter

  • Phaseplate

  • PiezoStage (untested)

  • Source

  • TemperatureControl

  • UserDoorHatch (untested)

Other components and plugins (LowDose, TIA, TecnaiCCD, Calgetter etc.) have their own COM interfaces.