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):
convolution_inf
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):
Convolution of two tophats
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.

Advertisements

4 responses to “matplotlib convolution animation”

  1. Krioma.net Blog says :

    More convolutions

    So a friend of mine asked if I could produce the same animation I did the other day of the [convolution of two top hats] but this time of two Gaussians. Pretty straight forward really: If you want to take…

  2. Michael Lerner (@mglerner) says :

    Hi,

    This looks very nice. Unfortunately, clicking on convolve.py gets an error. Can you check the permissions?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: