source: fact/tools/pyscripts/simulation/fact_spline_interpolations.py@ 17011

Last change on this file since 17011 was 14805, checked in by neise, 12 years ago
initial commit
  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/usr/bin/python -itt
2
3import sys
4import numpy as np
5
6import rlcompleter
7import readline
8readline.parse_and_bind('tab: complete')
9
10import matplotlib.pyplot as plt
11from scipy.interpolate import InterpolatedUnivariateSpline
12
13
14Wavelength_dependency_description_files = [
15 "030/Transmittance_1439Cones_FACT_bearbeitet.txt",
16 "030/fact-pde-1.4V.txt",
17 "030/MirrorReflectivity_Lustermann_FACT_bearbeitet.txt" ]
18
19angular_acceptance_files = [
20 "030/fact-cones-angular-acceptance.txt" ]
21
22def interpolate_from_files( filenames , debugging_graphics = False):
23
24 if debugging_graphics:
25 plt.ion()
26 fig = plt.figure()
27
28 splines = []
29 x_values = []
30
31 for filename in filenames:
32 data = readfile( filename)
33 x_values += data[:,0].tolist()
34 spline = InterpolatedUnivariateSpline(data[:,0],data[:,1])
35 splines.append(spline)
36 if debugging_graphics:
37 plt.plot(data[:,0],data[:,1],'.',label=filename[4:14])
38 plt.plot(data[:,0],spline(data[:,0]),':',label=filename[4:14]+'_intpol')
39
40
41 x_values = np.array(sorted(list(set(x_values))))
42 y_values = np.ones( x_values.shape )
43 for spline in splines:
44 y_values *= spline( x_values )
45
46 full_spline = InterpolatedUnivariateSpline(x_values,y_values)
47
48 if debugging_graphics:
49 plt.plot(x_values,y_values, '.:',label="full_spline")
50 plt.legend()
51 plt.grid(True)
52
53 return full_spline
54
55
56
57def readfile(filename):
58
59 f = open(filename)
60 lines = []
61
62 for index, line in enumerate(f):
63 line = line.split()
64 if len(line) == 0:
65 continue
66 if '#' in line[0]:
67 continue
68 line = map(float, line)
69
70 #print index, line
71
72 lines.append(line)
73
74 data = np.array(lines)
75 return data
76
77def test( filename ):
78 data = readfile(filename)
79
80 x = data[:,0]
81 y = data[:,1]
82
83 plt.ion()
84 fig = plt.figure()
85 plt.plot(x,y, '.',label="original data")
86
87
88 spline = InterpolatedUnivariateSpline(x,y)
89 xx = np.linspace( x[0], x[-1], len(x)*10)
90
91 plt.plot(xx,spline(xx), ':', label="spline interpolation")
92
93
94if __name__ == '__main__':
95 if len(sys.argv) > 1:
96 print ('trying to interpolate %s' % (sys.argv[1],))
97 test(sys.argv[1])
98 else:
99 wavelength_efficiency = interpolate_from_files(
100 Wavelength_dependency_description_files , True)
101 angular_acceptance = interpolate_from_files( angular_acceptance_files, True )
102
Note: See TracBrowser for help on using the repository browser.