Using the Python debugger

A few days ago I found out that using the Python debugger is so easy, I can’t believe I haven’t used it before.

Import the module:

import pdb

Set a breakpoint somewhere in your code:

def some_function(self, x, y, z):
    pdb.set_trace()
    ...

Run your program. Now every time ‘some_function’ is called, the Python interpreter will break. At this point you could:

  • type x to inspect the argument passed to the x parameter
  • hit the ‘n’ button to skip over the next line of code
  • hit the ‘c’ button to resume the program
  • hit the ‘h’ button to get help

Easy enough?

Sequential writes leveldb versus system_x

OK, calling it a benchmark is a bit of an overstatement. It’s taking two different database libraries for a quick spin, and seeing how fast they can write a bunch of integers to disk. A second benchmark checks how fast we can read them.

In this mini-test, I’m running leveldb against a new embedded database library, let’s call it system_x. The purpose is really just so that I can remember some rough numbers regarding these useful database libraries.

I used the time command to gather results, which shows real, user and sys time spent.

Read more

Plotting data on maps with matplotlib

I’m learning about matplotlib, and actually just bought the book Matplotlib for Python Developers.

Geographical plots

Browsing stackoverflow, the matplotlib homepage, and other resources, I eventually came by this stackoverflow post, which mentions BaseMap. Since the data that I’m plotting is inherently geographical, it makes sense to show the data on a map.

There are several nice examples on the basemap Github page.

Heatmaps

Often I want to create heatmaps of the data, using matplotlib.

On stackoverflow there are several posts on this topic:

There are different colormaps available for matplotlib, if you want to try different colorschemes.

How to install gfortran on Mac OS X

Why did I install gfortran? Well, not to write Fortran programs. I tried installing SciPy using pip install scipy, and I got a message that a Fortran compiler was needed.

Install

This is how I installed gfortran on my Mac:

Visit hpc.sourceforge.net, and select a binary distribution for your version of Mac OS X, e.g. gfortran-snwleo-intel-bin.tar.gz for Snow Leopard.

Read more