Transport

A Python program for collecting experimental data from instruments

The source code is available on Github, and the manual and code API are available here.

Source Code Manual API

What is it?

Transport is a bit of software I wrote while doing physics research at Penn State collect experimental data.

Here is an outline of features with links to screenshots and more detailed information below:

  1. Experiments: Users can create nested sequences of actions to manipulate scientific instruments and collect data from them.
  2. Instruments and Actions: The instruments and actions are highly configurable via dialogs.
  3. Extending the Code: A new instrument requires only a single file in the correct location. It will automatically be detected, and configuration dialogs for it and all of its actions will be generated.
  4. Graphing: Data can be graphed in real time.
  5. Configuration: File storage and graph appearances can be configured globally or for each user.
  6. Premade Experiments: Tailored graphical interfaces can be created for experiments that are run frequently.

Experiments

Experiments are sequences of actions performed on instruments. The user can configure experiments by dragging and dropping actions into the experiment tree. The System instrument supports various kinds of looping, delays, and blocks of actions to execute simultaneously (i.e. in separate threads), as well as performing calculations using data that have been collected so far.

Back to feature overview

Instruments and Actions

Any number of instruments can be added to an experiment, and each is configurable via dialog boxes. Each instrument defines its own set of actions, what inputs those actions require, and what data the actions return. Both inputs and outputs can be recorded to data files by giving them "Column Names" in the action configuration dialogs.

Back to feature overview

Extending the Code

Adding a new instrument to the program requires writing only a single file of Python code and putting it in the correct location. The syntax for the file is described in the manual. The actions available to the instrument are defined in a list describing the inputs and outputs. Transport will automatically detect instrument files, show the instrument in the Add Instrument dialog, and build configuration dialogs for the instrument and all defined actions.

Back to feature overview

Graphing

Data—anything assigned a column name in an action configuration dialog—can be graphed in real time. An arbitrary number of graphs can run at a time, and configuring the axes and when to start a new plot (i.e. a new line with a new color) is easy. All open graphs are automatically saved to disk when an experiment finishes.

Back to feature overview

Configuration

Default data file storage settings, graph color sequences, and graph refresh rate can be changed using a Settings dialog. If multiple people are using the same computer, users can be created. Each user can define his or her own default file settings, as well as input a telephone number to receive text alerts when an experiment finishes or an error occurs.

Back to feature overview

Premade Experiments

It's fairly common in science to perform the same set of measurements over and over, but on different samples. Premade experiments make this easier.

Premade experiments are experiments with their own custom user interfaces, with all of the appropriate configuration options and graphs immediately available. As with instruments, only a single file needs to be written to define a premade experiment. If that file is in the correct location, Transport will find it and make it available automatically—there's no need to alter any pre-existing code.

Back to feature overview

Premade experiments are filterable based on a few variables set in the experiment's Python file.

Back to feature overview

Why was it written?

The typical way that experimental data are collected in research labs is using a “programming language” called LabVIEW, developed by National Instruments. Programs are developed by dragging little squares which represent “virtual instruments”—the LabVIEW equivalent of functions or methods onto a canvas, and data flow is accomplished by making connections, called “wires,” between the inputs and the outputs of various virtual instruments.

LabVIEW has a number of advantages over more traditional programming languages:

  1. It is fairly self-explanatory to use, so non-programmers can make functional (though, from my experience debugging others’ programs, horribly planned and inelegant) programs.
  2. It makes user interface design extremely easy: components are dragged-and-dropped onto a “front panel”, just like virtual instruments.
  3. Implementing multiple threads is trivial—just create a branch when you're drawing wires.

It also has some serious disadvantages.

  1. Dragging-and-dropping—and digging through the menus and panels to find the virtual instruments to drag and drop—is infuriatingly slow for someone who knows how to type.
  2. Features of many editors, especially code-completion, cannot be used.
  3. To avoid confusing novice programmers, the developers of LabVIEW made passing objects by reference rather than by value nearly impossible—it requires patterns that most people would regard as hacks.
  4. The use of wires to control data-flow makes copying and pasting and search-and-replace difficult.

In my opinion, the disadvantages far outweighed the advantages. Thus, I began looking for ways to communicate with scientific instruments using a textual but reasonably modern programming language. At first, I was looking to do it with Java (my main language at the time). My searches kept bringing up comments about PyVISA, and eventually I ended up learning Python to develop an alternative system for collecting data.