4 from .. import curve as lhc
7 #Dummy class to provide ext and ret methods to the data list.
11 return self[0:halflen]
17 class jpkDriver(lhc.Driver):
19 def __init__(self, filename):
20 self.filename=filename #self.filename can always be useful, and should be defined
21 self.filedata = open(filename,'r') #We open the file
22 self.filelines=self.filedata.readlines()
24 '''These are two strings that can be used by Hooke commands/plugins to understand what they are looking at. They have no other
25 meaning. They have to be somehow defined however - commands often look for those variables.
27 self.filetype should contain the name of the exact filetype defined by the driver (so that filetype-specific commands can know
28 if they're dealing with the correct filetype)
29 self.experiment should contain instead the type of data involved (for example, various drivers can be used for force-clamp experiments,
30 but hooke commands could like to know if we're looking at force clamp data, regardless of their origin, and not other
33 Of course, all other variables you like can be defined in the class.
36 self.experiment = 'smfs'
45 we define our magic heuristic for jpk files
47 myfile=file(self.filename)
48 headerlines=myfile.readlines()[0:3]
50 if headerlines[0][0:11]=='# xPosition' and headerlines[1][0:11]=='# yPosition':
58 def _read_data_segment(self):
59 #routine that actually reads the data
67 self.springconstant=0 #if we don't meet any spring constant, use deflection...
69 for line in self.filelines:
70 #we meet the segment defining the order of data columns
72 if line[0:9]=='# columns':
73 splitline=line.split()[2:]
74 height_ms_index=splitline.index('smoothedStrainGaugeHeight')
75 height_m_index=splitline.index('strainGaugeHeight')
76 height_index=splitline.index('height')
77 v_deflection_index=splitline.index('vDeflection')
78 #h_deflection=splitline.index('hDeflection')
80 if line[0:16]=='# springConstant':
81 self.springconstant=float(line.split()[2])
83 if line[0] != '#' and len(line.split())>1:
85 height_ms.append(float(dataline[height_ms_index]))
86 height_m.append(float(dataline[height_m_index]))
87 height.append(float(dataline[height_index]))
88 v_deflection.append(float(dataline[v_deflection_index]))
89 #h_deflection.append(float(dataline[h_deflection_index]))
91 if self.springconstant != 0:
92 force=[item*self.springconstant for item in v_deflection]
93 else: #we have measured no spring constant :(
96 height_ms=DataChunk([item*-1 for item in height_ms])
97 height_m=DataChunk([item*-1 for item in height_m])
98 height=DataChunk([item*-1 for item in height])
99 deflection=DataChunk(v_deflection)
100 force=DataChunk(force)
102 return height_ms,height_m,height,deflection,force
104 def deflection(self):
105 height_ms,height_m,height,deflection,force=self._read_data_segment()
106 deflection_ext=deflection.ext()
107 deflection_ret=deflection.ret()
108 deflection_ret.reverse()
109 return deflection_ext,deflection_ret
111 def default_plots(self):
113 height_ms,height_m,height,deflection,force=self._read_data_segment()
115 height_ms_ext=height_ms.ext()
116 height_ms_ret=height_ms.ret()
117 force_ext=force.ext()
118 force_ret=force.ret()
119 #reverse the return data, to make it coherent with hooke standard
120 height_ms_ret.reverse()
123 main_plot=lhc.PlotObject()
124 main_plot.add_set(height_ms_ext,force_ext)
125 main_plot.add_set(height_ms_ret,force_ret)
129 if self.springconstant != 0:
130 main_plot.units=['meters','force']
132 main_plot.units=['meters','meters']
134 main_plot.normalize_vectors()
136 main_plot.destination=0
137 main_plot.title=self.filename