3 """Library for interpreting Hemingway force spectroscopy files.
5 __version__='2007_02_15_devel'
8 2007_02_15: fixed time counter with my counter
9 2007_02_07: Initial implementation
12 from .. import curve as lhc
14 class DataChunk(list):
15 '''Dummy class to provide ext and ret methods to the data list.
16 In this case ext and self can be equal.
25 class hemingclampDriver(lhc.Driver):
27 def __init__(self, filename):
29 self.filedata = open(filename,'r')
30 self.data = self.filedata.readlines()[6:]
33 self.filetype = 'hemingclamp'
34 self.experiment = 'clamp'
36 self.filename=filename
43 we define our magic heuristic for HemingClamp files
45 myfile=file(self.filename)
46 headerlines=myfile.readlines()[0:3]
48 if headerlines[0][0:10]=='#Hemingway' and headerlines[1][0:19]=='#Experiment: FClamp':
53 def _getdata_all(self):
63 temp = string.split(i)
64 #time.append(float(temp[0])*(1.0e-3)) # This is managed differently now, since each data point = 1ms: see below
65 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
66 zpiezo.append(float(temp[2])*(1.0e-9))
67 defl.append(float(temp[3])*(1.0e-9))
68 imposed.append(float(temp[4])*(1.0e-9))
70 for x in range (0,len(phase)):
71 if phase[x] != trim_counter:
72 trim_indexes.append(x)
73 trim_counter = phase[x]
75 #we rebuild the time counter assuming 1 point = 1 millisecond
81 return time,phase,zpiezo,defl,imposed,trim_indexes
84 return DataChunk(self._getdata_all()[0])
87 return DataChunk(self._getdata_all()[1])
90 return DataChunk(self._getdata_all()[2])
93 return DataChunk(self._getdata_all()[3])
96 return DataChunk(self._getdata_all()[4])
98 def trimindexes(self):
99 return DataChunk(self._getdata_all()[5])
103 Explicitly closes all files
105 self.filedata.close()
107 def default_plots(self):
108 main_plot=lhc.PlotObject()
109 defl_plot=lhc.PlotObject()
114 deflection=self.deflection()
115 imposed=self.imposed()
117 main_plot.vectors=[[time,zpiezo],[time,phase]]
118 main_plot.units=['seconds','meters']
119 main_plot.destination=0
120 main_plot.title=self.filename
122 defl_plot.vectors=[[time,deflection],[time,imposed]]
123 defl_plot.units=['seconds','Newtons']
124 defl_plot.destination=1
126 return [main_plot, defl_plot]