Posts
Redirecting text output from Python functions
Two posts ago, I described how I wrote a function in Python that reads in a binary file from Labview. In my last post, I described using wxPython to write a GUI to process the data from those binary files. Naturally, I called the binary-file-reader function from the GUI. The problem is that the file reader prints a lot of information to the terminal, using Python printstatements. None of this goes to the GUI, requiring the user to run the GUI from a terminal and keep an eye on the text output, which is inconvenient. However, I don’t want to modify the file reader to include GUI-specific code, because that would be less modular and less re-usable. Instead, I learned that Python has a very easy facility to redirectstdout, the default destination of the print statement. I modified the file reader as follows:
Fun with threads in Python and wxPython
I have finally gotten back to programming in the last couple of days. Our project has finally started to generate a lot of data, so I’ve been refactoring and improving my code that reads data stored in LabView binaries. Today I spent a lot of time creating a GUI for browsing data. Arguably, this wasn’t the best use of my time, but I learned a lot about multi-threaded Python GUI programming with wxPython. You can find a gold mine of information on the multi-threaded wx programming at the wxPython wiki. Because the LabView binary data has to be read sequentially, and the files are rather large, it takes a long time to read in a file. I spawn a thread to handle the file reading, while allowing the GUI to remain responsive. The thread posts messages to the GUI window, which are used to update the user on the status of the file reading operation. When the file is read, a final message containing the data is posted to the window. It’s really pretty slick now that I’ve figured out how to do it. I will soon post a clever scheme to capture text output from the file-reading function, and display it in the GUI, without making substantial changes to the file-reading function.
Reading Labview binary files with Python
My research group uses Labview 7.1 to write custom data acquisition (DAQ) software. I code everything else in Python, so I need to get data from Labview into Python for processing. Our DAQ program produces Labview binary files, so I had to find a way to read them with Python. Binary files are nice because they are a compact way to store numerical data as compared to ASCI or (heaven forbid) XML, but they are much harder to read. The binary format used by Labview is documented only indirectly, so I had to hack a little. The first thing to realize is that the Labview binary file is a direct dump of the data that was stored in RAM. How Labview stores data in memory is documented here. Indirectly, this documents how binary files are stored on disk. Our DAQ program writes a rather complex “cluster” (Labview’s version of a C structure) to disk. The elements of the cluster are stored contiguously as a sequence of bytes, and there’s no way to know which byte goes with which element, unless you know the size of each element and the order in which they are stored in the cluster. So, the first step is to document the cluster that’s being written to disk. You can use the context help in Labview to view the data type of the wire that leads to the VI that writes the file. With this in hand, you are ready to write Python code. First, make sure you open the file in binary mode:
Server move completed and general update
The site is back online after a server move. Actually I can’t blame the server move for the downtime, because I went out of town and then had a lot of catching up to do, and as a result I didn’t switch the domain to point to the new server. I haven’t been blogging much because I haven’t done much software development, Linux admin, or lighting design lately. I have been busy in the lab at work and I’ve been supervising a trainee lighting operator instead of running my own shows. We haven’t been moving forward with plans to purchase a new lighting control console, so no update on that, either. Hopefully, I’ll have something interesting to post soon.
Presentation at BarCamp Orlando 2008
I gave a presentation at BarCamp Orlando on 5 April 2008. Here is a link to my presentation, Data Analysis with Python.
Connecting to a Windows file server from a Linux box
Updated 18 Jan 2013
Gentoo
There are two basic prerequisites for mounting a Windows share on a Gentoo Linux client. First, your kernel must be compiled with cifs support. Second, you must emerge the appropriate packages. The package used to be called mount-cifs, but this package is obsolete. You only need to install net-fs/samba, which will pull in net-fs/cifs-utils and a few other dependencies. The Samba page on the Gentoo Wiki is pretty good. Since you probably need a user name and password to log in to the Windows share, you should create a credentials file. You don’t want to specify your password on the command line because it will be saved in your .bash_history file and unauthorized users may be able to see it. I created a file called /etc/credentials.txt and set permissions so that only root can see it. The format is:
Found a bunch of templates
I use XFCE as my window manager, with Thunar as my file manager. Thunar has always had this “Create Document -> from template” entry in the File menu, but it didn’t come with any templates. I finally went looking for some templates, and found a good collection at stalefries. Just unpack the archive in a directory called “Templates” in your home directory. BTW, isn’t it about time I created a “linux” category instead of trying to stuff my Linux entries under the “software development” category?
Cheap LED fixtures
Normally, we stay far away from anything marketed to DJ’s, but we’ve been experimenting with cheap LED fixtures as an inexpensive way to put more colors on stage. LED fixtures have a few advantages: they efficiently produce light without much heat, they don’t require a dimmer, and they can produce multiple colors without gel changes. They also have some disadvantages. Color mixing is produced by combining LED’s of different colors (RGB) at different intensities, so the color is only “mixed” at the surface it is illuminating. It can be difficult to produce white light that matches light from other fixtures. LED’s cannot be dimmed by lowering the voltage, like a conventional light. Instead the LED is strobed (pulsed) at a rate too fast for your eye to discern. Unfortunately, the Chauvet ColorPalette fixtures shown below use a pulse rate that is slow enough that it can be picked up on a video camera. When the fixtures illuminate a set piece like this one, which is in the background of many IMAG shots, the flicker is very distracting if the intensity is run at anything less than 100%
Practically speaking, when a Color Palette is visible on camera,we can only get seven full-intensity colors: red, blue, green, white, purple, blue-green, and yellow. We’ve since moved them out into the auditorium where they are used to illuminate the walls. We did find one really cool application for these lights. We have a number of deep-purple, “blacklight” Color Palettes mounted backstage to enable people to move in the dark. They stay on all the time, draw very little power, and are totally invisible to the audience, even during a dead blackout.
This is a Chauvet COLORado 1, which is meant to replace a small par can. It’s mounted on a pipe above and behind the musicians and lights them from behind. This is the view you get from the front row in the audience. See the red, blue, and green LEDs? That’s producing white light, but you wouldn’t know it from this angle. That’s what happens when the colors don’t mix at the light. We don’t have the strobing problem on video with the COLORado’s, but I don’t know if that’s due to their positioning or their design. For more information, see the LED lighting reviews by onstagelighting.co.uk. There are also pro-grade LED fixtures that are much better…but I haven’t used them.
Cool set design: Part II
Here’s another cool set design. What’s interesting about these two pictures is that the set is illuminated using the same lights at two different intensity levels, but the color seems different. That’s a neat feature of incandescent lights–at low intensity you can get deep, saturated colors. 
Here is a look in another color.
I didn’t think to take close-up pictures of this set. It turns out that our set designer likes to have these pictures, so now I’m trying to do a more thorough job. This one is constructed of a wooden frame with a light colored wrinkly fabric stapled to it. Like I said, I don’t design or build these things, but if you want to know the details, I’m sure I can find out for you.