1 # Copyright (C) 2008-2010 Massimo Sandal <devicerandom@gmail.com>
2 # W. Trevor King <wking@drexel.edu>
4 # This file is part of Hooke.
6 # Hooke is free software: you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation, either
9 # version 3 of the License, or (at your option) any later version.
11 # Hooke is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with Hooke. If not, see
18 # <http://www.gnu.org/licenses/>.
20 """Library for interpreting Hemingway force spectroscopy files.
22 __version__='2007_02_15_devel'
25 2007_02_15: fixed time counter with my counter
26 2007_02_07: Initial implementation
29 from .. import curve as lhc
31 class DataChunk(list):
32 '''Dummy class to provide ext and ret methods to the data list.
33 In this case ext and self can be equal.
42 class hemingclampDriver(lhc.Driver):
44 def __init__(self, filename):
46 self.filedata = open(filename,'r')
47 self.data = self.filedata.readlines()[6:]
50 self.filetype = 'hemingclamp'
51 self.experiment = 'clamp'
53 self.filename=filename
60 we define our magic heuristic for HemingClamp files
62 myfile=file(self.filename)
63 headerlines=myfile.readlines()[0:3]
65 if headerlines[0][0:10]=='#Hemingway' and headerlines[1][0:19]=='#Experiment: FClamp':
70 def _getdata_all(self):
80 temp = string.split(i)
81 #time.append(float(temp[0])*(1.0e-3)) # This is managed differently now, since each data point = 1ms: see below
82 phase.append(float(temp[1])*(1.0e-7)) # The nonsensical (e-7) multiplier is just there to make phase data nicely plottable along other data
83 zpiezo.append(float(temp[2])*(1.0e-9))
84 defl.append(float(temp[3])*(1.0e-9))
85 imposed.append(float(temp[4])*(1.0e-9))
87 for x in range (0,len(phase)):
88 if phase[x] != trim_counter:
89 trim_indexes.append(x)
90 trim_counter = phase[x]
92 #we rebuild the time counter assuming 1 point = 1 millisecond
98 return time,phase,zpiezo,defl,imposed,trim_indexes
101 return DataChunk(self._getdata_all()[0])
104 return DataChunk(self._getdata_all()[1])
107 return DataChunk(self._getdata_all()[2])
109 def deflection(self):
110 return DataChunk(self._getdata_all()[3])
113 return DataChunk(self._getdata_all()[4])
115 def trimindexes(self):
116 return DataChunk(self._getdata_all()[5])
120 Explicitly closes all files
122 self.filedata.close()
124 def default_plots(self):
125 main_plot=lhc.PlotObject()
126 defl_plot=lhc.PlotObject()
131 deflection=self.deflection()
132 imposed=self.imposed()
134 main_plot.vectors=[[time,zpiezo],[time,phase]]
135 main_plot.units=['seconds','meters']
136 main_plot.destination=0
137 main_plot.title=self.filename
139 defl_plot.vectors=[[time,deflection],[time,imposed]]
140 defl_plot.units=['seconds','Newtons']
141 defl_plot.destination=1
143 return [main_plot, defl_plot]