6 Driver for text-exported MFP 1D files.
8 Copyright 2009 by Massimo Sandal
9 with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
11 This program is released under the GNU General Public License version 2.
20 __version__='0.0.0.20090923'
22 class mfp1dexportDriver(lib.driver.Driver):
24 def __init__(self, filename):
26 This is a driver to import Asylum Research MFP 1D data.
29 self.filename = filename
30 self.filedata = open(filename,'rU')
31 self.lines = list(self.filedata.readlines())
34 self.filetype = 'mfp1dexport'
35 self.experiment = 'smfs'
37 def _read_columns(self):
39 self.raw_columns=self.lines[39:]
42 for line in self.lines:
43 if line[:7]=='SpringC':
47 kline=kline.split(':')
49 #self.k=float(self.raw_header[23][8:])
50 self.k=float(kline[1])
52 #find retract velocity to calculate loading rate
53 retract_velocity = None
54 for line in self.lines:
55 if line.startswith('RetractVelocity:'):
56 retract_velocity = line.split(':')
57 self.retract_velocity = float(retract_velocity[1])
64 for line in self.raw_columns:
66 xext.append(float(spline[0]))
67 yext.append(float(spline[1]))
68 xret.append(float(spline[2]))
69 yret.append(float(spline[3]))
71 return [[xext,yext],[xret,yret]]
78 self.raw_header = self.lines[0:38]
80 #Not enough lines for a header; not a good file
83 #FIXME: We want a more reasonable header recognition
84 if self.raw_header[0].startswith('Wave'):
89 def default_plots(self):
93 defl_ext, defl_ret = self.deflection()
94 yextforce = [i * self.k for i in defl_ext]
95 yretforce = [i * self.k for i in defl_ret]
97 extension = lib.curve.Curve()
98 retraction = lib.curve.Curve()
100 extension.color = 'red'
101 extension.label = 'extension'
102 extension.style = 'plot'
103 extension.title = 'Force curve'
104 extension.units.x = 'm'
105 extension.units.y = 'N'
106 extension.x = self.data[0][0]
107 extension.y = yextforce
108 retraction.color = 'blue'
109 retraction.label = 'retraction'
110 retraction.style = 'plot'
111 retraction.title = 'Force curve'
112 retraction.units.x = 'm'
113 retraction.units.y = 'N'
114 retraction.x = self.data[1][0]
115 retraction.y = yretforce
117 plot = lib.plot.Plot()
118 plot.title = os.path.basename(self.filename)
119 plot.curves.append(extension)
120 plot.curves.append(retraction)
125 def deflection(self):
126 self.data = self._read_columns()
127 return self.data[0][1], self.data[1][1]