6 Global analysis of force curves with various parameters
14 import libpeakspot as lps
15 import libhookecurve as lhc
21 class massanalysisCommands:
24 self.mass_variables={}
25 self.interesting_variables=['curve','firstpeak_distance','lastpeak_distance','Npeaks','median_distance','mean_distance']
28 def _clean_data(self):
29 for variable in self.interesting_variables:
30 self.mass_variables[variable]=[]
32 def peak_position_from_contact(self, item, locations):
34 calculates X distance of a peak from the contact point
36 item.identify(self.drivers)
39 cut_index=self.find_contact_point()
41 #we assume the first is the plot with the force curve
42 plot=item.curve.default_plots()[0]
43 xret=plot.vectors[1][0]
45 start_x=xret[cut_index]
47 real_positions=[abs((xret[index])-(start_x)) for index in locations]
49 item.curve.close_all()
50 #needed to avoid *big* memory leaks!
55 def do_maplist(self,args):
62 self._clean_data() #if we recall it, clean previous data!
63 min_deviation=self.convfilt_config['mindeviation']
67 for item in self.current_list:
69 peak_location,peak_size=self.exec_has_peaks(item, min_deviation)
70 real_positions=self.peak_position_from_contact(item, peak_location)
72 self.mass_variables['Npeaks'].append(len(peak_location))
74 if len(peak_location) > 1:
75 self.mass_variables['firstpeak_distance'].append(min(real_positions))
76 self.mass_variables['lastpeak_distance'].append(max(real_positions))
79 for index in range(len(real_positions)-1):
80 distancepeaks.append(real_positions[index+1]-real_positions[index])
82 self.mass_variables['firstpeak_distance'].append(0)
83 self.mass_variables['lastpeak_distance'].append(0)
85 if len(peak_location) > 2:
86 self.mass_variables['median_distance'].append(np.median(distancepeaks))
87 self.mass_variables['mean_distance'].append(np.mean(distancepeaks))
89 self.mass_variables['median_distance'].append(0)
90 self.mass_variables['mean_distance'].append(0)
94 print 'curve',c,'not mapped'
99 def do_plotmap(self,args):
104 x=self.mass_variables[args[0]]
105 y=self.mass_variables[args[1]]
107 print 'Give me two arguments between those:'
108 print self.interesting_variables
111 scattermap=lhc.PlotObject()
112 scattermap.vectors=[[]]
113 scattermap.vectors[0].append(x)
114 scattermap.vectors[0].append(y)
116 scattermap.units=[args[0],args[1]]
117 scattermap.styles=['scatter']
118 scattermap.destination=1
120 self._send_plot([scattermap])
122 def do_savemaps(self,args):
128 def csv_write_cols(data, f):
130 #from Bruno Desthuillers on comp.lang.python
132 writer = csv.writer(f)
134 writer.writerow(dict(zip(keys,keys)))
135 for row in zip(*data.values()):
136 writer.writerow(dict(zip(keys, row)))
140 lh.csv_write_dictionary(f,self.mass_variables)