Skip to main content

Python Interface for Imspector

Project description

Imspector comes with a Python Interface named SpecPy which can be used either from the embedded Python console or from an external Python console running on the same computer (to enable sharing of measurement data) or even running on a different computer.

It can be used for remote control of microscopes, reading/writing data from/to running Imspector instances, and subscribing to change notifications. Essentially, all Imspector settings can be read and manipulated.

It can also be used as a standalone file reader to read .obf and .msr files in Python.

Start

  • Working from an external Python console you need to start the Imspector Server (which requires Administrator privileges the first time)

  • To load the Python Interface just say

from specpy import *

Examples

Open an .obf file in Python without Imspector running.

import specpy as sp
import numpy as np
from matplotlib import pyplot as plt

file = sp.File(r"C:\path\to\your\file.obf", sp.File.Read)

number_of_stacks = file.number_of_stacks()
metadata = file.metadata()

for i_stack in range(number_of_stacks):
    stack = file.read(i_stack)
    stack_name = stack.name()
    stack_data = stack.data()

    if stack_data.dtype == "uint16":
        fig, ax = plt.subplots()
        ax.set_title(stack_name)
        ax.imshow(stack_data)

Remote control an Imspector instance to open a Stack and calculate some statistics

import specpy as sp
import numpy as np

imspector = sp.get_application()
measurement = imspector.open(r"C:\path\to\your\file.obf")

threshold = 410

for name in measurement.stack_names():
  stack = measurement.stack(name)
  data = stack.data()

  mean = data.mean()
  standard_deviation = data.std()
  print(name, mean, standard_deviation)

  masked_data = np.ma.masked_less(data, threshold)
  mean = masked_data.mean()
  standard_deviation = masked_data.std()
  print(name, mean, standard_deviation)

  np.putmask(data, data < threshold, 4095)
  measurement.update()  # Update Imspector display after modifying stack data

Interface

Imspector

get_application()

first tries to return the local Imspector object (living in the same process) or else returns a proxy Imspector object connected to the Imspector Application running on localhost.

get_application(host)

where host is a host name returns a proxy Imspector object connected to the Imspector Application running on the corresponding host.

If imspector is an Imspector object then

imspector.host()

returns the name of the host the Imspector Application is running on or an empty string in case the Imspector object is local (living in the same process),

imspector.version()

returns the current Imspector version,

imspector.device_drivers()

returns the Imspector device drivers as a dictionary of name value pairs,

imspector.value_at(path, specpy.ValueTree.Hardware).get()

where path is of the form device/…/parameter_name returns the corresponding Imspector parameter value (the empty path returns a dictionary of name value pairs of all parameters).

imspector.value_at(path, specpy.ValueTree.Hardware).set(value)

where path is of the form device/…/parameter_name and value is a value, sets the corresponding Imspector parameter value (the empty path sets a dictionary of name value pairs of all parameters).

imspector.value_at(path, specpy.ValueTree.Status).get()

where path is of the form device/…/state_name returns the corresponding Imspector state value (the empty path returns a dictionary of name value pairs of all states).

imspector.value_at(path, specpy.ValueTree.Status).set(value)

where path is of the form device/…/state_name and value is a value, sets the corresponding Imspector state value (the empty path sets a dictionary of name value pairs of all states).

imspector.measurement_names()

returns the list of names of all open measurements in Imspector,

imspector.active_measurement()

for the currently active measurement in Imspector, returns the corresponding Measurement object or throws a RuntimeError if no measurement is active,

imspector.measurement(name)

where name is the name of an open measurement in Imspector, returns the corresponding Measurement object,

imspector.create_measurement()

creates an empty measurement in Imspector and returns the corresponding Measurement object,

imspector.open(path)

where path is the path to a measurement file, opens it in Imspector (if it is not already open) and returns the corresponding Measurement object,

imspector.activate(measurement)

where measurement is a Measurement object, activates the corresponding measurement in Imspector,

imspector.start(measurement)

where measurement is a Measurement object, starts the corresponding measurement in Imspector and returns immediately,

imspector.pause(measurement)

where measurement is a Measurement object, pauses the corresponding measurement in Imspector,

imspector.run(measurement)

where measurement is a Measurement object, runs the corresponding measurement in Imspector (starts it and returns when it has finished),

imspector.close(measurement)

where measurement is a Measurement object, closes the corresponding measurement in Imspector,

imspector.active_stack()

for the currently active stack (from the currently active measurement) in Imspector, returns the corresponding Stack object or throws a RuntimeError if no stack is active,

