Hi, I would like to do some 3d interpolations. Is it possible with scipy or should I use something different? Greetings! Fabian
Hi Fabian, On 16/09/06, Fabian Braennstroem <f.braennstroem@gmx.de> wrote:
Hi,
I would like to do some 3d interpolations. Is it possible with scipy or should I use something different?
I haven't found any specifically 3-D interpolation routines in scipy, but have used 1-D interpolations successively over each axis to achieve something similar. Have a look at the congrid routine listed in the cookbook (http://www.scipy.org/Cookbook/Rebinning) for an example of how this can be done. Disclaimers: I wrote this when I was just starting to understand numpy so I'm afraid it's ugly and deserving of a rewrite. Also, as I've said there, I'm not actually sure how technically appropriate it is to do interpolation this way, but the results looks about right. Can anyone offer a more educated opinion? In any case, I hope that helps, Angus. -- AJC McMorland, PhD Student Physiology, University of Auckland Armourer, Auckland University Fencing Secretary, Fencing North Inc.
On 2006-09-16, Fabian Braennstroem <f.braennstroem@gmx.de> wrote:
I would like to do some 3d interpolations. Is it possible with scipy or should I use something different?
I find that Scientific.Functions.LeastSquares.leastSquaresFit works well. -- Grant Edwards grante Yow! Hold the MAYO & pass at the COSMIC AWARENESS... visi.com
Hi Grant, * Grant Edwards <grante@visi.com> wrote:
On 2006-09-16, Fabian Braennstroem <f.braennstroem@gmx.de> wrote:
I would like to do some 3d interpolations. Is it possible with scipy or should I use something different?
I find that Scientific.Functions.LeastSquares.leastSquaresFit works well.
Do you have a small working example? Would be nice! Greetings! Fabian
On 2006-09-16, Fabian Braennstroem <f.braennstroem@gmx.de> wrote:
I would like to do some 3d interpolations. Is it possible with scipy or should I use something different?
I find that Scientific.Functions.LeastSquares.leastSquaresFit works well.
Do you have a small working example?
Here's something I just tossed together... ---------------------------------demo.py--------------------------------- #!/usr/bin/python import Scientific.Functions.LeastSquares lsf = Scientific.Functions.LeastSquares.leastSquaresFit def m(c,p): a,b,c,d,e = c x,y = p return a*x + b*x*x + c*y +d*y*y +e # data for surface z = 1.2*x - 0.2*x*x -y + 0.1*y*y + 3 # [[x,y],z] d = [[[0.000000,0.000000],3.000000], [[0.000000,1.000000],2.100000], [[0.000000,2.000000],1.400000], [[0.000000,3.000000],0.900000], [[1.000000,0.000000],4.000000], [[1.000000,1.000000],3.100000], [[1.000000,2.000000],2.400000], [[1.000000,3.000000],1.900000], [[2.000000,0.000000],4.600000], [[2.000000,1.000000],3.700000], [[2.000000,2.000000],3.000000], [[2.000000,3.000000],2.500000], [[3.000000,0.000000],4.800000], [[3.000000,1.000000],3.900000], [[3.000000,2.000000],3.200000], [[3.000000,3.000000],2.700000], [[4.000000,0.000000],4.600000], [[4.000000,1.000000],3.700000], [[4.000000,2.000000],3.000000], [[4.000000,3.000000],2.500000]] r = lsf(model=m, parameters=[0,0,0,0,0], data=d) print "coefficients", r[0] print "chisquared", r[1] ---------------------------------demo.py--------------------------------- $ python demo.py coefficients [1.1999998068357483, -0.19999995420210845, -0.99999983832361761, 0.099999948513050232, 3.0000000498833987] chisquared 1.75763435818e-13 -- Grant Edwards grante@visi.com
Hi Grant, thanks for the small demo! * Grant Edwards <grante@visi.com> wrote:
On 2006-09-16, Fabian Braennstroem <f.braennstroem@gmx.de> wrote:
I would like to do some 3d interpolations. Is it possible with scipy or should I use something different?
I find that Scientific.Functions.LeastSquares.leastSquaresFit works well.
Do you have a small working example?
Here's something I just tossed together...
---------------------------------demo.py--------------------------------- #!/usr/bin/python import Scientific.Functions.LeastSquares lsf = Scientific.Functions.LeastSquares.leastSquaresFit
def m(c,p): a,b,c,d,e = c x,y = p return a*x + b*x*x + c*y +d*y*y +e
# data for surface z = 1.2*x - 0.2*x*x -y + 0.1*y*y + 3 # [[x,y],z]
d = [[[0.000000,0.000000],3.000000], [[0.000000,1.000000],2.100000], [[0.000000,2.000000],1.400000], [[0.000000,3.000000],0.900000], [[1.000000,0.000000],4.000000], [[1.000000,1.000000],3.100000], [[1.000000,2.000000],2.400000], [[1.000000,3.000000],1.900000], [[2.000000,0.000000],4.600000], [[2.000000,1.000000],3.700000], [[2.000000,2.000000],3.000000], [[2.000000,3.000000],2.500000], [[3.000000,0.000000],4.800000], [[3.000000,1.000000],3.900000], [[3.000000,2.000000],3.200000], [[3.000000,3.000000],2.700000], [[4.000000,0.000000],4.600000], [[4.000000,1.000000],3.700000], [[4.000000,2.000000],3.000000], [[4.000000,3.000000],2.500000]]
r = lsf(model=m, parameters=[0,0,0,0,0], data=d)
print "coefficients", r[0] print "chisquared", r[1] ---------------------------------demo.py---------------------------------
$ python demo.py coefficients [1.1999998068357483, -0.19999995420210845, -0.99999983832361761, 0.099999948513050232, 3.0000000498833987] chisquared 1.75763435818e-13
Greetings! Fabian
participants (3)
-
Angus McMorland -
Fabian Braennstroem -
Grant Edwards