File: example1.py

package info (click to toggle)
python-scipy 0.6.0-12
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 32,016 kB
  • ctags: 46,675
  • sloc: cpp: 124,854; ansic: 110,614; python: 108,664; fortran: 76,260; objc: 424; makefile: 384; sh: 10
file content (53 lines) | stat: -rwxr-xr-x 1,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import scipy as s
import scipy.interpolate

from scipy.sandbox.rbf import Rbf

import matplotlib
matplotlib.use('Agg')
import pylab as p

# 1d tests - setup data
x = s.linspace(0,10,9)
y = s.sin(x) 
xi = s.linspace(0,10,101)

# use interpolate methods
ius = s.interpolate.InterpolatedUnivariateSpline(x,y)
yi = ius(xi)
p.subplot(2,1,1)
p.plot(x,y,'o',xi,yi, xi, s.sin(xi),'r')
p.title('Interpolation using current scipy fitpack2')

# use RBF method
rbf = Rbf(x, y)
fi = rbf(xi)
p.subplot(2,1,2)
p.plot(x,y,'bo',xi,fi,'g',xi, s.sin(xi),'r')
p.title('RBF interpolation - multiquadrics')
p.savefig('rbf1d.png')
p.close()

# 2-d tests - setup scattered data
x = s.rand(100)*4.0-2.0
y = s.rand(100)*4.0-2.0
z = x*s.exp(-x**2-y**2)
ti = s.linspace(-2.0,2.0,100)
(XI,YI) = s.meshgrid(ti,ti)

# use RBF
rbf = Rbf(x,y,z,epsilon=2)
ZI = rbf(XI, YI)

# plot the result
n = p.normalize(-2., 2.)
p.subplot(1,1,1)
p.pcolor(XI,YI,ZI,cmap=p.cm.jet)
p.scatter(x,y,100,z,cmap=p.cm.jet)
p.title('RBF interpolation - multiquadrics')
p.xlim(-2,2)
p.ylim(-2,2)
p.colorbar()
p.savefig('rbf2d.png')
p.close()