3 """Global analysis of force curves with various parameters
13 from .. import libpeakspot as lps
14 from .. import curve as lhc
15 from .. import libhooke as lh
17 class massanalysisCommands(object):
20 self.mass_variables={}
21 self.interesting_variables=['curve','firstpeak_distance','lastpeak_distance','Npeaks','median_distance','mean_distance']
24 def _clean_data(self):
25 for variable in self.interesting_variables:
26 self.mass_variables[variable]=[]
28 def peak_position_from_contact(self, item, locations):
30 calculates X distance of a peak from the contact point
32 item.identify(self.drivers)
35 cut_index=self.find_contact_point()
37 #we assume the first is the plot with the force curve
38 plot=item.curve.default_plots()[0]
39 xret=plot.vectors[1][0]
41 start_x=xret[cut_index]
43 real_positions=[abs((xret[index])-(start_x)) for index in locations]
45 item.curve.close_all()
46 #needed to avoid *big* memory leaks!
51 def do_maplist(self,args):
58 self._clean_data() #if we recall it, clean previous data!
59 min_deviation=self.convfilt_config['mindeviation']
63 for item in self.current_list:
65 peak_location,peak_size=self.exec_has_peaks(item, min_deviation)
66 real_positions=self.peak_position_from_contact(item, peak_location)
68 self.mass_variables['Npeaks'].append(len(peak_location))
70 if len(peak_location) > 1:
71 self.mass_variables['firstpeak_distance'].append(min(real_positions))
72 self.mass_variables['lastpeak_distance'].append(max(real_positions))
75 for index in range(len(real_positions)-1):
76 distancepeaks.append(real_positions[index+1]-real_positions[index])
78 self.mass_variables['firstpeak_distance'].append(0)
79 self.mass_variables['lastpeak_distance'].append(0)
81 if len(peak_location) > 2:
82 self.mass_variables['median_distance'].append(np.median(distancepeaks))
83 self.mass_variables['mean_distance'].append(np.mean(distancepeaks))
85 self.mass_variables['median_distance'].append(0)
86 self.mass_variables['mean_distance'].append(0)
90 print 'curve',c,'not mapped'
95 def do_plotmap(self,args):
100 x=self.mass_variables[args[0]]
101 y=self.mass_variables[args[1]]
103 print 'Give me two arguments between those:'
104 print self.interesting_variables
107 scattermap=lhc.PlotObject()
108 scattermap.vectors=[[]]
109 scattermap.vectors[0].append(x)
110 scattermap.vectors[0].append(y)
112 scattermap.units=[args[0],args[1]]
113 scattermap.styles=['scatter']
114 scattermap.destination=1
116 self._send_plot([scattermap])
118 def do_savemaps(self,args):
124 def csv_write_cols(data, f):
126 #from Bruno Desthuillers on comp.lang.python
128 writer = csv.writer(f)
130 writer.writerow(dict(zip(keys,keys)))
131 for row in zip(*data.values()):
132 writer.writerow(dict(zip(keys, row)))
136 lh.csv_write_dictionary(f,self.mass_variables)