imspector.connect_measurement_cb(callable, signal)

where callable is a callable Python object and signal is one of specpy.MeasurementSignal.beg_measurement, specpy.MeasurementSignal.end_measurement, specpy.MeasurementSignal.beg_step, or specpy.MeasurementSignal.end_step, connects the callable to the corresponding signal in Imspector,

imspector.disconnect_measurement_cb(callable, signal)

where callable is a callable Python object and signal is one of specpy.MeasurementSignal.beg_measurement, specpy.MeasurementSignal.end_measurement, specpy.MeasurementSignal.beg_step, or specpy.MeasurementSignal.end_step, disconnects the callable from the corresponding signal in Imspector.

Measurement

If measurement is a Measurement object then

measurement.name()

returns the name of the measurement,

measurement.number_of_configurations()

returns the number of configurations in the measurement,

measurement.configuration_names()

returns the list of names of all configurations in the measurement,

measurement.active_configuration()

for the currently active configuration in the measurement, returns the corresponding Configuration object,

measurement.configuration(position)

where position is in the range from zero to the number of configurations in the measurement minus one, returns the corresponding Configuration object,

measurement.configuration(name)

where name is one of the configuration names in the measurement, returns the corresponding Configuration object,

measurement.activate(configuration)

where configuration is a Configuration object, activates the corresponding configuration in the measurement (if the measurement contains only one configuration, this configuration is activated by default),

measurement.clone(configuration)

where configuration is a Configuration object, clones the corresponding configuration in the measurement and activates and returns the clone,

measurement.remove(configuration)

where configuration is a Configuration object, removes the corresponding configuration in the measurement,

measurement.parameters(path)

where path is of the form device/…/parameter_name returns the corresponding measurement parameter value for the currently active configuration (the empty path returns a dictionary of name value pairs of all parameters),

measurement.set_parameters(path, value)

where path is of the form device/…/parameter_name and value is a value, sets the corresponding measurement parameter value for the currently active configuration (the empty path sets a dictionary of name value pairs of all parameters),

measurement.number_of_stacks()

returns the number of stacks in the measurement,

measurement.stack_names()

returns the list of names of all stacks in the measurement,

measurement.stack(position)

where position is in the range from zero to the number of stacks in the measurement minus one, returns the corresponding Stack object,

measurement.stack(name)

where name is one of the stack names in the measurement, returns the corresponding Stack object,

measurement.create_stack(type, sizes)

where type is a NumPy array data type and sizes is a list of exactly four sizes of dimensions, creates a new stack and returns the corresponding Stack object,

measurement.update()

redraws all corresponding stacks in Imspector (useful when the stack content was changed from Python),

measurement.save_as(path[, compression])

where path is a file path and compression is True by default or False saves it into a file.

Configuration

If configuration is a Configuration object then

configuration.name()

returns the name of the configuration,

configuration.parameters(path)

where path is of the form device/…/parameter_name returns the corresponding measurement parameter value for this configuration (the empty path returns a dictionary of name value pairs of all parameters),

configuration.set_parameters(path, value)

where path is of the form device/…/parameter_name and value is a value, sets the corresponding measurement parameter value for this configuration (the empty path sets a dictionary of name value pairs of all parameters),

configuration.number_of_stacks()

returns the number of stacks in this configuration,

configuration.stack_names()

returns the list of names of all stacks in this configuration,

configuration.stack(position)

where position is in the range from zero to the number of stacks in the configuration minus one, returns the corresponding Stack object,

configuration.stack(name)

where name is one of the stack names in this configuration, returns the corresponding Stack object.

File

File(path, mode)

where path is the path to an .obf or .msr file and mode is either File.Read or File.Write or File.Append opens it and returns the corresponding File object.

If file is a File object then

file.description()

returns the description of the file,

file.set_description(string)

where string is a string sets the description of the file,

file.number_of_stacks()

returns the number of stacks in the file,

file.read(position)

where position is in the range from zero to the number of stacks in the file minus one, reads and returns the corresponding Stack object,

file.write(stack[, compression])

where stack is a Stack object and compression is True by default or False writes it to the file,

del file

closes the file.

Stack

Stack(array)

where array is a NumPy ndarray returns a new local Stack object with data values from the array.

Stack(type, sizes)

where type is a NumPy array data type and sizes is a list of sizes of all dimensions returns a new local Stack object.

If stack is a Stack object then

stack.name()

returns the name of the stack,

