-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmassanalysis.py
143 lines (109 loc) · 4.29 KB
/
massanalysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
'''
massanalysis.py
Global analysis of force curves with various parameters
Requires:
libpeakspot.py
flatfilts.py
'''
import libpeakspot as lps
import libhookecurve as lhc
import libhooke as lh
import numpy as np
import csv
class massanalysisCommands:
def _plug_init(self):
self.mass_variables={}
self.interesting_variables=['curve','firstpeak_distance','lastpeak_distance','Npeaks','median_distance','mean_distance']
self._clean_data()
def _clean_data(self):
for variable in self.interesting_variables:
self.mass_variables[variable]=[]
def peak_position_from_contact(self, item, locations):
'''
calculates X distance of a peak from the contact point
'''
item.identify(self.drivers)
real_positions=[]
cut_index=self.find_contact_point()
#we assume the first is the plot with the force curve
plot=item.curve.default_plots()[0]
xret=plot.vectors[1][0]
start_x=xret[cut_index]
real_positions=[abs((xret[index])-(start_x)) for index in locations]
#close all open files
item.curve.close_all()
#needed to avoid *big* memory leaks!
del item.curve
del item
return real_positions
def do_maplist(self,args):
'''
MAPLIST
(flatfilts.py)
----
pass
'''
self._clean_data() #if we recall it, clean previous data!
min_deviation=self.convfilt_config['mindeviation']
c=0
for item in self.current_list:
try:
peak_location,peak_size=self.exec_has_peaks(item, min_deviation)
real_positions=self.peak_position_from_contact(item, peak_location)
self.mass_variables['Npeaks'].append(len(peak_location))
if len(peak_location) > 1:
self.mass_variables['firstpeak_distance'].append(min(real_positions))
self.mass_variables['lastpeak_distance'].append(max(real_positions))
distancepeaks=[]
for index in range(len(real_positions)-1):
distancepeaks.append(real_positions[index+1]-real_positions[index])
else:
self.mass_variables['firstpeak_distance'].append(0)
self.mass_variables['lastpeak_distance'].append(0)
if len(peak_location) > 2:
self.mass_variables['median_distance'].append(np.median(distancepeaks))
self.mass_variables['mean_distance'].append(np.mean(distancepeaks))
else:
self.mass_variables['median_distance'].append(0)
self.mass_variables['mean_distance'].append(0)
print 'curve',c
except SyntaxError:
print 'curve',c,'not mapped'
pass
c+=1
def do_plotmap(self,args):
'''
'''
args=args.split()
if len(args)>1:
x=self.mass_variables[args[0]]
y=self.mass_variables[args[1]]
else:
print 'Give me two arguments between those:'
print self.interesting_variables
return
scattermap=lhc.PlotObject()
scattermap.vectors=[[]]
scattermap.vectors[0].append(x)
scattermap.vectors[0].append(y)
scattermap.units=[args[0],args[1]]
scattermap.styles=['scatter']
scattermap.destination=1
self._send_plot([scattermap])
def do_savemaps(self,args):
'''
args=filename
'''
'''
def csv_write_cols(data, f):
#from Bruno Desthuillers on comp.lang.python
writer = csv.writer(f)
keys = data.keys()
writer.writerow(dict(zip(keys,keys)))
for row in zip(*data.values()):
writer.writerow(dict(zip(keys, row)))
'''
f=open(args,'wb')
lh.csv_write_dictionary(f,self.mass_variables)
f.close()