Updated copyright blurbs in all files to '# Copyright'
[hooke.git] / hooke / driver / mfp1dexport.py
1 # Copyright
2
3 """Driver for text-exported MFP 1D files
4 """
5
6 import os
7
8 from .. import libhooke as lh
9 from .. import curve as lhc
10
11
12 __version__='0.0.0.20090923'
13
14
15 class mfp1dexportDriver(lhc.Driver):
16
17     def __init__(self, filename):
18         '''
19         This is a driver to import Asylum Research MFP 1D data.
20         Status: experimental
21         '''
22         self.filename = filename
23         self.filedata = open(filename,'rU')
24         self.lines = list(self.filedata.readlines())
25         self.filedata.close()
26
27         self.filetype='mfp1dexport'
28         self.experiment='smfs'
29
30     def close_all(self):
31         self.filedata.close()
32
33     def is_me(self):
34         try:
35             self.raw_header = self.lines[0:38]
36         except:
37             #Not enough lines for a header; not a good file
38             return False
39
40         #FIXME: We want a more reasonable header recognition
41         if self.raw_header[0].startswith('Wave'):
42             return True
43         else:
44             return False
45
46     def _read_columns(self):
47
48         self.raw_columns=self.lines[39:]
49
50         kline=None
51         for line in self.lines:
52             if line[:7]=='SpringC':
53                 kline=line
54                 break
55
56         kline=kline.split(':')
57
58         #self.k=float(self.raw_header[23][8:])
59         self.k=float(kline[1])
60
61         xext=[]
62         xret=[]
63         yext=[]
64         yret=[]
65         for line in self.raw_columns:
66             spline=line.split()
67             xext.append(float(spline[0]))
68             yext.append(float(spline[1]))
69             xret.append(float(spline[2]))
70             yret.append(float(spline[3]))
71
72         return [[xext,yext],[xret,yret]]
73
74     def deflection(self):
75         self.data = self._read_columns()
76         return self.data[0][1], self.data[1][1]
77
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']
93         return [main_plot]