[Numpy-discussion] numarray, Convolve, and lineshapes

Jochen Küpper jochen at jochen-kuepper.de
Wed Aug 21 20:56:02 EDT 2002

Looking at Convolve last night I came up with the idea that we often
need to convolute datasets with common profiles, such as Gauss- or
Voigt-lineshapes, for example.

So tonight I took my old module I had for that purpose apart and put
it as submodule into Convolve. Well, currently it really only supports
Gauss, Lorentz, and Voigt, but the general "framework" to add more
profiles is there. Adding a new one would consist of defining a new
derived class (overall 5 lines of code) and providing a function that
calculates the actual line profile.

I chose the implementation using functor classes so profiles can be

I am aware that there are some issues with the functions in
Lineshape.py (error checking, not automatically converting sequences
to arrays, ...). If this is a way to go I would move the functions to
C anyway. Nevertheless a sample function in Python will be provided,
so new profiles can easily added without caring about C.

I would like to get some feedback whether you think this should be
included in numarray. I believe it fits very well into Convolve.

Example use:

import numarray as num
import random as ran
import Convolve
import Convolve.Lineshape as ls

resolution = 0.1
fwhm = 0.5

# get some (random) data, i.e. a stick-spectrum
x = num.arange(-50, 50+resolution, resolution)
y = num.zeros(x.shape, num.Float)
for i in range(10):
    y[ran.randint(0, len(y)-1)] = ran.random()

# create lineshape objects
g = ls.GaussProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), 1.0)
v = ls.VoigtProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), (0.6, 0.6))

# convolute data with profile
res_g = Convolve.convolve(y, g(), Convolve.SAME)
res_v = Convolve.convolve(y, v(), Convolve.SAME)
for i in zip(x, y, res_g, res_v):
    print "%12.6f %12.6f %12.6f %12.6f" % i

I attach an archive of the whole Convolve/ dir here in my local copy.

Einigkeit und Recht und Freiheit                http://www.Jochen-Kuepper.de
    Liberté, Égalité, Fraternité                GnuPG key: 44BCCD8E
        Sex, drugs and rock-n-roll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: convolve.tar.gz
Type: application/x-gzip
Size: 10075 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20020821/6a619820/attachment.bin>

More information about the NumPy-Discussion mailing list