3 """Driver for text-exported MFP 1D files
8 from .. import libhooke as lh
9 from .. import curve as lhc
12 __version__='0.0.0.20090923'
15 class mfp1dexportDriver(lhc.Driver):
17 def __init__(self, filename):
19 This is a driver to import Asylum Research MFP 1D data.
22 self.filename = filename
23 self.filedata = open(filename,'rU')
24 self.lines = list(self.filedata.readlines())
27 self.filetype='mfp1dexport'
28 self.experiment='smfs'
35 self.raw_header = self.lines[0:38]
37 #Not enough lines for a header; not a good file
40 #FIXME: We want a more reasonable header recognition
41 if self.raw_header[0].startswith('Wave'):
46 def _read_columns(self):
48 self.raw_columns=self.lines[39:]
51 for line in self.lines:
52 if line[:7]=='SpringC':
56 kline=kline.split(':')
58 #self.k=float(self.raw_header[23][8:])
59 self.k=float(kline[1])
65 for line in self.raw_columns:
67 xext.append(float(spline[0]))
68 yext.append(float(spline[1]))
69 xret.append(float(spline[2]))
70 yret.append(float(spline[3]))
72 return [[xext,yext],[xret,yret]]
75 self.data = self._read_columns()
76 return self.data[0][1], self.data[1][1]
78 def default_plots(self):
79 main_plot = lhc.PlotObject()
80 defl_ext,defl_ret = self.deflection()
81 yextforce = [i*self.k for i in defl_ext]
82 yretforce = [i*self.k for i in defl_ret]
83 main_plot.add_set(self.data[0][0], yextforce)
84 main_plot.add_set(self.data[1][0], yretforce)
85 main_plot.normalize_vectors()
86 #main_plot.units = ['Z','force'] #FIXME: if there's an header saying something about the time count, should be used
87 main_plot.units = ['m','N']
88 main_plot.destination = 0
89 main_plot.filename = self.filename
90 main_plot.title = os.path.basename(self.filename)
91 main_plot.colors = ['red','blue']
92 main_plot.style = ['plot','plot']