Updated copyright blurbs in all files to '# Copyright'
[hooke.git] / hooke / driver / hdf5.py
1 # Copyright
2
3 """Driver for text-exported HDF5 files from Igor pro
4 """
5
6 from .. import curve as lhc
7 from .. import libhooke as lh
8
9 class hdf5Driver(lhc.Driver):
10     
11     def __init__(self, filename):
12         
13         self.filename=filename
14         self.filedata=open(filename,'rU')
15         self.lines=list(self.filedata.readlines())
16         self.filedata.close()
17         
18         self.filetype='hdf5'
19         self.experiment='smfs'
20         
21     def close_all(self):
22         self.filedata.close()
23         
24     def is_me(self):
25         self.raw_header=self.lines[0]      
26                 
27         if 'IGP-HDF5-Hooke' in self.raw_header:
28             return True
29         else:
30             return False
31         
32     def _read_columns(self):
33         
34         self.raw_columns=self.lines[4:]
35         
36         kline=None
37         for line in self.lines:
38             if line[:7]=='SpringC':
39                 kline=line
40                 break
41         
42         kline=kline.split(':')
43         
44         self.k=float(kline[1])
45         
46         
47         xext=[]
48         xret=[]
49         yext=[]
50         yret=[]
51         for line in self.raw_columns:
52             spline=line.split()
53             xext.append(float(spline[0]))
54             yext.append(float(spline[1]))
55             xret.append(float(spline[2]))
56             yret.append(float(spline[3]))
57             
58         return [[xext,yext],[xret,yret]]
59         
60     def deflection(self):
61         self.data=self._read_columns()
62         return self.data[0][1],self.data[1][1]
63         
64         
65     def default_plots(self):   
66         main_plot=lhc.PlotObject()
67         defl_ext,defl_ret=self.deflection()
68         yextforce=[i*self.k for i in defl_ext]
69         yretforce=[i*self.k for i in defl_ret]
70         main_plot.add_set(self.data[0][0],yextforce)
71         main_plot.add_set(self.data[1][0],yretforce)
72         main_plot.normalize_vectors()
73         main_plot.units=['Z','force']  #FIXME: if there's an header saying something about the time count, should be used
74         main_plot.destination=0
75         main_plot.title=self.filename
76         #main_plot.colors=['red','blue']
77         return [main_plot]