Posts

Showing posts with the label Python

The state of the PyVISA ecosystem (and more)

Yesterday we released several packages of the Python Instrumentation Ecosystem. You can upgrade to  PyVISA 1.8, PyVISA-py 0.2 and PyVISA-sim 0.3   by: pip install -U pyvisa pyvisa-py pyvisa-sim For those of you who are new to instrumentation in Python,  PyVISA is a Python frontend for the VISA specification that enables controlling all kinds of measurement equipment through GPIB, RS232, USB and Ethernet among others interfaces. If you are familiar with VISA instruments in LabVIEW, Matlab, C or .NET you already know how it works and you can make use of PyVISA as a nice Pythonic API to write your programs . If you have never done any instrumentation, Python and PyVISA is great combination to start . Code:  https://github.com/hgrecco/pyvisa Docs :  http://pyvisa.readthedocs.org/ Tracker:  https://github.com/hgrecco/pyvisa/issues As I mentioned before PyVISA is a frontend for the VISA specification, but what does this means in terms of software?...

PyVISA-sim. Test your PyVISA applications without connected instruments

I have just released PyVISA-sim 0.1.  PyVISA-sim is a backend for  PyVISA . It allows you to simulate devices and therefore test your applications without having real instruments connected. While there still a lot of features to add, this early release already allows you to: - play around with a simulated device. - write your own simulated  device  in YAML files.  - simulated  devices can include commands and properties which are automatically generated from the YAML file. - Properties can have some basic validation rules. Install it using:     pip install -U pyvisa-sim Code:  https://github.com/ hgrecco/pyvisa-sim Docs:  http://pyvisa-sim. readthedocs.org/ Tracker:  https://github.com/ hgrecco/pyvisa-sim/issues

Lantz 0.3 is out: better PyVISA support, leaner drivers, great GUI building blocks

Lantz is a Python automation and instrumentation toolkit that allows you to control scientific instruments in a clean and efficient manner writing pure Python code. After waiting for a long time, Lantz 0.3 is out. It took a while, but it was for a good reason: we were toying, playing and testing with new ideas to make Lantz better. I am going to go quickly over some of them. MessageBasedDriver: a class to rule them all MessageBasedDriver  replaces all previous Driver classes for message based instruments. It leverages the power of PyVISA to talk over many different interfaces. But remember that this does not mean that you require NI-VISA installed. You can still talk via the pyvisa-py backend which uses PySerial / PyUSB / Python Standard library. You can also use the pyvisa-sim backend to simulate devices! Great GUI applications Lantz provides two classes to help you build applications: Backend and Frontend. The first contains the logic of your application and the...

Pint 0.6: faster and with better non-multiplicative units support

I have released version 0.6 of Pint, a Python units library. Pint is Python package to define, operate and manipulate physical quantities: the product of a numerical value and a unit of measurement. It allows arithmetic operations between them and conversions from and to different units. It provides a comprehensive and extensive list of physical units, prefixes and constants defined in a standalone text file. The registry can parse prefixed and pluralized forms of units resulting in a much shorter and maintainable unit definition list. It also provides great NumPy integration without monkey patching or importing a particular module, with implicit unit conversion and an emphasis on correctness. What's new The largest change landed in the way Pint handles offset units such as temperatures. It now provides a much better behavior that is both correct and useful. It deals properly with differences of temperatures, providing useful error messages when the requested operat...

PyVISA command-line utilities

PyVISA is a Python frontend for the VISA library that enables controlling all kinds of measurement equipment through GPIB, RS232, USB and Ethernet among others interfaces. If you are following the development of PyVISA you might have seen that we have recently made the visa module executable to provide a few useful utilities. To try this, you need to update to the latest PyVISA: $ pip install -U https://github.com/hgrecco/pyvisa/zipball/master First, we now provide a simpler way to get debug information: $ python -m visa info Machine Details:    Platform ID:    Darwin-10.8.0-x86_64-i386-32bit    Processor:      i386 Python:    Implementation: CPython    Executable:     /Users/grecco/envs/lantz/bin/python    Version:        3.2.3    Compiler:       GCC 4.2.1 (Apple Inc. build 5666) (dot 3)  ...

Communicating with instruments using PyVISA but without NI-VISA

PyVISA is a Python frontend for the VISA library that enables controlling all kinds of measurement equipment through GPIB, RS232, USB and Ethernet among others interfaces. Starting form version 1.6 , PyVISA allows to use different backends. The cool thing is that your code remains the same, except the line in which you instantiate the resource manager (which tells which backend to use). A few days ago I blogged about one of such alternative backends called PyVISA-sim which allows your to mock the presence of instruments (in cased that you missed the announcement, is here ). Today I am making public a second backend.   Until now, talking to instruments via PyVISA required that you had National Instruments VISA library installed in your system. This works most of the time, for most people. But NI-VISA is a proprietary library that only works on certain systems. That is when PyVISA-py jumps in. It is an implementation of message based communication (Serial/USB/Ethernet) using...

Simulated devices in PyVISA: early preview

