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 together with
NumPy-MKL 1.8.2
Then from the Command Prompt run
C:\Python27\python.exe -m pip install specpy
Start
Working from an external Python console you need to start the Imspector Server
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
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.0.0-cp27-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dabeeba71b08ddbbbd8a76cf5a58b2045261c5ad1caa57755faf82dcedf3a243 |
|
MD5 | 68251952f2d492ee32c68a5b88ac8753 |
|
BLAKE2b-256 | cf560181a417bc8f34222fe32a2c4b3d7dceebff07f4dad0fa3607be2d84b3c9 |
Hashes for specpy-1.0.0-cp27-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8eec174e4cd8e3d653ef0f83041d5cc648532f307b45587c25d9f641c39feea |
|
MD5 | 457ef855288b014e13a9ef83f00cb4cc |
|
BLAKE2b-256 | 84cf48758b8c0c84047507de37c2662ac47e270bbbdfb9b560bb58423f536ad8 |