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