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 reused. 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. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Liberté, Égalité, Fraternité GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll
Hi Jochen, Your contribution to the Convolve package is a welcome addition provided that you are willing to tighten up your copyrights a little. Doc/unittest.py has an example of an acceptable copyright, where "Python" should technically be replaced by "numarray", but where the intent remains the same: open source under a BSD-like license. Regards, Todd Jochen Küpper wrote:
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 reused.
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.
Greetings, Jochen
-- Todd Miller jmiller@stsci.edu STSCI / SSG
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 22 Aug 2002 14:25:37 -0400 Todd Miller wrote: Todd> Your contribution to the Convolve package is a welcome addition Todd> provided that you are willing to tighten up your copyrights a Todd> little. That's fine, no problem. You can assume that I am willing to allow a 'modified BSD'-style license [1] on everything that I'll contribute to numarray. I might still send it to the ml as GPL'ed, because that's what I put all my code under initially. (And if it doesn't go into numarray, I'd probably like to keep it that way.) Todd> open source under a BSD-like license. I don't like "normal" BSD so much because I wish to release most of my code GPL'ed, unless somebody asks. But GPL and "normal" BSD don't get along well. (See [1]) So I'll clean it up a little tonight and check it in, if that's ok with you. Greetings, Jochen Footnotes: [1] http://www.gnu.org/philosophy/license-list.html#ModifiedBSD - -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6-cygwin-fcn-1 (Cygwin) Comment: Processed by Mailcrypt and GnuPG <http://www.gnupg.org/> iEYEARECAAYFAj1lMK0ACgkQiJ/aUUS8zY7fmgCfd+3XlZSkdGT/tfOpEZEh3bmu jRUAni3NHLtJWsIumxpkO6anLUyonyPF =EUBk -----END PGP SIGNATURE-----
Jochen Küpper wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Thu, 22 Aug 2002 14:25:37 -0400 Todd Miller wrote:
Todd> Your contribution to the Convolve package is a welcome addition Todd> provided that you are willing to tighten up your copyrights a Todd> little.
That's fine, no problem.
Excellent.
You can assume that I am willing to allow a 'modified BSD'-style license [1] on everything that I'll contribute to numarray. I might
Good.
still send it to the ml as GPL'ed, because that's what I put all my code under initially. (And if it doesn't go into numarray, I'd
That's OK.
probably like to keep it that way.)
Todd> open source under a BSD-like license.
My mistake here. numarray is already using a modified-BSD-like license.
I don't like "normal" BSD so much because I wish to release most of my code GPL'ed, unless somebody asks. But GPL and "normal" BSD don't get along well. (See [1])
To keep open the possibility that numarray might someday be included in Python, we don't want any part of numarray to be GPL'ed. This is a little overkill, because Packages probably wouldn't be on the immediate list of things to submit anyway. Still, it keeps life simple and us out of trouble.
So I'll clean it up a little tonight and check it in, if that's ok with you.
Sounds great!
Greetings, Jochen
Footnotes: [1] http://www.gnu.org/philosophy/license-list.html#ModifiedBSD - -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6-cygwin-fcn-1 (Cygwin) Comment: Processed by Mailcrypt and GnuPG <http://www.gnupg.org/>
iEYEARECAAYFAj1lMK0ACgkQiJ/aUUS8zY7fmgCfd+3XlZSkdGT/tfOpEZEh3bmu jRUAni3NHLtJWsIumxpkO6anLUyonyPF =EUBk -----END PGP SIGNATURE-----
------------------------------------------------------- This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE! https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Regards, Todd -- Todd Miller jmiller@stsci.edu STSCI / SSG
participants (3)
-
Jochen Küpper
-
Jochen Küpper
-
Todd Miller