Ran update_copyright.py, updating all the copyright blurbs and adding AUTHORS.
[hooke.git] / hooke / driver / hdf5.py
1 # Copyright (C) 2009-2010 Alberto Gomez-Casado
2 #                         Massimo Sandal <devicerandom@gmail.com>
3 #                         W. Trevor King <wking@drexel.edu>
4 #
5 # This file is part of Hooke.
6 #
7 # Hooke is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation, either
10 # version 3 of the License, or (at your option) any later version.
11 #
12 # Hooke is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with Hooke.  If not, see
19 # <http://www.gnu.org/licenses/>.
20
21 """Driver for text-exported HDF5 files from Igor pro
22 """
23
24 from .. import curve as lhc
25 from .. import libhooke as lh
26
27 class hdf5Driver(lhc.Driver):
28     
29     def __init__(self, filename):
30         
31         self.filename=filename
32         self.filedata=open(filename,'rU')
33         self.lines=list(self.filedata.readlines())
34         self.filedata.close()
35         
36         self.filetype='hdf5'
37         self.experiment='smfs'
38         
39     def close_all(self):
40         self.filedata.close()
41         
42     def is_me(self):
43         self.raw_header=self.lines[0]      
44                 
45         if 'IGP-HDF5-Hooke' in self.raw_header:
46             return True
47         else:
48             return False
49         
50     def _read_columns(self):
51         
52         self.raw_columns=self.lines[4:]
53         
54         kline=None
55         for line in self.lines:
56             if line[:7]=='SpringC':
57                 kline=line
58                 break
59         
60         kline=kline.split(':')
61         
62         self.k=float(kline[1])
63         
64         
65         xext=[]
66         xret=[]
67         yext=[]
68         yret=[]
69         for line in self.raw_columns:
70             spline=line.split()
71             xext.append(float(spline[0]))
72             yext.append(float(spline[1]))
73             xret.append(float(spline[2]))
74             yret.append(float(spline[3]))
75             
76         return [[xext,yext],[xret,yret]]
77         
78     def deflection(self):
79         self.data=self._read_columns()
80         return self.data[0][1],self.data[1][1]
81         
82         
83     def default_plots(self):   
84         main_plot=lhc.PlotObject()
85         defl_ext,defl_ret=self.deflection()
86         yextforce=[i*self.k for i in defl_ext]
87         yretforce=[i*self.k for i in defl_ret]
88         main_plot.add_set(self.data[0][0],yextforce)
89         main_plot.add_set(self.data[1][0],yretforce)
90         main_plot.normalize_vectors()
91         main_plot.units=['Z','force']  #FIXME: if there's an header saying something about the time count, should be used
92         main_plot.destination=0
93         main_plot.title=self.filename
94         #main_plot.colors=['red','blue']
95         return [main_plot]