(mfp1dexport.py , mfp_igor_scripts) Initial indirect support for the MFP1D Asylum...
[hooke.git] / mfp1dexport.py
1 #!/usr/bin/env python
2
3 '''
4 mfp1dexport.py
5
6 Driver for text-exported MFP 1D files
7
8 Massimo Sandal (c) 2009
9 '''
10
11 import libhookecurve as lhc
12 import libhooke as lh
13
14 class mfp1dexportDriver(lhc.Driver):
15     
16     def __init__(self, filename):
17         
18         self.filename=filename
19         self.filedata=open(filename,'rU')
20         
21         lines=list(self.filedata.readlines())
22         self.raw_header=lines[0:38]
23         self.raw_columns=lines[39:]
24         self.filedata.close()
25         
26         self.data=self._read_columns()
27         
28         self.k=float(self.raw_header[22][16:])
29         
30         #print self.k
31         self.filetype='mfp1dexport'
32         self.experiment='smfs'
33         
34     def close_all(self):
35         self.filedata.close()
36         
37     def is_me(self):
38         if self.raw_header[0][0:4]=='Wave':
39             return True
40         else:
41             return False
42         
43     def _read_columns(self):
44         xext=[]
45         xret=[]
46         yext=[]
47         yret=[]
48         for line in self.raw_columns:
49             spline=line.split()
50             xext.append(float(spline[0]))
51             yext.append(float(spline[1]))
52             xret.append(float(spline[2]))
53             yret.append(float(spline[3]))
54             
55         return [[xext,yext],[xret,yret]]
56         
57     def deflection(self):
58         return self.data[0][1],self.data[1][1]
59         
60         
61     def default_plots(self):   
62         main_plot=lhc.PlotObject()
63         
64         yextforce=[i*self.k for i in self.data[0][1]]
65         yretforce=[i*self.k for i in self.data[1][1]]
66         main_plot.add_set(self.data[0][0],yextforce)
67         main_plot.add_set(self.data[1][0],yretforce)
68         main_plot.normalize_vectors()
69         main_plot.units=['Z','force']  #FIXME: if there's an header saying something about the time count, should be used
70         main_plot.destination=0
71         main_plot.title=self.filename
72         #main_plot.colors=['red','blue']
73         return [main_plot]