PyJEM.sightx

This package is used to control the detector functions of the SigthX. s

Caution:

This package supports some functions published by the SigthX. Therefore, this package cann’t be used under the following conditions.

  • The SigthX is not configured in the network.

  • The SigthX is not running.

PyJEM.sightx.set_ip(val)

Set the IP address used by this package.

Parameters:

val (str) – IP address.

Return type:

None

Examples

>>> set_ip("127.0.0.1")
PyJEM.sightx.set_port(val)

Set the port number used by this package.

Parameters:

val (int) – Port number.

Return type:

None

Warning

Please do not use this except for JEOL service staff.

Examples

>>> set_ip("127.0.0.1")
PyJEM.sightx.get_config()

Get this package connection settings.

Returns:

Service configuration dictionary.

Return type:

dict

PyJEM.sightx.check_connection(timeout=3.0)

Check whether the target service is running.

Parameters:

timeout (float) – timout in seconds for the connection check. Default is 3.0 seconds.

Returns:

True if the target service is running. False if the service is not running or the IP address or port number may be incorrect.

Return type:

bool

Examples

>>> check_connection()
True
PyJEM.sightx.get_attached_detector()

Acquire the list of available ADF/Camera detectors in TEMCenter.

Returns:

List of available detector names.

Return type:

list of str

Examples

>>> from PyJEM import sightx
>>> sightx.get_attached_detector()
["HAADF", "LAADF", "BF", "Camera", "None"]
PyJEM.sightx.assign_channel(detectorName, channel=0)

Assign the selected detector to a channel.

Parameters:
  • detectorName (str) – Detector name (e.g., “HAADF”, “Camera”).

  • channel (int, optional) – Channel number to assign (for multi-channel configurations). Default is 0.

Returns:

Execution result.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.assign_channel("HAADF", 1)
{"status": "OK"}
PyJEM.sightx.get_assignChannels()

Get the list of active detector assignments.

Returns:

Dictionary mapping channel numbers (as strings) to assigned detector names.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.get_assignChannels()
{
    "0": "BF",
    "1": "HAADF",
    "2": "Camera",
    "3": "None"
}
PyJEM.sightx.snapshotall()

Acquire all available detectors simultaneously.

Returns:

Execution result.

Return type:

dict

Note

  • This function is only available in STEM mode.

  • To obtain the acquired image data, use snapshotframe() or get_image_cache().

Examples

>>> from PyJEM import sightx
>>> sightx.snapshotall()
{"status": "OK"}
>>> det = sightx.Detector("HAADF")
>>> img = det.snapshotframe("bmp")
PyJEM.sightx.start_accumulate_image_cache()

Enable caching of live acquisition images.

When enabled, live images are stored in a cache that can be retrieved via get_image_cache().

Returns:

Execution result.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.start_accumulate_image_cache()
{"status": "OK"}
PyJEM.sightx.stop_accumulate_image_cache()

Disable caching of live acquisition images.

When disabled, live images are no longer stored in the cache.

Returns:

Execution result.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.stop_accumulate_image_cache()
{"status": "OK"}
class PyJEM.sightx.Detector(det)

Bases: object

livestart()

Start live acquisition.

Returns:

Execution result.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> det = sightx.Detector("HAADF")
>>> det.livestart()
{"status": "OK"}
livestop()

Stop live acquisition.

Returns:

Execution result.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> det = sightx.Detector("HAADF")
>>> det.livestop()
{"status": "OK"}
snapshot(ext, save=False, filename=None, show=False)

Acquire an image with the specified format.

Parameters:
  • ext (str) – Image format: "jpg", "bmp", "tif".

  • save (bool, optional) – If True, save the captured file. Default is False.

  • filename (str, optional) – File name or absolute path. Used only when save=True. Default is None.

  • show (bool, optional) – If True, display the image. Default is False.

Returns:

  • If only ext is provided: image data stream (bytes).

  • If save=True: saved file path (str).

Return type:

bytes or str

Examples

>>> from PyJEM import sightx
>>> det = sightx.Detector("HAADF")
>>> img = det.snapshot("bmp")
>>> with open("temp.bmp", "wb") as f:
...     f.write(img)
263222
snapshotframe(ext, save=False, filename=None, show=False)

Return previously captured image frame (from snapshotall())

Parameters:
  • ext (str) – Image format: "jpg", "bmp", "tif".

  • save (bool, optional) – If True, save the captured file. Default is False.

  • filename (str, optional) – File name or absolute path. Used only when save=True. Default is None.

  • show (bool, optional) – If True, display the image. Default is False.

Returns:

  • If only ext is provided: image data stream (bytes).

  • If save=True: saved file path (str).

Return type:

bytes or str

Note

This function does not acquire a new image; it returns the frame from the previous snapshotall() call. Use snapshotall() before this function to acquire images.

