Posts with the category Computations

Pandas / PyTables Error Trying to store a string with len [42] in [values_block_0] column

If you get an error message like

Traceback (most recent call last):
  File "./", line 81, in <module>
  File "./", line 63, in main
    store.append('df', df, format='t', complib=None)
  File "/home/philipp/.pyvenv/playground-3.4/lib/python3.4/site-packages/pandas/io/", line 904, in append

Read on

Counting bits set to 1 in bytes with Python / Popcount or Hamming Weight

I want to run popcount on a large set of 144-byte-long bytearrays. Doing so in Python can be a pita! First, I was using the naive approach with bin(b).count('1') but it was very slow. I did some research on the internet for faster algorithms and I found some. But running...

Read on

False Color Plots

False color (or more exactly pseudo color) can be useful when a device / detector records a grayscale image and a human has to interpret it. Fine differences are hard to see in grayscale images und a false color mapping allows us to map the 255 shades of gray...

Read on

Maximum Value in 2D Array in Matlab

Finding the value and the position of the maximum value in a 2D array (or the first one if there are more than one maximum values) can be done like this:


Read on

Creating a Gaussian Window in 3D Using Matlab

If you want to create a gaussian window with Matlab in three dimensions (as you can do in two dimensions with the built-in gausswin()) you can use the function gauss3D() found on MATLAB Central:

S = gauss3D(20,20,7);

Read on

German Tax ID – Calculate the Check Sum using Python/ Steuer-Identifikationsnummer – Prüfsummenberechnung mit Python

Calculate the Check Sum for a German Tax ID number using Python:

#!/usr/local/env python
# -*- coding: utf-8 -*-

class CalcCheckCipher(object):
    def getCheckCipher( idnrString):

Read on

ezyfit - An Alternative to Matlab's Curve Fitting Toolbox

ezyfit can prevent you from buying the Curve Fitting Tool that Matlab does not come with by default. This is how I use it to fit data according to a function :

y = 30 +...

Read on

Handle 16bit TIFF Images in Python

There seem to be quite a lot of problems with 16-bit grey scale TIFF images (especially with the Python Imaging Library - PIL). If you can, you may want to use FITS instead of TIFF. There are good and up-to-date libraries for Python: PyFITS.

For me, however, the FreeImage...

Read on

hub teaches git about GitHub

Hub is a useful extension to make git GitHub aware.

catch lines:

hub introduces git to GitHub
hub teaches git about GitHub


brew install hub


See hub's webpage for introductory examples and its man page for further reference.


Read on

Light Wavelength from Energy

You can use the following Python function to convert a photon energy (in electron volts) to the corresponding wavelength (in nano meters):

def wavelength_from_energy ( electron_volts):
    """Returns a photon wavelength in nm from a photon energy given in eV."""

Read on

Physical Constants in Python

SciPy (updated to CODATA 2010)

Installation (easiest using pip):

  1. Install Fortran as described for your OS on (or via brew install gfortran on Max OS X)
  2. Install SciPy itself: pip install scipy


from scipy.constants import *
print "The Planck constant h:", <span...

Read on

Install matplotlib on Mac OS X

Installation of the pre-built binaries for OS X

Read Installing OSX binaries in the matplotlib Installation FAQ.

Installation via pip

This is a good way if you have an up-to-date Python installation on your computer and pip installed. It takes, however, some time (~ 20 mins for me) to install as it...

Read on

Image Functions in Matlab

Matlab has several functions to handle images:

info = imfinfo(filename)
A = imread(filename)

Create an animated GIF image

x = 0:0.01:1;

Read on

Use XML files in Matlab

Here are the solutions I've found on the web:

Read on

A PID Controller in Python


Read on

Estimate the transform limited beam duration of a laser pulse from its spectral width in nm in Python

A transform limited pulse has a time-bandwidth product of for Gaussian beams.

Here are a couple of Python functions to find the minimum duration of a gaussian pulse with a certain spectral FWHM (measured in nm) at a given central wavelength plus the...

Read on

Newport Power Meter 2935T-C via libusb on Linux

This power meter from Newport has a serial RS232 and a USB connection. This page tries to find out how it's possible to talk to the device via USB. For RS232 connection, look at the blog post Newport Power Meter 2935T-C – Serial Connection via Python.

USB Connection Info

Output of...

Read on

Octave on Mac OS X

You can either download a *.dmg from

Or you can also install it via homebrew using:

brew install octave

I also wanted to install gnuplot including its AquaTerm terminal via homebrew (see Soeren's comment on But the build for AquaTerm failed :( :

cd /usr/local/Library/Formula/

Read on

Convert between Power and dBm

Many devices that send & receive data via antennas give you information about their power in units of dBm. If you wan to know how to convert this unit to a power value given in mW (and vice versa) you may read on.

The formulae found in the Wikipedia article...

Read on

Convert between plus-cylinder and minus-cylinder notation in eyeglass prescription writings using Python

Doctors in Germany usually give out prescriptions with negative values for the cylinder. Some eyeglass manufacturers list their products with plus-cylinder notation so the optometrists have to convert the notations.

Online Converter

If you want to convert your prescription writings, I created this online tool to convert your values:

Convert Cylindrical Notation


Read on

Chinese OCR

OCR for Windows

OCR for Mac OS

Read on