4 Global analysis of force curves with various parameters
12 import libpeakspot as lps
13 import libhookecurve as lhc
19 class massanalysisCommands:
22 self.mass_variables={}
23 self.interesting_variables=['curve','firstpeak_distance','lastpeak_distance','Npeaks','median_distance','mean_distance']
26 def _clean_data(self):
27 for variable in self.interesting_variables:
28 self.mass_variables[variable]=[]
30 def peak_position_from_contact(self, item, locations):
32 calculates X distance of a peak from the contact point
34 item.identify(self.drivers)
37 cut_index=self.find_contact_point()
39 #we assume the first is the plot with the force curve
40 plot=item.curve.default_plots()[0]
41 xret=plot.vectors[1][0]
43 start_x=xret[cut_index]
45 real_positions=[abs((xret[index])-(start_x)) for index in locations]
47 item.curve.close_all()
48 #needed to avoid *big* memory leaks!
53 def do_maplist(self,args):
60 self._clean_data() #if we recall it, clean previous data!
61 min_deviation=self.convfilt_config['mindeviation']
65 for item in self.current_list:
67 peak_location,peak_size=self.exec_has_peaks(item, min_deviation)
68 real_positions=self.peak_position_from_contact(item, peak_location)
70 self.mass_variables['Npeaks'].append(len(peak_location))
72 if len(peak_location) > 1:
73 self.mass_variables['firstpeak_distance'].append(min(real_positions))
74 self.mass_variables['lastpeak_distance'].append(max(real_positions))
77 for index in range(len(real_positions)-1):
78 distancepeaks.append(real_positions[index+1]-real_positions[index])
80 self.mass_variables['firstpeak_distance'].append(0)
81 self.mass_variables['lastpeak_distance'].append(0)
83 if len(peak_location) > 2:
84 self.mass_variables['median_distance'].append(np.median(distancepeaks))
85 self.mass_variables['mean_distance'].append(np.mean(distancepeaks))
87 self.mass_variables['median_distance'].append(0)
88 self.mass_variables['mean_distance'].append(0)
92 print 'curve',c,'not mapped'
97 def do_plotmap(self,args):
102 x=self.mass_variables[args[0]]
103 y=self.mass_variables[args[1]]
105 print 'Give me two arguments between those:'
106 print self.interesting_variables
109 scattermap=lhc.PlotObject()
110 scattermap.vectors=[[]]
111 scattermap.vectors[0].append(x)
112 scattermap.vectors[0].append(y)
114 scattermap.units=[args[0],args[1]]
115 scattermap.styles=['scatter']
116 scattermap.destination=1
118 self._send_plot([scattermap])
120 def do_savemaps(self,args):
126 def csv_write_cols(data, f):
128 #from Bruno Desthuillers on comp.lang.python
130 writer = csv.writer(f)
132 writer.writerow(dict(zip(keys,keys)))
133 for row in zip(*data.values()):
134 writer.writerow(dict(zip(keys, row)))
138 lh.csv_write_dictionary(f,self.mass_variables)