Posts

A Pint a day ...

A few months ago I wrote about Pint , a Python units library that we developed for Lantz . With Pint  you can define physical quantities: the product of a numerical value and a unit of measurement. Pint can convert between units and perform mathematical operation between quantities. For example: >>> from pint import UnitRegistry >>> ureg = UnitRegistry() >>> my_beer = ureg.pint >>> print(my_beer.to('liter')) 0.473176473 liter >>> print(my_beer.dimensionality) [length] ** 3 >>> ureg.pint < ureg.imperial_pint True >>> ureg.pint < ureg.liter True As described in the Design principles section of the documentation, units definitions are loaded from a text file which is simple and easy to edit. Adding and changing units and their definitions does not involve changing the code. Prefixed and pluralized forms of units are recognized without explicitly defining them. In other words: as the prefix kilo and the u...

How many Pints do you want? Units in Python

Image
I tried many of the Python Units packages available when I started adding physical quantities (magnitude and units) support to Lantz . There are really great packages out there providing NumPy support and a broad definition list including units and constants. However these packages define the units within the Python code. This results in an unnecessary large and difficult to maintain package. Additionally, translation to other languages and changing to an incompatible system (eg. from SI to Gaussian ) is impossible without changing the codebase. Pint is a units package for Python that keeps the definitions in a separate text file .  The text file is really easy to read and modify, allowing you to update the unit definitions without changing the code. For each unit, you just type the relation with other units. Aliases can be added after the second equal. For example, here are the definitions of hour an minute : hour = 60 * minute = h = hr minute = 60 * second = min ...

The structure of a Lantz Driver

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. All Lantz drivers classes are derived from Driver , which provides the infrastructure and boiler plate code to perform common operations. Logging, timing, async calls and other features are enabled by sub-classing from Driver. But usually you do not subclass from Driver directly, but rather from a specialized class depending on the way you communicate with your instrument. For example, if the instrument is controlled over RS-232 (Serial), you sub-class from SerialDriver . If it is controlled over TCP, you sub-class from TCPDriver . There is also a class for GPIB and there be soon will for USB. All these classes belong to the same family as they communicate with instruments by exchanging  textual messages. They share a common interface and therefore it is very easy to build drivers that support different commu...

Moving to Lantz

Image
Lantz is a Python automation and instrumentation toolkit that allows you to control instruments in a clean and efficient manner writing pure Python code. Since I released Lantz a few weeks ago, I have received a lot of positive e-mails about the project. Most of them can be summarized as: It looks very nice! I love Python and I have been looking for a Pythonic way to do instrumentation! It is encouraging to receive such positive comments and also confirms that Lantz is in the right path: Not a Domain-specific language, not a do-it-my-way framework, but a complete, coherent and concise set of classes and functions for instrumentation in Python. Lantz provides base classes and functions decorators to help you write your drivers as shown in the figure (thanks Pablo Jais!). Y ou can find more details in the documentation's overview . Inertia is what stopping many to start using Lantz. For most of us, instrumentation is the means to an end. We need to measure, do experiment...

Announcing Lantz: Instrumentation in Python

Image
Today I am releasing Lantz , a Python automation and instrumentation toolkit that allows you to control instruments in a clean and efficient manner writing pure Python code. Instrumentation and experiment automation became a cornerstone of modern science. Most of the devices that we use to quantify and perturb natural processes can or should be computer controlled. Moreover, the ability to control and synchronize multiple devices, enables complex experiments to be accomplished in a reproducible manner. This toolkit emerges from my frustration with current solution. If you have worked in a research lab, you know that most that is out there is done using Domain Specific Languages (DSL) like LabVIEW and MatLab Instrumentation Toolbox . They are great for their original purpose but as soon as you want to code a real application their idiosyncrasy gets in the way. They lack certain features and good design that we enjoy in some general purpose languages. So the choices are: you ...