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.

Setup

To setup SpecPy you first need to install

  • Python 2.7.9 or 3.4.2 together with

  • NumPy-MKL 1.8.2

Then from the Command Prompt run

python.exe -m pip install specpy

Start

  • Working from an external Python console you need to start the Imspector Server

images/ImspectorRunServer.png
  • To load the Python Interface just say

from specpy import *

Interface

Imspector

Imspector()

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

Imspector(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 than

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.parameter(path)

where path is of the form device/…/parameter_name returns the corresponding Imspector parameter value,

imspector.set_parameter(path, value)

where path is of the form device/…/parameter_name and value is a value, sets the corresponding Imspector parameter value,

imspector.parameters()

returns the Imspector parameters as a dictionary of name value pairs,

imspector.set_parameters(dictionary)

where dictionary is a dictionary of name value pairs sets the corresponding Imspector parameter values,

imspector.measurement_titles()

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

imspector.active_measurement()

for the currently active measurement in Imspector, returns the corresponding Measurement object,

imspector.measurement(title)

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

imspector.open(path)

where path is the path to a measurement file, opens it in Imspector 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.stop(measurement)

where measurement is a Measurement object, stops 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.connect_begin(callable, flag)

where callable is a callable Python object, connects it to the corresponding begin signal in Imspector (if flag is 0 the begin of the whole measurement and if flag if 1 the begin of one measurement step),

imspector.disconnect_begin(callable, flag)

where callable is a callable Python object, disconnects it from the corresponding begin signal in Imspector (if flag is 0 the begin of the whole measurement and if flag if 1 the begin of one measurement step),

imspector.connect_end(callable, flag)

where callable is a callable Python object, connects it to the corresponding end signal in Imspector (if flag is 0 the end of the whole measurement and if flag if 1 the end of one measurement step),

imspector.disconnect_end(callable, flag)

where callable is a callable Python object, disconnects it from the corresponding end signal in Imspector (if flag is 0 the end of the whole measurement and if flag if 1 the end of one measurement step).

Measurement

If measurement is a Measurement object than

measurement.title()

returns the title of the measurement,

measurement.number_of_configurations()

returns the number of configurations in the measurement,

measurement.configuration_titles()

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

measurement.active_configuration()

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

measurement.configuration(index)

where index is from the interval \([0, number\_of\_configurations - 1]\) in the measurement, returns the corresponding Configuration object,

measurement.configuration(title)

where title is one of the configuration titles 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.parameter(path)

where path is of the form device/…/parameter_name, returns the corresponding measurement parameter value for the currently active configuration,

measurement.set_parameter(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,

measurement.parameters()

returns the measurement parameters for the currently active configuration as a dictionary of name value pairs,

measurement.set_parameters(dictionary)

where dictionary is a dictionary of name value pairs, sets the corresponding measurement parameter values for the currently active configuration,

measurement.number_of_stacks()

returns the number of stacks in the measurement,

measurement.stack_titles()

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

measurement.stack(index)

where index is from the interval \([0, number\_of\_stacks - 1]\) in the measurement, returns the corresponding Stack object,

measurement.stack(title)

where title is one of the stack titles in the measurement, returns the corresponding Stack object,

measurement.create_stack(type, sizes)

where type is one of the Data Types 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 than

configuration.title()

returns the title of the configuration,

configuration.parameter(path)

where path is of the form device/…/parameter_name, returns the corresponding measurement parameter value for this configuration,

configuration.set_parameter(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,

configuration.parameters()

returns the measurement parameters for this configuration as a dictionary of name value pairs,

configuration.set_parameters(dictionary)

where dictionary is a dictionary of name value pairs, sets the corresponding measurement parameter values for this configuration,

configuration.number_of_stacks()

returns the number of stacks in this configuration,

configuration.stack_titles()

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

configuration.stack(index)

where index is from the interval \([0, number\_of\_stacks - 1]\) in this configuration, returns the corresponding Stack object,

configuration.stack(title)

where title is one of the stack titles 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 than

file.description()

returns the description of the file,

file.set_description(description)

where description 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, reads and returns the corresponding Stack object,

file.write(stack)

where stack is a Stack object writes it to the file,

file.close()

closes it.

Stack

Stack(type, sizes)

where type is one of the Data Types and sizes is a list of sizes of all dimensions, returns a new local Stack object.

If stack is a Stack object than

stack.title()

returns the title of the stack,

stack.set_title(string)

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

stack.description()

returns the description,

stack.set_description(string)

where string is a string, sets the description,

stack.number_of_elements()

returns the number of elements,

stack.number_of_dimensions()

returns the number of dimensions,

stack.size(dimension)

where dimension is one of the dimensions returns the corresponding size (the number of steps/positions in that dimension),

stack.sizes()

returns the list of sizes of all dimensions,

stack.label(dimension)

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

stack.set_label(dimension, string)

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

stack.labels()

returns the list of labels of all dimensions,

stack.set_labels(strings)

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

stack.length(dimension)

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

stack.set_length(dimension, number)

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

stack.lengths()

returns the list of lengths of all dimensions,

stack.set_lengths(numbers)

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

stack.offset(dimension)

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

stack.set_offset(dimension, number)

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

stack.offsets()

returns the list of offsets of all dimensions,

stack.set_offsets(numbers)

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

stack.data()

returns the data as a NumPy array. Note that the shape of the array is reversed regarding the order of the dimensions in Imspector and all other methods of Stack.

Data Types

These are constants of the SpecPy module.

Int8
UInt8
Int16
UInt16
Int32
UInt32
Int64
UInt64
Float32
Float64
Complex64
Complex128

Examples

Changes the exposure time of the sample camera.

from specpy import *
imspector = Imspector()
measurement = imspector.active_measurement()
time = measurement.parameter('SimCam/ExposureTime')
measurement.set_parameter('SimCam/ExposureTime', 2*time)

Opens a Stack and does some statistics.

from specpy import *
imspector = Imspector()
measurement = imspector.open(r"D:\Data\20120806_PD neurons Dioc.lif")
import numpy
threshold = 410
# file = open('output.txt', 'w')
for title in measurement.stack_titles() :
  stack = measurement.stack(title)
  data = stack.data()
  mean = data.mean()
  standard_deviation = data.std()
  print title, mean, standard_deviation
#   print >> file, title, mean, standard_deviation
  masked_data = numpy.ma.masked_less(data, threshold)
  mean = masked_data.mean()
  standard_deviation = masked_data.std()
  print title, mean, standard_deviation
#   print >> file, title, mean, standard_deviation
  numpy.putmask(data, data < threshold, 4095)

# file.close()

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

specpy-1.0.2-cp34-none-win_amd64.whl (1.2 MB view hashes)

Uploaded CPython 3.4 Windows x86-64

specpy-1.0.2-cp34-none-win32.whl (1.1 MB view hashes)

Uploaded CPython 3.4 Windows x86

specpy-1.0.2-cp27-none-win_amd64.whl (1.4 MB view hashes)

Uploaded CPython 2.7 Windows x86-64

specpy-1.0.2-cp27-none-win32.whl (959.2 kB view hashes)

Uploaded CPython 2.7 Windows x86

Supported by

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