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, 3.4.2, or 3.5.0 together with
NumPy-MKL 1.8.2
Then from the Command Prompt run
python.exe -m pip install --upgrade specpy
Start
Working from an external Python console you need to start the Imspector Server (with requires Administrator permissions the first time):
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_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,
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 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.active_stack()
for the currently active stack (from the currently active measurement) in Imspector, returns the corresponding Stack object,
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.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.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_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 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.name()
returns the name 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_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 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 in the
file minus one, 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.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.number_of_elements()
returns the number of elements of the stack,
stack.number_of_dimensions()
returns the number of dimensions of the stack,
stack.size(dimension)
where dimension
is one of the dimensions returns the corresponding size of the stack
(the number of steps/positions in that dimension),
stack.sizes()
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.meta_data()
returns the meta data of the stack as a dictionary of name value pairs,
stack.data()
returns the data of the stack 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! Use transpose() to get a NumPy view with a reversed order of dimensions.
Data Types
These are constants of the SpecPy module.
Int8
UInt8
Int16
UInt16
Int32
UInt32
Float32
Float64
ComplexFloat32
ComplexFloat64
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 name in measurement.stack_names() :
stack = measurement.stack(name)
data = stack.data()
mean = data.mean()
standard_deviation = data.std()
print name, mean, standard_deviation
# print >> file, name, mean, standard_deviation
masked_data = numpy.ma.masked_less(data, threshold)
mean = masked_data.mean()
standard_deviation = masked_data.std()
print name, mean, standard_deviation
# print >> file, name, mean, standard_deviation
numpy.putmask(data, data < threshold, 4095)
# file.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for specpy-1.1.2-cp35-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3f76ed043f2f22f13df8efdbe4e14fb1f7e5441ab9c30ea14d3578389015b30 |
|
MD5 | 145a4e0122bc0cd1cc15b362e80ad7e9 |
|
BLAKE2b-256 | 9e69158aaf8cdcaa0872e1a324ed93fe2908416e3ca5138d2de90d17fcc8bb77 |
Hashes for specpy-1.1.2-cp35-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07e4afbe7c9edebba5f426fd2ab34a025ddfa81345bbb8d16c0e8e720be555cc |
|
MD5 | 7ed1aa1a24db2173f725a5e786c4615d |
|
BLAKE2b-256 | 5a0aa321d623ae7be3264fb32b22b9ba7177c0a5e2af37afa3ef3388038dfc64 |
Hashes for specpy-1.1.2-cp34-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 768df7ee7e8ce31df4c00be5442e027e3d8615b55121b07010005a9dec7014a6 |
|
MD5 | bc4da82d492f91bda7a808d9c808fdde |
|
BLAKE2b-256 | 3946d8d7c86b5c4fc467147a7e56d4ae92db9d634926a5c83cb704415247a91c |
Hashes for specpy-1.1.2-cp34-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31a350cdc8e1820e19765beaa53c28fc21069bec9c2589cfb6e82c4a1f7e1dab |
|
MD5 | b54e2c91d8fb6e35a3d4a069dde6f787 |
|
BLAKE2b-256 | a432ef2e21d0e0b4ed2e7a3df6c12c2450d6d97c3a6a42bd20de724f52b0e436 |
Hashes for specpy-1.1.2-cp27-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6306b73ec045834738d407f93a9587d20701d52a76c2c9c69185752cb33fd74c |
|
MD5 | 366d600ff970c8f482c9d468d285d7a2 |
|
BLAKE2b-256 | 0363f1aa1db2992f176b6e2592a2dfe586917eac128a7e6e34d5be0aaf42d318 |
Hashes for specpy-1.1.2-cp27-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6917b5f7c2cc61b1ddcadc9db3a27a6207f7219f18f9edc5862fd401f82ee5f7 |
|
MD5 | ef08faec8537889551d86aba1370f734 |
|
BLAKE2b-256 | 33e16b5cf1da5f9e138acb1be7e4e35be5dec7c6219b63a55b4c3c77114d50e8 |