-#!/usr/bin/env python
+# Copyright (C) 2008-2010 Massimo Sandal <devicerandom@gmail.com>
+# W. Trevor King <wking@drexel.edu>
+#
+# This file is part of Hooke.
+#
+# Hooke is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
+#
+# Hooke is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Hooke. If not, see
+# <http://www.gnu.org/licenses/>.
import string
-import libhookecurve as lhc
+from .. import curve as lhc
class DataChunk(list):
#Dummy class to provide ext and ret methods to the data list.
-
+
def ext(self):
halflen=(len(self)/2)
return self[0:halflen]
-
+
def ret(self):
halflen=(len(self)/2)
return self[halflen:]
self.filename=filename #self.filename can always be useful, and should be defined
self.filedata = open(filename,'r') #We open the file
self.filelines=self.filedata.readlines()
- self.filedata.close()
+ self.filedata.close()
'''These are two strings that can be used by Hooke commands/plugins to understand what they are looking at. They have no other
meaning. They have to be somehow defined however - commands often look for those variables.
-
+
self.filetype should contain the name of the exact filetype defined by the driver (so that filetype-specific commands can know
if they're dealing with the correct filetype)
self.experiment should contain instead the type of data involved (for example, various drivers can be used for force-clamp experiments,
- but hooke commands could like to know if we're looking at force clamp data, regardless of their origin, and not other
+ but hooke commands could like to know if we're looking at force clamp data, regardless of their origin, and not other
kinds of data)
-
+
Of course, all other variables you like can be defined in the class.
'''
self.filetype = 'jpk'
self.experiment = 'smfs'
-
-
+
+
def __del__(self):
- self.filedata.close()
-
+ self.filedata.close()
+
def is_me(self):
'''
we define our magic heuristic for jpk files
return True
else:
return False
-
+
def close_all(self):
self.filedata.close()
-
+
def _read_data_segment(self):
#routine that actually reads the data
-
+
height_ms=[]
height_m=[]
height=[]
v_deflection=[]
h_deflection=[]
-
+
self.springconstant=0 #if we don't meet any spring constant, use deflection...
-
+
for line in self.filelines:
#we meet the segment defining the order of data columns
-
+
if line[0:9]=='# columns':
splitline=line.split()[2:]
height_ms_index=splitline.index('smoothedStrainGaugeHeight')
height_index=splitline.index('height')
v_deflection_index=splitline.index('vDeflection')
#h_deflection=splitline.index('hDeflection')
-
+
if line[0:16]=='# springConstant':
self.springconstant=float(line.split()[2])
-
+
if line[0] != '#' and len(line.split())>1:
dataline=line.split()
height_ms.append(float(dataline[height_ms_index]))
height.append(float(dataline[height_index]))
v_deflection.append(float(dataline[v_deflection_index]))
#h_deflection.append(float(dataline[h_deflection_index]))
-
+
if self.springconstant != 0:
force=[item*self.springconstant for item in v_deflection]
else: #we have measured no spring constant :(
force=v_deflection
-
+
height_ms=DataChunk([item*-1 for item in height_ms])
height_m=DataChunk([item*-1 for item in height_m])
height=DataChunk([item*-1 for item in height])
deflection=DataChunk(v_deflection)
force=DataChunk(force)
-
+
return height_ms,height_m,height,deflection,force
-
+
def deflection(self):
height_ms,height_m,height,deflection,force=self._read_data_segment()
deflection_ext=deflection.ext()
deflection_ret=deflection.ret()
deflection_ret.reverse()
return deflection_ext,deflection_ret
-
+
def default_plots(self):
-
+
height_ms,height_m,height,deflection,force=self._read_data_segment()
-
+
height_ms_ext=height_ms.ext()
height_ms_ret=height_ms.ret()
force_ext=force.ext()
#reverse the return data, to make it coherent with hooke standard
height_ms_ret.reverse()
force_ret.reverse()
-
- main_plot=lhc.PlotObject()
+
+ main_plot=lhc.PlotObject()
main_plot.add_set(height_ms_ext,force_ext)
main_plot.add_set(height_ms_ret,force_ret)
-
-
-
+
+
+
if self.springconstant != 0:
main_plot.units=['meters','force']
else:
main_plot.units=['meters','meters']
-
+
main_plot.normalize_vectors()
-
+
main_plot.destination=0
main_plot.title=self.filename
-
- return [main_plot]
\ No newline at end of file
+
+ return [main_plot]