stack.set_name(string)

where string is a string sets the name of the stack. If another stack in the same measurement already has the same name, suffixes of the form [1], [2], .. are added.

stack.description()

returns the description of the stack,

stack.set_description(string)

where string is a string, sets the description of the stack,

stack.type()

returns the type of the stack elements as NumPy array data type,

stack.number_of_elements()

returns the number of elements of the stack,

stack.shape()

returns the list of sizes of all dimensions of the stack,

stack.label(dimension)

where dimension is one of the dimensions returns the corresponding label of the stack,

stack.set_label(dimension, string)

where dimension is one of the dimensions and string is a string sets the corresponding label of the stack,

stack.labels()

returns the list of labels of all dimensions of the stack,

stack.set_labels(strings)

where strings is a list of strings for all dimensions sets the corresponding labels of the stack,

stack.length(dimension)

where dimension is one of the dimensions returns the corresponding length of the stack,

stack.set_length(dimension, number)

where dimension is one of the dimensions and number is a number sets the corresponding length of the stack,

stack.lengths()

returns the list of lengths of all dimensions of the stack,

stack.set_lengths(numbers)

where numbers is a list of numbers for all dimensions sets the corresponding lengths of the stack,

stack.offset(dimension)

where dimension is one of the dimensions returns the corresponding offset of the stack,

stack.set_offset(dimension, number)

where dimension is one of the dimensions and number is a number sets the corresponding offset of the stack,

stack.offsets()

returns the list of offsets of all dimensions of the stack,

stack.set_offsets(numbers)

where numbers is a list of numbers for all dimensions sets the corresponding offsets of the stack,

stack.parameters(path)

where path is of the form …/parameter_name returns the corresponding stack parameter value (the empty path returns a dictionary of name value pairs of all parameters),

stack.data()

returns the data of the stack as a NumPy ndarray.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

specpy-2026.20.24464-cp314-cp314-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.14Windows x86-64

specpy-2026.20.24464-cp314-cp314-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

specpy-2026.20.24464-cp314-cp314-macosx_15_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

specpy-2026.20.24464-cp313-cp313-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.13Windows x86-64

specpy-2026.20.24464-cp313-cp313-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

specpy-2026.20.24464-cp313-cp313-macosx_15_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

specpy-2026.20.24464-cp312-cp312-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.12Windows x86-64

specpy-2026.20.24464-cp312-cp312-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

specpy-2026.20.24464-cp312-cp312-macosx_15_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

specpy-2026.20.24464-cp311-cp311-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.11Windows x86-64

specpy-2026.20.24464-cp311-cp311-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

specpy-2026.20.24464-cp311-cp311-macosx_15_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

specpy-2026.20.24464-cp310-cp310-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.10Windows x86-64

specpy-2026.20.24464-cp310-cp310-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

specpy-2026.20.24464-cp310-cp310-macosx_15_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

specpy-2026.20.24464-cp39-cp39-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.9Windows x86-64

specpy-2026.20.24464-cp39-cp39-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

specpy-2026.20.24464-cp39-cp39-macosx_15_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.9macOS 15.0+ ARM64

File details

