source: fact/tools/pyscripts/simulation/old_and_tests/interpolate_textfile_tests_and_so.py

Last change on this file was 14805, checked in by neise, 12 years ago
initial commit
  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/python -itt
2
3import struct
4import sys
5import numpy as np
6
7import rlcompleter
8import readline
9readline.parse_and_bind('tab: complete')
10
11import matplotlib.pyplot as plt
12import scipy.interpolate
13
14print "start"
15
16f = open(sys.argv[1])
17lines = []
18print "file open"
19
20for 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
32data = np.array(lines)
33
34x = data[:,0]
35y = data[:,1]
36w = None
37
38plt.ion()
39fig = 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
56spline = scipy.interpolate.InterpolatedUnivariateSpline(x,y)
57#spline2 = scipy.interpolate.UnivariateSpline(x,y)
58
59# generate y-x-data from spline just for plotting.
60xx = np.linspace( x[0], x[-1], len(x)*10)
61xx = x
62
63#plt.plot(xx,spline(xx), ':')
64plt.plot(xx,spline(xx)-y, ':')
65#plt.plot(xx,spline2(xx), ':')
66
Note: See TracBrowser for help on using the repository browser.