4 Global analysis of force curves with various parameters
14 from .. import libpeakspot as lps
15 from .. import libhookecurve as lhc
16 from .. import libhooke as lh
18 class massanalysisCommands(object):
21 self.mass_variables={}
22 self.interesting_variables=['curve','firstpeak_distance','lastpeak_distance','Npeaks','median_distance','mean_distance']
25 def _clean_data(self):
26 for variable in self.interesting_variables:
27 self.mass_variables[variable]=[]
29 def peak_position_from_contact(self, item, locations):
31 calculates X distance of a peak from the contact point
33 item.identify(self.drivers)
36 cut_index=self.find_contact_point()
38 #we assume the first is the plot with the force curve
39 plot=item.curve.default_plots()[0]
40 xret=plot.vectors[1][0]
42 start_x=xret[cut_index]
44 real_positions=[abs((xret[index])-(start_x)) for index in locations]
46 item.curve.close_all()
47 #needed to avoid *big* memory leaks!
52 def do_maplist(self,args):
59 self._clean_data() #if we recall it, clean previous data!
60 min_deviation=self.convfilt_config['mindeviation']
64 for item in self.current_list:
66 peak_location,peak_size=self.exec_has_peaks(item, min_deviation)
67 real_positions=self.peak_position_from_contact(item, peak_location)
69 self.mass_variables['Npeaks'].append(len(peak_location))
71 if len(peak_location) > 1:
72 self.mass_variables['firstpeak_distance'].append(min(real_positions))
73 self.mass_variables['lastpeak_distance'].append(max(real_positions))
76 for index in range(len(real_positions)-1):
77 distancepeaks.append(real_positions[index+1]-real_positions[index])
79 self.mass_variables['firstpeak_distance'].append(0)
80 self.mass_variables['lastpeak_distance'].append(0)
82 if len(peak_location) > 2:
83 self.mass_variables['median_distance'].append(np.median(distancepeaks))
84 self.mass_variables['mean_distance'].append(np.mean(distancepeaks))
86 self.mass_variables['median_distance'].append(0)
87 self.mass_variables['mean_distance'].append(0)
91 print 'curve',c,'not mapped'
96 def do_plotmap(self,args):
101 x=self.mass_variables[args[0]]
102 y=self.mass_variables[args[1]]
104 print 'Give me two arguments between those:'
105 print self.interesting_variables
108 scattermap=lhc.PlotObject()
109 scattermap.vectors=[[]]
110 scattermap.vectors[0].append(x)
111 scattermap.vectors[0].append(y)
113 scattermap.units=[args[0],args[1]]
114 scattermap.styles=['scatter']
115 scattermap.destination=1
117 self._send_plot([scattermap])
119 def do_savemaps(self,args):
125 def csv_write_cols(data, f):
127 #from Bruno Desthuillers on comp.lang.python
129 writer = csv.writer(f)
131 writer.writerow(dict(zip(keys,keys)))
132 for row in zip(*data.values()):
133 writer.writerow(dict(zip(keys, row)))
137 lh.csv_write_dictionary(f,self.mass_variables)