Details for the file specpy-2026.20.24464-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 e8b8733e3d96c8e1be1a8d7cb7607fe177ac9c41dc3530998161c80d87b04a99
MD5 572d97572103d86cd44edc2f08cb57ef
BLAKE2b-256 832e9ed22cfceffeb8d7e229382c44552e7ec08f22e187dc0576d7df333591f9

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1c087ec56b390497132c569411fd546fabb7a33ea87980402db3a735989106f2
MD5 4eab9b93716fbb94df8f34a1c2201ca0
BLAKE2b-256 18b32f08b1fae8acb3ac4bf2dad8e780b342e777d53706dc2ac032f76c957ea3

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 086bb30a84e9e3f490b2ee037a3595799a9c64dfad1c2f37ca60d8eb5f049968
MD5 6f0ce5d8ee047e2b7df9b6c3c8a18a3f
BLAKE2b-256 3123d4e044c5b4c34af304b2cabb0e0ddef60702a7b3b2e9c2e91f5c726d8777

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 150828a53a82a1b6e2bb3a53076e8d14f5660ea3f6f79f112d7968fd78603808
MD5 8b1f38d3f51efdb6281ce23b5c095454
BLAKE2b-256 a5e0e4f37abd3c572775b1f8b1b211ee7533f265b0e7c3793dad3c33fcea5a74

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e5c0ebe1a8293f01e61c3eb0f27c80cf2a9f084149036f522d7284da96167492
MD5 109df371a492910141ace267ab9910d9
BLAKE2b-256 3988c71b3da3806b643c68d30ea5a9d7343093762106a961039b395d7c91f762

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 0afdaba4fe85b3c4a348447abb5f844eb84f8a1505722d8f2e6181ab283e0a98
MD5 feb70cd8ff544d347dcc2b76eb8056d4
BLAKE2b-256 d9f5e01932861b361cfa90676ec3949687723a7ec8f1da21bad63b08367c26d7

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 86c92fe078f08d10d35019f11f218d6d095427f0b5c53d8332d7e3d1b4bd91af
MD5 53a4ca0956538a20cd36faeddb0e460b
BLAKE2b-256 41c09dc8e5f9ed3d5f216658f1c66385ff767d00749be3b15a2da945aaa0f99a

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 29e0791002d2352d3e2af1715913d3b9e9ecdbaac1cc08d374cfe09f4d4330c4
MD5 dfa11f07f6b4c411d4e5c9a5cb7d8abf
BLAKE2b-256 fd144883151640a4c7ce49afca176701dcacc5c912edd9a88272519ca235f58f

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 19834e013b47b51af8da91b82f32cd36b88ed0d13ed3c218255a7301e9f08ded
MD5 ff8cb07e4f2b6fb1f7ee0fad9df440ed
BLAKE2b-256 fedd69e16ad5837626b0924e3aac40ebc6d6b30340fd944aed6090751f71e20c

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cf7574cd05f633766a8badd25188c27d6e667443bc02f41db0f33a29898ad0ff
MD5 e5db15bb20c17294a47d3514bb0fd7a6
BLAKE2b-256 80ea6052c5a54499847838857a1b8c395da057bc20fcdaa12b44e9daab24c101

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1e4b57c4ae6bffb71a6afc11d67d8f27cd5c9084ef715fd32153c8c5c9a8687b
MD5 0075f6d80de06b93bfb46f6aef9771ad
BLAKE2b-256 4bcdc99993f5039133dbe19fecce723146f0803677fa8509a9703156c4666c51

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 a8611d8bbeb19898ea22ece50d0a379efdfa7c3139053b56b01d92489024d3f1
MD5 0887e0dc29a8faffe8e9bf020a0acc7b
BLAKE2b-256 7961fd01dad8e1a01a2376fa301d80cd8f0bdbc28e9e21949ab0a9e6eb7cdd70

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 eaff5b09f94d21007fd2076e6620556d3f82eb5ff4783637f1bf76c4af8cfc6e
MD5 aafaacfb2fa25fd92e69627d452fdcb6
BLAKE2b-256 bed61a38546f4b1c73400c9d10f8383676b0ca66ff894889455cf221dbfb621a

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 60621b8e986b3306449128b3ab74c61a9be5b9a0cd7ad23e56b1287efa1e8db7
MD5 a1daadd1c4a2fa943bf77e06eaff5d2f
BLAKE2b-256 d4dcd974b5442f1c81a740fffc14cb5596d9c48f240394eeebcaa1f59c7782ad

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9891883d26e9f489648e7c1c4dbc9120ce8d22d500e73d0df7be1efd24d63bba
MD5 aedb5f18df4de4a4a7bf113fa768e80a
BLAKE2b-256 675e2bf7d356aa74e818583336b660d0ed06b57603a515c1fd5cc39c4e00e89f

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e60dc7323ecfbd8212bc7ca44acdbafb36378ac38b94bdadbd32c83d4986ace0
MD5 50db7f781c4191c85f44afe271d7489a
BLAKE2b-256 4973379e560598d03b3a20a4acdf29763646649a90b5eb9dd76a156561113351

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c2b0caf952d13070cad9039f11cfceece263f374826e638212ad6639705af664
MD5 a81fde51087a40bad2c2e06be5c76d2f
BLAKE2b-256 b2dde00f637b842206b5909354279c1c014c3ac0f92366ae613d14cfb3909fd3

See more details on using hashes here.

File details

Details for the file specpy-2026.20.24464-cp39-cp39-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for specpy-2026.20.24464-cp39-cp39-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b4fadba2152c71adaa4733db396b99424b3890d1c92b19fd7715d21f8a6480f9
MD5 a5ae7cbbc1170c79f1eb467af2756836
BLAKE2b-256 dbebf41a92dfde43a50bbae60e36e20e96451e971ccd7437b40c195e357ec758

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page