Examples

>>> from PyJEM import sightx
>>> sightx.snapshotall()
>>> det = sightx.Detector("HAADF")
>>> img = det.snapshotframe("bmp")
>>> with open(r"C:\temp.bmp", "wb") as f:
...     f.write(img)
263222
>>> det.snapshotframe("bmp", save=True)
'C:\...\20230217174244.bmp'
livesnapshot(ext, save=False, filename=None, show=False)

Capture a live image quickly without stopping acquisition.

Parameters:
  • ext (str) – Image format: "jpg", "bmp", "tif".

  • save (bool, optional) – If True, save the captured file. Default is False.

  • filename (str, optional) – File name or absolute path. Used only when save=True. Default is None.

  • show (bool, optional) – If True, display the image. Default is False.

Returns:

  • If only ext is provided: image data stream (bytes).

  • If save=True: saved file path (str).

Return type:

bytes or str

Note

This function captures an image frame from the active live stream. It is faster than snapshot() because it does not interrupt the live acquisition.

Examples

>>> from PyJEM import sightx
>>> det = sightx.Detector("HAADF")
>>> img = det.livesnapshot("bmp")
>>> with open(r"C:\temp.bmp", "wb") as f:
...     f.write(img)
263222
>>> det.livesnapshot("bmp", save=True)
'C:\...\20230217174244.bmp'
snapshot_rawdata()

Return raw image data from the selected detector.

Returns:

Raw 2-D image byte array as returned by the detector.

Return type:

bytes

Examples

Convert raw bytes to a NumPy array and save with PIL:

>>> import numpy as np
>>> from PIL import Image
>>> det = sightx.Detector("Camera")
>>> img = det.snapshot_rawdata()
>>> settings = det.get_detectorsetting()
>>> width = settings["ImagingArea"]["Width"]
>>> height = settings["ImagingArea"]["Height"]
>>> imgarray = np.frombuffer(img, dtype=np.dtype('<i2')).reshape((width, height))
>>> img = Image.fromarray(imgarray, mode='L')
>>> img.save('test.bmp')
get_detectorsetting()

Obtain setting information for the selected detector.

Returns:

Detector configuration dictionary containing keys such as ExposureTimeValue, GainIndex, OffsetIndex, frameIntegration, ImagingArea, SpotPosition, BinningSize, scanMode, ScanRotation, and others (model-dependent).

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> det = sightx.Detector("HAADF")
>>> settings = det.get_detectorsetting()
>>> settings["ExposureTimeValue"]
100
set_detectorsetting(body)

Set detector or camera parameters by sending a settings dictionary.

Parameters:

body (dict) –

Settings payload.

key

type

value

AreaModeImagingArea

dict

Imaging area for Area mode. Valid when scanMode == 3. ⇒ See AreaModeImagingArea items.

BinningIndex

int

Pixel binning index.

BinningSize

dict

Camera binning configuration. ⇒ See BinningSize items.

DigitalRotation

float

Digital rotation angle in degrees (0.0-360.0).

ExposureTimeIndex

int

Exposure time index.

ExposureTimeValue

float

Exposure time in microseconds.

frameIntegration

int

Number of frame accumulations.

GainIndex

int

Gain value index.

ImagingArea

dict

Imaging area settings. ⇒ See ImagingArea items.

OffsetIndex

int

Offset value index.

scanMode

int

Scan mode. 0: Scan, 1: Area, 3: Spot.

ScanRotation

float

Scan rotation angle in degrees.

scanRotationStep

float

Minimum variation of scan rotation step in degrees.

SpotPosition

dict

Spot position (valid when scanMode == 1). ⇒ See SpotPosition items.

AreaModeImagingArea items

key

type

value

X

int

Left edge X coordinate.

Y

int

Top edge Y coordinate.

Width

int

Width in pixels.

Height

int

Height in pixels.

BinningSize items

key

type

value

Width

int

Horizontal binning factor.

Height

int

Vertical binning factor.

ImagingArea items

key

type

value

X

int

Left edge X coordinate.

Y

int

Top edge Y coordinate.

Width

int

Width in pixels.

Height

int

Height in pixels.

SpotPosition items

key

type

value

X

int

Spot X coordinate.

Y

int

Spot Y coordinate.

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> param = {
...     "ExposureTimeValue": 100,
...     "GainIndex": 8000,
...     "OffsetIndex": 8000
... }
>>> sightx.Detector("HAADF").set_detectorsetting(param)
set_frameintegration(value)

Set the frame integration (accumulation) count.

Parameters:

value (int) – Frame integration value (range depends on TEM model, typically 0-255).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").set_frameintegration(10)
set_exposuretime_index(value)

Set the exposure time as an index value.

Parameters:

