## 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 "./append_to_hdf5.py", line 81, in <module> main() File "./append_to_hdf5.py", 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/pytables.py", line 904, in append **kwargs) ...

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

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

## 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:

[v,ind]=max(X); [v1,ind1]=max(max<span...

## 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); slice(<span...

## 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): @staticmethod def getCheckCipher( idnrString): ...

## 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 :

x=15:45 y = 30 +...

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

## hub teaches git about GitHub

Hub is a useful extension to make git GitHub aware.

catch lines:

hub introduces git to GitHub

and

hub teaches git about GitHub

### Installation

brew install hub

### Usage

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

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

## Physical Constants in Python

### SciPy (updated to CODATA 2010)

Installation (easiest using `pip`

):

- Install Fortran as described for your OS on http://www.scipy.org/Installing_SciPy (or via
`brew install gfortran`

on Max OS X) - Install SciPy itself:
`pip install scipy`

Usage:

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

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

## Image Functions in Matlab

Matlab has several functions to handle images:

info = imfinfo(filename) A = imread(filename) % http://www.mathworks.com/help/techdoc/ref/image.html % http://octave.sourceforge.net/image/function/imread.html image(A)

### Create an animated GIF image

http://www.mathworks.com/support/solutions/en/data/1-48KECO/?solution=1-48KECO

x = 0:0.01:1; <span...

## Use XML files in Matlab

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

**struct2xml**and**xml2struct****struct2xml**(2010-09-06, updated 2011-04-13) http://www.mathworks.com/matlabcentral/fileexchange/28639-struct2xml

Convert a MATLAB structure into a XML file.**xml2struct**(2010-08-20, updated 2011-07-14) http://www.mathworks.com/matlabcentral/fileexchange/28518-xml2struct

Convert an xml file into a MATLAB structure for easy access to the data.

**xml_io_tools**(2006-11-06, updated 2010-11-05): http://www.mathworks.com/matlabcentral/fileexchange/12907-xmliotools

...

## A PID Controller in Python

- PID Controller on Wikipedia: http://en.wikipedia.org/wiki/PID_controller
- Python example (didn't have a close look into it): http://code.activestate.com/recipes/577231-discrete-pid-controller/
- Another Python example with a 3D visualization: http://www.chiefdelphi.com/forums/showthread.php?t=61874
- Python class
`PIDController`

from the cgkit module (Python Computer Graphics Kit): http://cgkit.sourceforge.net/doc2/pidcontroller.html#PIDController - PyPID: http://pypi.python.org/pypi/pypid/

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

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

## Octave on Mac OS X

You can either download a *.dmg from http://octave.sourceforge.net/.

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 http://slashusr.wordpress.com/2010/01/17/gnuplot-with-aquaterm-on-osx-snow-leopard/). But the build for AquaTerm failed :( :

cd /usr/local/Library/Formula/ wget...

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

## 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:**

It...

## Chinese OCR

## OCR for Windows

- PenPower Chinese OCR (Chinese product website: http://www.pen-power.com/chinese/chineseocr.html)

## OCR for Mac OS

- Readiris Pro Asian (English product website: http://www.irislink.com/c2-1685-189/Readiris-12-for-Mac.aspx)
- IRISPen Express Asian (English product website: http://www.irislink.com/c2-1099-189/IRISPen-Express-Asian---Pen-scanner-for-Asian-text-recognition-.aspx)
- Tesseract 3.0 (free, open source) (install via Homebrew formula tesseract.rb and install the Chinese training data file
`chi_tra.traineddata.gz`

or`chi_sim.traineddata.gz`

...