NLSL
c16pc371e.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 from pylab import *
3 from subprocess import Popen, PIPE, STDOUT
4 import os
5 def read_column_data(filename):
6  fp = open(filename,'r')
7  data = []
8  for j in fp.readlines():
9  data.append(j.split())
10  data = array(data,dtype = double)
11  fp.close()
12  return data
13 os.system('make') # check that everything is up to date
14 #cmd = './nlsl < c16pc371e.run'
15 #print "about to run '"+cmd+"'"
16 #os.system(cmd) # actually run nlsl
17 print "about to run nlsl"
18 #proc = Popen(['nlsl'],stdout = PIPE, stdin = PIPE, stderr = STDOUT)
19 if os.name == 'posix':
20  proc = Popen(['./nlsl'],stdin = PIPE, stderr = STDOUT)
21 else:
22  proc = Popen(['nlsl'],stdin = PIPE, stderr = STDOUT)
23 fp = open('c16pc371e.run')
24 output = proc.communicate(input = fp.read())
25 fp.close()
26 print "output was:",output
27 data = read_column_data('c16pc371e.spc')
28 fields = data[:,0]
29 experimental = data[:,1]
30 fit = data[:,2]
31 integral_of_spectrum = cumsum(experimental)
32 normalization = abs(sum(integral_of_spectrum))
33 fig = figure(figsize = (9,6))
34 fig.add_axes([0.1,0.1,0.6,0.8]) # l b w h
35 if data.shape[1] > 3:
36  components = data[:,3:]
37 else:
38  components = None
39 plot(fields,experimental/normalization,'k',linewidth = 1,label = 'experimental')
40 plot(fields,fit/normalization,'k',alpha = 0.5,linewidth = 2,label = 'fit')
41 max_of_fit = max(fit)/normalization
42 if components is not None:
43  plot(fields,components/normalization,alpha = 0.3,linewidth = 1,label = 'component')
44 ax = gca()
45 ylims = ax.get_ylim()
46 scale_integral = max_of_fit/max(integral_of_spectrum)
47 plot(fields,integral_of_spectrum * scale_integral,'k:',alpha = 0.5,linewidth = 1,label = '$\int \int$ (scaled by %0.2g)'%scale_integral)
48 legend(bbox_to_anchor=(1.05,0,0.5,1), # bounding box l b w h
49  loc = 2, # upper left (of the bounding box)
50  borderaxespad=0.)
51 ax.set_ylim(ylims)
52 rms = mean((fit/normalization-experimental/normalization)**2)
53 ax.text(0.75, 0.75, 'rms = %0.2g'%rms,
54  horizontalalignment='left',
55  verticalalignment='top',
56  transform=ax.transAxes)
57 show()
def read_column_data(filename)
Definition: c16pc371e.py:5