matplotlib convolution animation
I’ve recently been doing quite a few convolutions, quite important in the paper I’m working on (hopefully to finish soon, more on that soon I hope), and I thought I’d demonstrate a nice example of how todo a convolution in python with the aid of scipy, numpy and matplotlib (actually this is as much a posting for myself so I don’t have to go hunting through my python script directory). It’s actually fairly straight forward, but before that I should just recap what a convolution is.
Essentially a convolution is just an integral that expresses the amount of overlap of one function as it is shifted over by another. This is of great importance in radio astronomy. In synthesis imaging (the key to all large interferometer imaging), the measured dirty map is a convolution of the “true” CLEAN map with the dirty beam (this is determined from the Fourier Transform of the uv-data that is taken by the telescope). If you want to know more about this kind of thing, specifically for radio astronomy, take a look at the [NRAO workshop pages] – tons of info. Mathematically the convolution of two functions is (over infinite range):
Here is an example of the convolution (the green curve) of two rectangular (top hat) functions, there is a slight issue with my plotting that makes them not quite look rectangular (lack of points basically):
As you can see the final product is a triangle. This is really quite simple to code and I’ve aimed to make this a nice an accessible program by doing things in a simplistic manner – take a look at [convolve.py]. The animation is produced using imagemagick and the convert task at the end of the script, if you don’t have this then just comment it out.