1 | #!/usr/bin/python -itt
|
---|
2 |
|
---|
3 | import struct
|
---|
4 | import sys
|
---|
5 | import numpy as np
|
---|
6 |
|
---|
7 | import rlcompleter
|
---|
8 | import readline
|
---|
9 | readline.parse_and_bind('tab: complete')
|
---|
10 |
|
---|
11 | import matplotlib.pyplot as plt
|
---|
12 | import scipy.interpolate
|
---|
13 |
|
---|
14 | print "start"
|
---|
15 |
|
---|
16 | f = open(sys.argv[1])
|
---|
17 | lines = []
|
---|
18 | print "file open"
|
---|
19 |
|
---|
20 | for index, line in enumerate(f):
|
---|
21 | line = line.split()
|
---|
22 | if '#' in line[0]:
|
---|
23 | continue
|
---|
24 | line = map(float, line)
|
---|
25 |
|
---|
26 | print index, line
|
---|
27 | if len(line) == 0:
|
---|
28 | continue
|
---|
29 |
|
---|
30 | lines.append(line)
|
---|
31 |
|
---|
32 | data = np.array(lines)
|
---|
33 |
|
---|
34 | x = data[:,0]
|
---|
35 | y = data[:,1]
|
---|
36 | w = None
|
---|
37 |
|
---|
38 | plt.ion()
|
---|
39 | fig = plt.figure()
|
---|
40 |
|
---|
41 | #plt.plot(x,y, '.')
|
---|
42 |
|
---|
43 |
|
---|
44 | #scipy.interpolate.UnivariateSpline
|
---|
45 | #(self, x, y, w=None, bbox=[None, None], k=3, s=None)
|
---|
46 | #spline = scipy.interpolate.UnivariateSpline( x=x ,y=y ,w=w )
|
---|
47 |
|
---|
48 | #PiecewisePolynomial
|
---|
49 | # __init__(self, xi, yi, orders=None, direction=None)
|
---|
50 | #spline = scipy.interpolate.PiecewisePolynomial(x,y)
|
---|
51 | # did not work
|
---|
52 |
|
---|
53 | # ringing like hell!
|
---|
54 | #spline = scipy.interpolate.BarycentricInterpolator(x,y)
|
---|
55 |
|
---|
56 | spline = scipy.interpolate.InterpolatedUnivariateSpline(x,y)
|
---|
57 | #spline2 = scipy.interpolate.UnivariateSpline(x,y)
|
---|
58 |
|
---|
59 | # generate y-x-data from spline just for plotting.
|
---|
60 | xx = np.linspace( x[0], x[-1], len(x)*10)
|
---|
61 | xx = x
|
---|
62 |
|
---|
63 | #plt.plot(xx,spline(xx), ':')
|
---|
64 | plt.plot(xx,spline(xx)-y, ':')
|
---|
65 | #plt.plot(xx,spline2(xx), ':')
|
---|
66 |
|
---|