-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhemingclamp.py
executable file
·134 lines (101 loc) · 3.69 KB
/
hemingclamp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python
'''
libhemingclamp.py
Library for interpreting Hemingway force spectroscopy files.
Copyright (C) 2008 Massimo Sandal, Marco Brucale (University of Bologna, Italy)
This program is released under the GNU General Public License version 2.
'''
__version__='2007_02_15_devel'
__changelog__='''
2007_02_15: fixed time counter with my counter
2007_02_07: Initial implementation
'''
import string
import libhookecurve as lhc
class DataChunk(list):
'''Dummy class to provide ext and ret methods to the data list.
In this case ext and self can be equal.
'''
def ext(self):
return self
def ret(self):
return self
class hemingclampDriver(lhc.Driver):
def __init__(self, filename):
self.filedata = open(filename,'r')
self.data = self.filedata.readlines()[6:]
self.filedata.close()
self.filetype = 'hemingclamp'
self.experiment = 'clamp'
self.filename=filename
def __del__(self):
self.filedata.close()
def is_me(self):
'''
we define our magic heuristic for HemingClamp files
'''
myfile=file(self.filename)
headerlines=myfile.readlines()[0:3]
myfile.close()
if headerlines[0][0:10]=='#Hemingway' and headerlines[1][0:19]=='#Experiment: FClamp':
return True
else:
return False
def _getdata_all(self):
time = []
phase = []
zpiezo = []
defl = []
imposed = []
trim_indexes = []
trim_counter = 0.0
for i in self.data:
temp = string.split(i)
#time.append(float(temp[0])*(1.0e-3)) # This is managed differently now, since each data point = 1ms: see below
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
zpiezo.append(float(temp[2])*(1.0e-9))
defl.append(float(temp[3])*(1.0e-9))
imposed.append(float(temp[4])*(1.0e-9))
for x in range (0,len(phase)):
if phase[x] != trim_counter:
trim_indexes.append(x)
trim_counter = phase[x]
#we rebuild the time counter assuming 1 point = 1 millisecond
c=0.0
for z in zpiezo:
time.append(c)
c+=(1.0e-3)
return time,phase,zpiezo,defl,imposed,trim_indexes
def time(self):
return DataChunk(self._getdata_all()[0])
def phase(self):
return DataChunk(self._getdata_all()[1])
def zpiezo(self):
return DataChunk(self._getdata_all()[2])
def deflection(self):
return DataChunk(self._getdata_all()[3])
def imposed(self):
return DataChunk(self._getdata_all()[4])
def trimindexes(self):
return DataChunk(self._getdata_all()[5])
def close_all(self):
'''
Explicitly closes all files
'''
self.filedata.close()
def default_plots(self):
main_plot=lhc.PlotObject()
defl_plot=lhc.PlotObject()
time=self.time()
phase=self.phase()
zpiezo=self.zpiezo()
deflection=self.deflection()
imposed=self.imposed()
main_plot.vectors=[[time,zpiezo],[time,phase]]
main_plot.units=['seconds','meters']
main_plot.destination=0
main_plot.title=self.filename
defl_plot.vectors=[[time,deflection],[time,imposed]]
defl_plot.units=['seconds','Newtons']
defl_plot.destination=1
return [main_plot, defl_plot]