value (int) – Exposure time index (range depends on TEM model, typically 0-65535).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").set_exposuretime_index(100)
set_exposuretime_value(value)

Set the exposure time as a direct value in microseconds.

Parameters:

value (float) – Exposure time in microseconds (range depends on TEM model).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").set_exposuretime_value(500.0)
set_gainindex(value)

Set the gain value as an index.

Parameters:

value (int) – Gain index (range depends on TEM model, typically 0-4095).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").set_gainindex(1000)
set_offsetindex(value)

Set the offset value as an index.

Parameters:

value (int) – Offset index (range depends on TEM model, typically 0-4095).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").set_offsetindex(1000)
set_digitalrotation(value)

Set the digital rotation angle as an absolute value.

Parameters:

value (float) – Digital rotation angle in degrees (0.0-360.0).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").set_digitalrotation(45.0)
set_scanrotation(value)

Set the scan rotation angle as an absolute value.

Parameters:

value (float) – Scan rotation angle in degrees (0.0-360.0).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").set_scanrotation(45.0)
set_scanrotation_step(value)

Set the minimum variation (step) of scan rotation.

Parameters:

value (float) – Scan rotation step in degrees (0.0-20.0).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").set_scanrotation_step(1.0)
set_imaging_area(Width, Height, X=None, Y=None)

Set the imaging area (region of interest) for acquisition.

Parameters:
  • Width (int) – Width in pixels (0-4096).

  • Height (int) – Height in pixels (0-4096).

  • X (int, optional) – Left edge X coordinate (0-4096). If not provided, the value is not changed.

  • Y (int, optional) – Top edge Y coordinate (0-4096). If not provided, the value is not changed.

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").set_imaging_area(Width=1024, Height=1024, X=512, Y=512)
set_spotposition(X, Y)

Set the beam position when scan mode is Spot.

Sets which part of the scanning range (as defined by ImagingArea) is scanned. The top left vertex is (0, 0).

Parameters:
  • X (int) – Spot X coordinate (0-4096).

  • Y (int) – Spot Y coordinate (0-4096).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").set_spotposition(X=2048, Y=2048)
set_areamode_imagingarea(Width, Height, X=None, Y=None)

Set the beam position when scan mode is Area.

Sets which part of the scanning range (as defined by ImagingArea) is scanned. The top left vertex is (0, 0).

Parameters:
  • Width (int) – Width in pixels (0-4096).

  • Height (int) – Height in pixels (0-4096).

  • X (int, optional) – Left edge X coordinate (0-4096). If not provided, the value is not changed.

  • Y (int, optional) – Top edge Y coordinate (0-4096). If not provided, the value is not changed.

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").set_areamode_imagingarea(Width=512, Height=512, X=1024, Y=1024)
set_scanmode(value)

Set the scan mode.

Parameters:

value (int) – Scan mode value. 0: Scan, 1: Area, 3: Spot.

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").set_scanmode(0)
set_binningindex(value)

Set the pixel binning value as an index.

Parameters:

value (int) – Binning index (range depends on TEM model, typically 0-4).

Returns:

Dictionary containing the applied detector settings.

Return type:

dict

Note

This function corresponds to camera detectors only.

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").set_binningindex(2)
AutoFocus()

Start AutoFocus function.

Returns:

Execution status.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("HAADF").AutoFocus()
{"status": "OK"}
AutoContrastBrightness()

Start AutoContrastBrightness function.

Returns:

Execution status.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").AutoContrastBrightness()
{"status": "OK"}
AutoStigmator()

Start AutoStigmator function.

Returns:

Execution status.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").AutoStigmator()
{"status": "OK"}
AutoOrientation()

Start AutoOrientation function.

Returns:

Execution status.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").AutoOrientation()
{"status": "OK"}
AutoZ()

Start AutoZ function.

Returns:

Execution status.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").AutoZ()
{"status": "OK"}
get_insert_state()

Get detector in/out status.

Returns:

Execution status indicating whether detector is inserted.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").get_insert_state()
{"status": "OK"}
insert()

Insert the selected detector into the beam path.

Returns:

Execution status.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").insert()
{"status": "OK"}
retract()

Retract the selected detector from the beam path.

Returns:

Execution status.

Return type:

dict

Examples

>>> from PyJEM import sightx
>>> sightx.Detector("Camera").retract()
{"status": "OK"}
get_image_cache()

Return a cached image of the current Live acquisition.

The cache is automatically maintained only when the cache accumulation flag is enabled (via start_accumulate_image_cache()).

Returns:

Raw 2-D image byte array from the detector cache.

Return type:

bytes

Examples

>>> from PyJEM import sightx
>>> sightx.start_accumulate_image_cache()
>>> sightx.Detector("Camera").get_image_cache()
b'\x00\x01...'