PyVISA started as wrapper for the NI-VISA library and therefore you need to install National Instruments VISA library in your system. This works most of the time, for most people. But sometimes you need to test PyVISA without the devices or even without VISA. Starting form version 1.6 , PyVISA allows to use different backends. These backends can be dynamically loaded. PyVISA-sim is one of such backends. It implements most of the methods for Message Based communication (Serial/USB/GPIB/Ethernet) in a simulated environment . The behavior of simulated devices can be controlled by a simple configuration in plain text . In the near future, you will be able to load this from file to change it depending on your needs. To test it you need to install PyVISA 1.6 which is currently only available from GitHub: $ pip install -U https://github.com/hgrecco/pyvisa/zipball/master And then install: $ pip install -U https://github.com/hgrecco/pyvisa-sim/zipball/master     For...

PyVISA 1.6 brings comprehensive resources classes, thread-safety and more

PyVISA is a Python frontend for the VISA library that enables controlling all kinds of measurement equipment through GPIB, RS232, USB, Ethernet among others interfaces. PyVISA 1.6 release is close and it brings several new nice things. One of the most visible improvements is the addition of a comprehensive set of resources classes , each mapping to a one of the 13 types of resources. Each class implements the methods and attributes that the specific session can handle, providing a Pythonic way to interact with the device (See here ). This has allowed us to implement higher level functions such as the group execute trigger in the GPIB Interface. PyVISA 1.6 brings a much better way to query a device for values , providing a comprehensive API to convert back and from ASCII and binary blocks. An API to write values to a device has been added (See here ). PyVISA 1.6 is thread-safe . While the VISA library has always been thread-safe, PyVISA was not. We have refactored the code r...

PyVISA 1.5 is out

PyVISA is a Python wrapper for the VISA library that enables controlling all kinds of measurement equipment through GPIB, RS232, USB and Ethernet. It has served the instrumentation community very well since 2005 (that's Python 2.3!) and still does. However, Python and the different supported platforms have changed a lot in the recent years. We thought that PyVISA could use an update. Within the Lantz Project we did a small proof of principle of such update in visalib . Now we are taking what worked well and use it into PyVISA 1.5 (without changing the API!). In other words, PyVISA 1.5 brings several important changes in the underlying architecture without forcing you to change the programs . Some time ago I posted that we were going beta. Now PyVISA 1.5 is finally released. The new architecture is summarized here and the comparison with the previous one is here . Briefly you get Python 3 support , Mac OS X support , a better way to find libraries in your platform , a...

Pint 0.5: now with uncertainties!

Today I have released version 0.5 of Pint, a Python units library. Pint is Python package to define, operate and manipulate physical quantities: the product of a numerical value and a unit of measurement. It allows arithmetic operations between them and conversions from and to different units. It provides a comprehensive and extensive list of physical units, prefixes and constants defined in a standalone text file. The registry can parse prefixed and pluralized forms of units resulting in a much shorter and maintainable unit definition list. It also provides great NumPy integration, with implicit unit conversion and an emphasis on correctness. What's new Pint 0.5 brings a long awaited feature: the integration with uncertainties , a great package by Eric Lebigot. Pint Measurement Class is now built using uncertainties ufloat class. The integration will be complete in 0.6 when we add support for all math operations. By the way, the integration of uncertainties in Pint is ...

A new PyVISA release is around the corner and we need your help

PyVISA is a Python wrapper for the VISA library that enables controlling control all kinds of measurement equipment through GPIB, RS232, USB and Ethernet. It has served the instrumentation community very well since 2005 (that's Python 2.3!) and still does. However, Python and the different supported platforms have changed a lot in the recent years. We think that PyVISA can use an update. Within the Lantz Project we did a small proof of principle of such update in visalib . Now we are taking what worked well and use it into PyVISA 1.5 (without changing the API!). In other words, PyVISA 1.5 brings several important changes in the underlying architecture without forcing you to change the programs. The new architecture is summarized here and the comparison with the previous one is here . Briefly you get Python 3 support , Mac OS X support , a better way to find libraries in your platform , an isolated ctypes wrapper. But the most important change is that the VISA library is not op...

Context aware unit conversion in Pint

Today I am releasing version 0.4 of Pint, a Python units library. Pint is Python package to define, operate and manipulate physical quantities: the product of a numerical value and a unit of measurement. It allows arithmetic operations between them and conversions from and to different units. It provides a comprehensive and extensive list of physical units, prefixes and constants defined in a standalone text file. The registry can parse prefixed and pluralized forms of units resulting in a much shorter and maintainable unit definition list. It also provides great NumPy integration, with implicit unit conversion and an emphasis on correctness. What's new Pint 0.4 introduces the concept of Context. A Context enables to convert between unrelated dimensions based on pre-established rules. For example, in spectroscopy you might require to convert between wavelength and frequency. As expected, Pint will raise an error if you try to do this:     >>> import ...

Running Python code in a LaTeX document

Image
I am currently working on a LaTeX document in which the content is still in a very fluid phase and  the figures change often. I usually have a Python script that prepares the figures and saves them as PDFs. To iterate faster, I wanted to insert Python code directly into LaTeX, executing the code when the document is compiled. Googling around I found that I was not the first one to want this. There is this LaTeX package with this github repo . The package provides a new environment ( python ) within which you can write arbitrary Python code. The code is executed when the document is compiled and the output is inserted into the document. I try it and it worked like a charm. It was even printing the traceback in red when there was an error in the script. You can do things like this: \documentclass[a4paper]{book} \usepackage[pdftex]{graphicx} \usepackage{python} \begin{document} A simple example: \begin{python} print(2+3) \end{python} \vspace{1cm} Generating and displaying...