Constrained least-squares fitting with Python
Friday, March 5th, 2010 Posted in Python, Scientific computing | No Comments »Scipy contains a good least-squares fitting routine, leastsq(), which implements a modified Levenberg-Marquardt algorithm. I just learned that it also has a constrained least-squared routine called fmin_slsqp(). I am using simple upper and lower bound constraints, but it's also possible ...
Storing large Numpy arrays on disk: Python Pickle vs. HDF5
Sunday, January 10th, 2010 Posted in Python, Scientific computing, Software development | No Comments »In a previous post, I described how Python's Pickle module is fast and convenient for storing all sorts of data on disk. More recently, I showed how to profile the memory usage of Python code. In recent weeks, I've uncovered ...
Building and linking to a shared Fortran library
Monday, October 26th, 2009 Posted in Fortran, Linux, Scientific computing | No Comments »I'm using GNU Fortran (gfortran) to build several shared libraries, and then dynamically linking to them from a Fortran program. The process is a little different than what I'm used to for C libraries, so I thought I'd explain it. ...
Profiling memory usage of Python code
Friday, April 17th, 2009 Posted in Linux, Python, Scientific computing, Software development | 2 Comments »In a previous post, I explained how to use the Python profiler. The profile is great for finding out which parts of the code run the slowest, or are called most often. However, the profiler doesn't give any information about ...
Lookup tables and spline fitting in Python
Wednesday, April 8th, 2009 Posted in Python, Scientific computing, Software development | No Comments »Lookup tables and spline fitting are widely used by scientific programmers. A particular function may not have an analytic solution--in other words, it can't be expressed as an equation of elementary functions. This might happen if the function were empirically ...
3D Plotting Software for Python::Part 1::PyX
Friday, March 20th, 2009 Posted in Python, Scientific computing, Software development | 3 Comments »There are lots of good open-source tools that you can use to make high-resolution, publication-quality 2D plots. Personally, I like to use Python, numpy, and matplotlib. Unfortunately, it is much harder to find a good tools to make 3D plots. ...
Updated Python class for writing Paraview (VTK) (.vtu) files
Friday, January 23rd, 2009 Posted in Python, Scientific computing | No Comments »I have released a new version of my Python class that generates VTK data files in the .vtu format, which is compatible with Paraview and other VTK applications. If you have downloaded the old one, please get the latest version, ...
Scipy.integrate ODEPACK import error solved!
Wednesday, January 14th, 2009 Posted in Linux, Python, Scientific computing | No Comments »I recently found a solution to a problem that had been vexing me for about a year. In order to successfully import anything from scipy.integrate, I had edit the file scipy/integrate/__init__.py and comment out the line from odepack import * If ...
Optimizing Python code for fast math
Friday, January 9th, 2009 Posted in Python, Scientific computing, Software development | 1 Comment »I spent some time today profiling a Brownian dynamics simulation written in Python to see how I could make it faster before starting some long runs on a Linux cluster. In the sections below, I have attempted to quantify ...
A lookup table for fast Python math
Thursday, December 11th, 2008 Posted in Python, Scientific computing | 2 Comments »EDIT: the UnivariateSpline class from Scipy is much faster! Numerical programming frequently requires the use of look-up tables. A look-up table is a collection of pre-computed values. When given an "x" value, the table returns a pre-computed "y" value. ...
Update 2: building 64-bit Numpy with Intel compilers and MKL
Tuesday, December 9th, 2008 Posted in Linux, Python, Scientific computing | No Comments »In a previous post I described how I built Numpy with Intel compilers and the Math Kernel Library on a 64-bit cluster. Today I upgraded to Numpy-1.2.1 and I made a few improvements to my install process. Please ...
Even faster collision detection in Python using Numpy
Thursday, October 16th, 2008 Posted in Python, Scientific computing, Software development | No Comments »Last night, in the shower, I realized that my collision detection routine could be even faster. Here is a representative snippet of code from my previous post: d2 = (x-self.x[0:i])*(x-self.x[0:i]) + (y-self.y[0:i])*(y-self.y[0:i]) + (z-self.z[0:i])*(z-self.z[0:i]) For some reason, I ...
Installing numpy with the Intel Math Kernel Library (mkl)
Friday, September 19th, 2008 Posted in Linux, Scientific computing | 1 Comment »Today I installed numpy on a cluster. Normally, as a Gentoo admin, I just install things with emerge, and all the details are taken care of automagically. However, this cluster runs Red Hat Enterprise, and I don't have ...
Reading Labview binary files with Python
Wednesday, June 25th, 2008 Posted in Scientific computing, Software development | 4 Comments »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 ...

