Posts

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...

Make your functions units-aware with Pint 0.3

Image
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. >>> from pint import UnitRegistry >>> ureg = UnitRegistry() >>> q1 = 24. * ureg.meter >>> q2 = 10. * ureg.centimeters >>> q1 + q2 <Quantity(24.1, 'meter')> 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. >>> import numpy as np >>> np.cos([0, 45] * ureg.degrees) <Quantity([ 1. 0.70710678], 'dimensionless')> >>> np.cos([0, 45] * ureg.meter) Traceb...